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

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

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

Jump to solution
1,174 Views
Braulio_Cespede
Contributor III

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.

Labels (1)
Tags (3)
1 Solution
948 Views
eduardo_viramon
NXP Employee
NXP Employee

Braulio,

From your init code, you are setting an 8-bit count because you are writing the modulo value with 0x00FF (you write 0 to the high byte and 0xFF to teh low byte). This means that channel will count up to 0x00FF.

For the full 16-bit counting you actually need to leave the modulo value with 0x0000, per the reference manual, this will cause the counter to count the full 16-bit range. i also notice that your ActualRatio variable is an 8-bit value, you will have problems with this as well. Change variable to 16 bit declaration and compare 100% duty cycle with 0xFFFF.

Basically, the counter will count up to the modulo value, so whatever value you write there is the number of bits of your PWM signal.

Hope this clarifies everything,

Eduardo V.

View solution in original post

0 Kudos
Reply
4 Replies
948 Views
eduardo_viramon
NXP Employee
NXP Employee

Braulio,

Your question is not very clear. Can you explain in more detail what you are trying to do?

Also, please include your timer init code.

Tks,

Eduardo V.

0 Kudos
Reply
948 Views
Braulio_Cespede
Contributor III

Hi Eduardo, Thanks for answer.

I'm working with the MC13234, It's a Zigbee micro controller with a HCS08 core.

I have read the data sheet to make a PWM component. I made it, but It's just works at 8 bits.

I need to make it works a 16 bits.

Thanks for advanced.

0 Kudos
Reply
949 Views
eduardo_viramon
NXP Employee
NXP Employee

Braulio,

From your init code, you are setting an 8-bit count because you are writing the modulo value with 0x00FF (you write 0 to the high byte and 0xFF to teh low byte). This means that channel will count up to 0x00FF.

For the full 16-bit counting you actually need to leave the modulo value with 0x0000, per the reference manual, this will cause the counter to count the full 16-bit range. i also notice that your ActualRatio variable is an 8-bit value, you will have problems with this as well. Change variable to 16 bit declaration and compare 100% duty cycle with 0xFFFF.

Basically, the counter will count up to the modulo value, so whatever value you write there is the number of bits of your PWM signal.

Hope this clarifies everything,

Eduardo V.

0 Kudos
Reply
948 Views
Braulio_Cespede
Contributor III

Thanks you, It's works perfect.

There were minor modification I have to do, but not a great thing.

Thanks again :smileyhappy:.