AnsweredAssumed Answered

S12Z Output Compare Module Unexpected Behaviour

Question asked by Kas Lewis on Jul 11, 2016
Latest reply on Jul 13, 2016 by Kas Lewis


I have been working with the S12ZV trying to get the OC to change the state on the output pin when the next interrupt occurs. The issue I have been facing is that instead of the next event causing the effect on the output pin the change happens IMMEDIATELY. I have included my TEST below.

 

void output_compare_software_controled(int number_of_pulses, int low_duration, int high_duration){   long i = 0;   int j = 0;     TIM0TSCR1 |= 0x80; //Enable OC module    TIM0TIE = 0x00;   TIM0TTOV = 0x00;   TIM0TFLG1 = 0xFF;   TIM0TFLG2 = 0xFF;    TIM0TIOS = 0x02; //Set channel 1 as OC   TIM0TCTL2 = 0x0C; //Set pin output on next OC event   TIM0OCPD &= ~0x02; //Enable the timer channel port for desired action   TIM0CFORC = 0x02; //Force OC action on specified channel     for(j = 0; j < number_of_pulses; j++){     for(i = 0; i < high_duration; i++){       //Wait      }     PTS_PTS1 = 0;//***********     PTS_PTS2 = 0;//***********     TIM0TCTL2 = 0x08; //Clear pin output on next OC event     TIM0OCPD = 0x00; //Enable the timer channel port for desired action     TIM0CFORC = 0x02; //Force OC action on specified channel      PTP_PTP7 = 0;     for(i = 0; i < low_duration; i++){       //Wait      }     PTS_PTS1 = 1;//***********     PTS_PTS2 = 1;//***********     TIM0TCTL2 = 0x0C; //Set pin output on next OC event     TIM0OCPD = 0x00; //Enable the timer channel port for desired action     TIM0CFORC = 0x02; //Force OC action on specified channel    } }    }

 

I understand that this is NOT interrupt driven but the behaviour is the same. When the code reaches line 14, 24 or 33 the state of the pin changes immediately. What should happen is that the state should only change when the code reaches line 16, 26 or 35 when the force register is set indicating that the change should happen.

 

I have similar code running that initializes the code in a function and sets the compare register to a set value but again the change happens when reaching TCTL2 and not when the next interrupt occurs. Any help in resolving this issue would be very much appreciated.

 

Thanks

Kas

Outcomes