#define TM1MOD 0x3E4
//2.3khzTM1Freq/1MHZCpuFreq
void PWM_Init(void)
{
unsigned int freq;
/* TPM1SC:
TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */
setReg8(TPM1SC,
0x00);
/* Disable device */
/* TPM1C0SC:
CH0F=0,CH0IE=0,MS0B=1,MS0A=1,ELS0B=1,ELS0A=1,??=0,??=0 */
setReg8(TPM1C0SC,
0x3C);
/* Set up PWM mode with output signal level low */
RatioStore =
0xFFFFU;
/* Store initial value of the ratio */
/* TPM1MOD:
BIT15=0,BIT14=0,BIT13=0,BIT12=1,BIT11=1,BIT10=1,BIT9=1,BIT8=1,BIT7=0,BIT6=0,BIT5=1,BIT4=0,BIT3=0,BIT2=0,BIT1=0,BIT0=0
*/
// setReg16(TPM1MOD,
0x1F20U); /* Set
modulo register */
freq=TM1MOD*cpu_speed; // ??
setReg16(TPM1MOD,
freq); /* Set
modulo register */
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 */
setReg8(TPM1SC,
0x48);
/* Run the counter (set CLKSB:CLKSA) */