AnsweredAssumed Answered

How to set a PWM output of 8-bits to 16-bits on HCS08?

Question asked by Braulio_Cespedes on May 19, 2014
Latest reply on May 20, 2014 by Braulio_Cespedes

Hi again everyone.

 

I need help with this component, I working on the MC13234 and I have problems setting the configuration of the PWM output to work at 16-bits.

 

This is the code:

Init_ Code

void PWM_Init(void)

{

  /* TPM1SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0*/

  TPM1SC  =  0x00U;         /* Disable device */

  /* TPM1C0SC: CH0F=0,CH0IE=0,MS0B=1,MS0A=0,ELS0B=0,ELS0A=1,??=0,??=0 */

          /* Set up PWM mode with output signal level high*/

  TPM1C0SC =  0x24U;

  ActualRatio = 0x00U;           /* Store initial value of the ratio */

PWM_EnEvent = TRUE;                   /* Enable events */

  /* TPM1MODH: BIT15=1,BIT14=0,BIT13=1,BIT12=1,BIT11=1,BIT10=1,BIT9=1,BIT8=1,BIT7=1,BIT6=1,BIT5=1,BIT4=1,BIT3=1,BIT2=1,BIT1=1,BIT0=1 */

  /* Set modulo register, Also this is the timer Module*/

  TPM1MODH =0x00;

  TPM1MODL =0xFF;        

  SetRatio();                          /* Calculate and set up new values of the compare according to the selected speed CPU mode */

  /* TPM1SC: TOF=0,TOIE=1,CPWMS=0,CLKSB=0,CLKSA=1,PS2=0,PS1=0,PS0=0 */

  TPM1SC =  0x48U;              /* Run the counter (set CLKSB:CLKSA)  */

}

 

Code_SetRatio

void SetRatio(void)

{

uint8_t temparray[2]={0,0};

  temparray[0]=(uint8_t) (ActualRatio >> 8);

  temparray[1]=(uint8_t) (ActualRatio);

if (ActualRatio >= 0xFF) {  /* Duty = 100%? */

   temparray[0]=0x00;

   temparray[1]=0xFE;

    TPM1C0VH = temparray[0];                 /* Store new value to the compare reg. */

    TPM1C0VL = temparray[1];

  } else {

   TPM1C0VH = temparray[0];           

   TPM1C0VL = temparray[1];

    }

}

 

 

What I need to do is set the PWM from 8-bits to 16-bits output.

Can someone help me with this?, I will appreciate so much.

Outcomes