Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
- Posts: 62
- Joined: Sun Jul 16, 2017 9:57 pm
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;
- Posts: 857
- Joined: Thu Jul 21, 2016 4:24 pm
- Posts: 2073
- Joined: Mon Oct 19, 2015 12:06 am
- Location: Munich, Germany
And what exactly should be the "same functionality"?
- Posts: 231
- Joined: Wed May 11, 2016 4:29 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 ....