Author Topic: WHardwareTimer.h  (Read 2435 times)

0 Members and 1 Guest are viewing this topic.


« on: October 08, 2014, 11:19:21 AM »
I've spent years programming in Arduino/Wiring environments, and every time I have to do something that involves the use of timers/counters, I ended up losing hours looking at the Atmega datasheet and implementing the same code over and over again.

Recently I decided to use WHardwareTimer.h which is, in fact, the only library that exists worldwide to handle AVR timers.

The problem is that it lacks documentation, it's not even commented the code itself, which is a real shame.

My question then is: how to use setMode and setOutputMode methods? What is supposed to pass as parameters?

Thank you in advance.



Re: WHardwareTimer.h
« Reply #1 on: October 20, 2014, 03:01:13 PM »
Yes, the reason it seems unfinished is because the way the hardware timers were being built originally were very Atmel AVR-centric, which led to a lot of AVR-isms.  We've been working on developing the Wiring Framework to be target independent, and as such, the settings for the hardware timers in the AVR series differ from other controllers.

As I built out the WHardwareTimer library, I started realizing that it was not going to go away from the the AVR-isms, so I ended up half-finishing the setMode and other register management functions.

But, in a nutshell, setMode writes to the WGM (Waveform Generation Mode) bits of the AVR 8 bit series TCCR (Timer/Counter Control Register).

Have a look at the HardwareTimer::setMode() function to see exact details:

Code: [Select]
void HardwareTimer::setMode(uint8_t mode)
  // WGMn3 and WGMn2 are in positions 4 and 3, respectively, in TCCRnB
  // WGMn1 and WGNn0 are in positions 1 and 0, respectively, in TCCRnA

  // For devices with global TIMSK, 8 bit timers have:
  // WGMn0 in position 6 of TCCRn register
  // WGMn1 in position 3 of TCCRn register

#if defined (TIMSK)
  if (_timerNumber == 0 || _timerNumber == 2)
    // only a single control register on these devices (TCCRn)
    *_tccrna = (*_tccrna & 0b10110111)
                 | ((mode & 0b00000001) << 6)
                 | ((mode & 0b00000010) << 2);
    // everything else conforms (the two control registers for the WGM)
  *_tccrna = (*_tccrna & 0b11111100) | (mode & 0b00000011);
  *_tccrnb = (*_tccrnb & 0b11100111) | ((mode & 0b00001100) << 1);
#if defined (TIMSK)

The same applies to setOutputMode - which sets the COM (Compare Output Mode) bits of the TCCR register:

Code: [Select]
void HardwareTimer::setOutputMode(uint8_t channel, uint8_t outputMode)
  uint8_t COMbitMask = 0b11;
  uint8_t shiftCount;

  outputMode &= 0b11;  // only 4 modes

  if (channel < _channelCount)
    if ((_timerNumber == 0 || _timerNumber == 2) && _channelCount == 1)
      // 8 bit timers with only 1 OCR
      shiftCount = COMn0;
      // 16 bit timers
      if (channel == CHANNEL_A)
        shiftCount = COMnA0;
      else if (channel == CHANNEL_B)
        shiftCount = COMnB0;
      else if (channel == CHANNEL_C)
        shiftCount = COMnC0;

    COMbitMask <<= shiftCount;
    outputMode <<= shiftCount;

    *_tccrna = (*_tccrna & ~(COMbitMask)) | outputMode;

I'd like to develop the HardwareTimer class into a cross-platform Framework class, such that the functions we use are generic enough to apply to any target controller.  I know that there will still be specific functions that will need to be supported, and may be handled by platform specific functions (i.e. incompatible), but target independent is what I'd personally like to shoot for.

As always, any help in designing and defining the Framework would be greatly appreciated.


Re: WHardwareTimer.h
« Reply #2 on: November 15, 2014, 01:39:07 AM »
Hi Brett, thank you for your response.

I think the only thing missing from this library is a set of #defines for modes and output modes, as there exist for prescalers and interrupts. For example, in my application I used the following:

Timer2.setClockSource (CLOCK_NO_PRESCALE);
Timer1.setClockSource (CLOCK_PRESCALE_8);
Timer1.attachInterrupt (INTERRUPT_COMPARE_MATCH_A, timer1IntHandler);

Timer2.setMode (0b0100);   // CTC mode
Timer1.setMode (0);        // Normal counting mode (0->2^16)
Timer2.setOutputMode (CHANNEL_A, 1);

These values I obtained by looking into the Wiring code, at sections where WHardwareTimer.h was used. Then I could define:

#define MODE_CTC              0b0100

But I really don't feel fully qualified to complete this work and to remain consistent with the style of the rest of the library.



