Hi Folks, I have this code in my setup to change the PWM frequency to 10khz. It seems to work fine normally, I use the pins 6,7,8 only for PWM output:
timer1.pause();
timer1.setPrescaleFactor(1);
timer1.setOverflow(7200);
timer1.refresh();
timer1.resume();
However I have to use center or symmetric PWM in my code not edge aligned PWM which is stock for the IDE.
To achieve this I modified the file 'boards.cpp' located at: maple/hardware/leaflabs/cores/maple for version 0.0.12
I changed the line:
regs->CR1 = TIMER_CR1_ARPE;
to
regs->CR1 = TIMER_CR1_ARPE|(1<<5);
Which works to make the PWM center/symmetric and I've confirmed this via a scope. The problem is that it seems to be changing the PWM frequency, so the setup code above now runs at half the speed, so 5khz instead of 10khz.
The other thing I've noticed is that I have a timed interrupt which normally runs every 100microseconds. This works fine normally until I make the change to the boards.cpp file (for center PWM). Then it runs at half speed. I have confirmed all this via the scope.
Does anyone know why this is happening and is there any way around it? I can think of some work arounds but it involves a lower resolution in my PWM output etc. I'd rather try and fix the main problem first.
Thanks for your time!