Issues with use of PWM on Kinetis K40

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issues with use of PWM on Kinetis K40

758 Views
stav
Contributor II

I have been using a PWM to power a light, switching off the pwm when the light needs to be off.

I found that using FTM2 module with output on PORTA_PCR10, I have a problem switching off the pwm and leaving the output in a known state. Sometimes it works sometimes it does not. The issue ***appears*** to be mainly present when using the debugger and not in standalone code.

Has anyone any idea what the source of the issue is? My main concern is that there might be a conflict between the trace_d0 output on the same pin (although I de-selected it). Its the only correlation I could think of between the debugger and the issue.

If another pin would be better I may have to change the hardware (yuk..)

 

all input appreciated,

 

this is part of the init code:

/* added polarity set register for inactive state*/
  FTM2_POL = (uint32_t) 0x01UL;


 

The following code is used to switch off the light:

 

  /*force output to inactive state*/
   FTM2_OUTMASK = 1;
  /*shut off counter (set source to none)*/
   FTM2_SC &= ~((uint32_t)0x10UL);

      /*  removed - was not effective
       FTM2_MODE |= (uint32_t)0x02UL;
       FTM2_MODE |= (uint32_t)0x02UL;*/

0 Kudos
1 Reply

400 Views
konrada
Contributor IV

First of all: you can still switch the pin to GPIO function using PORTA_PCR, then control the pin level with GPIO.

 

One idea: are you sure about your magic constants? FTMx_SC on K70 (but I doubt K40 has it differently) has CLKS in bits 3..4, which your AND mask only half erases. Using FTM_SC_CLKS_MASK would also be easier to read in a forum.

 

Another idea: FTM synchronizes writes to its registers; if you turn off the clock, FTMx_OUTMASK may never be committed.

0 Kudos