Page 1 of 1

G30TH Timer trouble

Posted: Tue Aug 09, 2016 9:49 pm
by jgriessen
I've looked up how to do register writes using names in the stm module.
I changed my dual pulser program to use register writes to initialize the output compare pin's HIGH state,
and left the pyb.Timer.OC_INACTIVE compare in there, but no go. It's as if the HIGH state is not being set.

Oh wait! I think I know why.. I set a pin high in a callback that never gets called!
Adding some more init stuff...

Hmmm..... there is no CCMR3 defined in the stmhal/cmsis/devinc/stm32f401xe.h file.
Maybe this is for library size reasons...

Rewriting to use different timer numbers....

Re: G30TH Timer trouble

Posted: Tue Aug 09, 2016 11:07 pm
by dhylands
CCMR3? I'm not seeing that defined anywhere?

There are only 4 channels for any of the timers on the 40x chips, and each CCMRx register covers 2 channels, so there will only be CCMR1 (for channels 1 & 2) and CCMR2 (for channels 3 & 4)

Re: G30TH Timer trouble

Posted: Wed Aug 10, 2016 1:33 am
by jgriessen
Well I am caught out as a newbie at STM32F's and python too!

Re: G30TH Timer trouble

Posted: Wed Aug 10, 2016 9:02 pm
by jgriessen
Thanks for pointing out that mistake about CCMR1, CCMR2 registers.
What I think I can use now after trying stuff and reading a lot, is called frozen mode where the timer output pin does not change, then go back to PWM mode 1 when I want an output again. That's how I will get my desired PWM outputs that alternate half cycles, and everything will change symmetrically when I change the compare number with a micropython method such as
t2ch2.pulse_width(950)
t2ch3.pulse_width(950)
The pulses will be exactly the same, since the number change happened between times, not near a compare match, and the pulse width times do not depend on interrupts, the interrupts depend on the times.
I'll do that pulse_width() number changing in the interrupt callback. Not confirmed yet, but close...