Download 31295018467604
Transcript
The HC12 has the option to select either left-aligned or centered-aligned output. In this project left alignment was selected to simplify the deduction ofthe formulas to achieve the desired frequency. Figure 5.6 shows the block diagram ofthe PWM left aligned module. CLOCK SOURCE (ECLK) CENIR - 0 FROM POP r p DAI A REGISIER ^^ P* CJMfc PWCNlx UPCOUNItRONLY CLOCf .EDGt S YNC RESt 1 8-Bll COMPARE PWDlYx S Q i 8-BIIC0f<(PARE^ 1 1 -*" 1 MUX MUX ^ R i k PWPERx fOPIN DRIVER i i •^POLx 1 1 WENx ' PPOL ^ 0 PPOL-1 - * - PWDIY - ^ _ * • • FIWPLR Figure 5.6. PWM left aligned output channel. The last step it is to set the period ofthe waveform and the duty cycle. The PWM channel work as follow. The PWCNTx register (counter) will start counting up. When PWCNTx is equal to PWDTYx (duty cycle), the output bit is set accordingly to the polarity, but PWCNTx will continue counting up. When PWCNTx reaches PWPERx (period), PWPERx causes the output bit to be reset, and also causes PWCNTx to be reset to zero, then starts again. It is important to note that the resolution ofthe duty cycle depends on the value of PWPERx. The larger the PWPERx value, the more accurate the duty cycle can be adjusted. In order to have this, the period needs to be as large as possible. For this project, the frequency ofthe signal was selected to be lOkHz. The clock A and B was set for 2MHz (prescalar of 2 on PWCLK). Clock SO and SI were not used. The PWPER set for 200d (out of 255d). The formula is as follows: 31