AnsweredAssumed Answered

HCS12 - Strange PWM Issue

Question asked by Andrea Ricco on Mar 10, 2015
Latest reply on Mar 24, 2015 by iggi

I'm working on an old project based on HCS12 for a temperature PID control where PWM5 is used to drive an SSR. Following the init of PWM unit:


output( PWMCTL, input( PWMCTL ) & ~12 ); // PWM reset wait e freeze bit
output( PWMSDN, 0 ); // PWM shutdown register (disabled)


   /* channels 6,7,3,2 takes source from (S)B clock: HI FREQ PWM */

  /* channels 4,5,1,0 takes source from (S)A clock LOW FRAQ PWM */

PWMCLK   = 0xFF;    // all sources from scaled clocks

PWMPRCLK = 0x07;    // Prescaler select A/128 B/1

PWMSCLA  = 0x00;    // scale value clock SA (0 == 256)

PWMSCLB  = 0x00;    // scale value clock SB (0 == 256)

PWMCAE   = 0x00;    // all left aligned signals

PWMPOL   = 0x00;    // normal polarity (1-0)


PWM5 is used with 8 bit, it is enabled at the beginning and never stopped, PWMPER5 is at default reset value 0xFF and never changed so the period is about 2090 ms. More or less every 1200 ms PID algorithm set a new duty value writing PWMDTY5 asynchronous with respect to PWM unit so the last value written before period ends shall be the new value for the duty.

Usually all it works fine, but sometimes (once in 3-4 hours) starting from a steady temperature we have notice that PWM has a strange behavior like PWMDTY5 was loaded with 0xFF even if monitoring pid output this value is not written in the register, infact once the temperature is stable duty value from PID are about few units.

What we have noticed is that this always happens if duty value is written immediately after period end, when PWMCNT5 should be 0 if i'm right since conter is increased every 8 ms. I've attached an image with yellow trace for the PWM (it is negated by hardware port) and green trace for debug pin befor (high) and after (low) PWMDTY5 writing.

I was wondering if some have you have ever seen phenomena like this or have something to suggest to me like workaround.