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) */ } |