i want to run pwm function on PA2 pin with variable frequency and 1% duty cycle.
i write the code bellow but the problem is i just can change the frequency in void setup. but when i try to change the timer2.setPeriod value in void loop{} pwm frequency doesn't change.
where is the problem?
this is my code
Code: Select all
#define pin PA2
void setup() {
pinMode(PA2 , PWM);
Timer2.pause();
Timer2.setPeriod(10); // in microseconds
Timer2.setMode(TIMER_CH1,TIMER_OUTPUTCOMPARE);
Timer2.setCompare(TIMER_CH1, 1);
Timer2.attachInterrupt(TIMER_CH1,handler_led);
Timer2.refresh();
Timer2.resume();
Timer4.setPrescaleFactor(prescaler);
}
void loop() {
}
void handler_led(void) {
pwmWrite(PA2,167);
}