Timer setup

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
Post Reply
ted
Posts: 62
Joined: Sun Jul 16, 2017 9:57 pm

Timer setup

Post by ted » Sat Dec 23, 2017 2:03 am

Hi
Timers AVR to ARM
The program below is from arduino uno - timers setup, how to set up the timers in stm32f103 with the same functionality ?

Code: Select all

 // Set up timer 1.
  // Prescaler = 1, phase correct PWM mode, TOP = ICR1A


    TCCR1A = (1 << COM1A1) | (1 << WGM11);
    TCCR1B = (1 << WGM12) | (1 << WGM13) | (1 << CS10);    // CTC mode, prescaler = 1
    TCCR1C = 0;
    OCR1AH = (TIMER1_TOP/2 >> 8);
    OCR1AL = (TIMER1_TOP/2 & 0xFF);
    ICR1H = (TIMER1_TOP >> 8);
    ICR1L = (TIMER1_TOP & 0xFF);
    TCNT1H = 0;
    TCNT1L = 0;
    TIFR1 = 0x07;      // clear any pending interrupt
    TIMSK1 = (1 << TOIE1); 



    // Set up timer 0
    // Clock source = T0, fast PWM mode, TOP (OCR0A) = 7, PWM output on OC0B
    TCCR0A = (1 << COM0B1) | (1 << WGM01) | (1 << WGM00);
    TCCR0B = (1 << CS00) | (1 << CS01) | (1 << CS02) | (1 << WGM02);
    OCR0A = 7;
    OCR0B = 3;
    TCNT0 = 0;
    sei();


ag123
Posts: 854
Joined: Thu Jul 21, 2016 4:24 pm

Re: Timer setup

Post by ag123 » Sat Dec 23, 2017 4:56 am

i think the 'old' timer examples from the original leaflabs documents still works
http://docs.leaflabs.com/docs.leaflabs.com/index.html
http://docs.leaflabs.com/static.leaflab ... dwaretimer

stevestrong
Posts: 2043
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: Timer setup

Post by stevestrong » Sat Dec 23, 2017 9:00 am

And what exactly should be the "same functionality"?

dannyf
Posts: 228
Joined: Wed May 11, 2016 4:29 pm

Re: Timer setup

Post by dannyf » Sun Dec 24, 2017 8:00 pm

how to set up the timers in stm32f103 with the same functionality ?
you want to figure out what the code was doing on the avr. in the case of timer1, it sets up a user specified top, phase correct pwm on ch a, ...

you then want to pick a timer to replicate that on the stm32. a 16-bit timer would be my choice. from there, pick the top via the period register; pick a up/down counter to be "phase correct", and then ....

User avatar
mrburnette
Posts: 2190
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Timer setup

Post by mrburnette » Wed Dec 27, 2017 5:32 pm

The old libmaple docs had a section on timers:
http://docs.leaflabs.com/static.leaflab ... imers.html

May be helpful.

Use this query in Google for more info:

Code: Select all

STM32F103  Arduino timers
And then there is the big ol' reference manual and a few application notes such as AN4776. <<< PDF warning


Ray

Post Reply