Download video and MP3 youtube
« Reply #3 on: October 25, 2017, 04:41:45 PM »
<a href="https://descargarvideosdeyoutube.top/watch?v=AKxeCKSEWDk">Descargar VÍDEO o MP3 ¿PUEDES TERMINAR DE VER ESTE VIDEO?  Vertigo Test</a><br>Por favor SUSCRIBETE AHORA! http://bit.ly/JGsuscribeteSígueme en Instagram: http://bit.ly/2rLMFRDAnc</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=FSMVXibKCxk">Descargar VÍDEO o MP3 MEREZCO THE ABUNDANCE - EL PULSO DE LA REPÚBLICA</a><br>El Pulso de La República. El InIn (Informativo Informal) que sale todos los LUNES y JUEVES a las 11 </br>
<a href="https://descargarvideosdeyoutube.top/watch?v=4LfJnj66HVQ">Descargar VÍDEO o MP3 Lil Pump - "Gucci Gang" (Official Music Video)</a><br>Lil Pump Album Out Now: https://ad.gt/lilpumpLil Pump Tour Tickets: https://lilpumpjetskii.comFollow</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=zCQ3_hsBz28">Descargar VÍDEO o MP3 EL SEÑOR DE LOS CIELOS 5 - AVANCE CAPITULO 89 - MARTES 24 DE OCTUBRE 2017 - Últimos Capítulos</a><br>#ELSEÑORDELOSCIELOS 5MIS REDES SOCIALES:  ▬▬▬ ▬▬▬Facebook▬▬▬ ▬▬▬AQUÍ SE SUBEN LOS CAPÍTULOS COMPLETO</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=JBRtUmGPHA8">Descargar VÍDEO o MP3 El Señor de los Cielos 5 - Capítulo 88 Parte 5/5</a><br></br>
<a href="https://descargarvideosdeyoutube.top/watch?v=lwZlKRZnZZ0">Descargar VÍDEO o MP3 [BODA COMPLETA]  VANDA Y LUIS FERNANDO SE DAN EL SI Y YA SON ESPOSOS  Enamorandonos</a><br>Suscribete y Comparte.Gracias por ver.</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=ZweFdETcDtg">Descargar VÍDEO o MP3 Sin Senos Si Hay Paraiso 2  Capitulo 62 - 3/5 COMPLETO HD</a><br>Sin Senos Si Hay Paraiso 2  Capitulo 62 - 3/5 COMPLETO HD© Copyrights All Rights Reserved to Telemu</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=4WpiffabEeo">Descargar VÍDEO o MP3 Maluma desprecia y empuja a una fan en pleno concierto en Guadalajara (21 de octubre 2017)</a><br>Maluma desprecia y empuja a una fan en pleno concierto en Guadalajara (21 de octubre 2017)</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=6RPURCx1R9Y">Descargar VÍDEO o MP3 Revenden productos para damnificados - QUEFISHTV</a><br>Hola amiguitos, espero que este video les guste mucho, en verdad fue bastante intenso grabarlo (NO L</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=ypHPvgYF2R0">Descargar VÍDEO o MP3 Las curiosidades de la gala FIFA "The Best" que ganó Cristiano Ronaldo (2017)</a><br>No te pierdas este video de todas las curiosidades de la gala "The Best" que ganó Cristiano Ronaldo.</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=N7kCoZJONLs">Descargar VÍDEO o MP3 EN VIVO los mejores youtubers de latinoamérica en BRANDCAST 2017</a><br>Contacto asoyalexmontiel@gmail.com Facebook:https://www.facebook.com/EstoEsCOMBO Instagram:https://w</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=KWGWYmrAz4I">Descargar VÍDEO o MP3 Costillas de Res con Jack Daniel's  La Capital</a><br>Short Ribs, costilla cargada o asado de tira sazonada con sal, ajo y whisky cocinadas al horno por 3</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=GixOBBE1VFw">Descargar VÍDEO o MP3 Ittefaq Se (Raat Baaki)  Ittefaq  Sidharth Malhotra  Sonakshi Sinha  Akshaye Khanna  Nov 3</a><br>Presenting Ittefaq Se (Raat Baaki) - the title song of the film Ittefaq , which intrigued audiences </br>
<a href="https://descargarvideosdeyoutube.top/watch?v=Nzj6cfxeknY">Descargar VÍDEO o MP3 Pan de Muerto Tradicional</a><br>Pan de Muerto. Pan de Muerto Tradicional de Jauja Cocina Mexicana para conmemorar el Día  de Todos l</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=DJPoXRV3TD8">Descargar VÍDEO o MP3 Maradona le entregó el premio "The Best" a Cristiano Ronaldo - Café de la Tarde</a><br>El portugués estaba nominado con Messi y Neymar.</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=LGeklqbkqdw">Descargar VÍDEO o MP3 TRENDING 23 OCTUBRE - CAELI ESTRENA NOVIO, GANADORES ELIOT AWARDS 2017, #RESPECTHARRY Y MÁS.</a><br>Las noticias y tendencias en redes sociales más importantes del 22 y 23 de octubre de 2017. Ayer se </br>
<a href="https://descargarvideosdeyoutube.top/watch?v=p4SU536FeH0">Descargar VÍDEO o MP3 Eduardo Yáñez: "Mi hijo me engañó y me robó"  Al Rojo Vivo  Telemundo</a><br>El actor rompió el silencio y confesó las verdaderas razones por las que él y su hijo se distanciaro</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=iDFph89KZEI">Descargar VÍDEO o MP3 Fuertes imágenes: cámaras graban ataque a Jazmín Contreras</a><br>Imágenes exclusivas del momento en que dos hombres atacan a Jazmín Contreras, de 19 años, en Tlaxcal</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=NiAPGPInHpo">Descargar VÍDEO o MP3 Sardar Mohammad (Title Track) Tarsem Jassar- Latest Punjabi Songs 2017 -New Punjabi Songs 2017 -WHM</a><br>Sardar Mohammad (Title Track) Tarsem Jassar- Latest Punjabi Songs 2017 -New Punjabi Songs 2017 -WHMA</br>
<a href="https://descargarvideosdeyoutube.top/watch?v=EzOPJkX-q_A">Descargar VÍDEO o MP3 7 Cosas Que NO SABÍAS de Tu Propio Cuerpo</a><br>7 Cosas Que NO SABÍAS de Tu Propio CuerpoHola Toxos ¿Cómo están? si crees saber tooodo a acerca de t</br>