Re: pwm
|
||||
---|---|---|---|---|
初級會員
|
謝謝先進的回答我以明白pwm 算法
再此想再請教一個問題 這是 201 ASP 裡的範例 Put CCP1 module in PWM mode, Configure CCP to clear DCB1 and DCB0 ( no Q cycles) movlw 0x0C 這行會自己判斷 mode對嗎 如果改成0x2c會如何呢 movwf CCP1CON ---------------------- 看不太明白這意思也??是自己會判斷還是如何呢?? bit 5-4 DC1B<1:0>: PWM Duty Cycle Least Significant bits Capture mode: Unused. Compare mode: Unused. PWM mode: These bits are the two LSbs of the PWM duty cycle. The eight MSbs are found in CCPR1L
發表於: 2008/1/9 22:33
|
|||
|
Re: pwm
|
||||
---|---|---|---|---|
中級會員
|
依你的敘述,我以16F684為例…
PWM Period =(PR2+1) * 4 * TOSC * TMR2 Prescale Value 已知 PWM Period = 64us, TOSC = 1 / 8MHz, TMR2 Prescale Value = 1 代入上述公式即可得到PR2 = 127,而 Duty Cycle Value = PR2 * 25% = 127 * 25% = 31.75 當然你也可以調整TOSC或TMR2 Prescale Value的設定值(1、4、16),來符合你的需求,只不過PWM的解析度也會因此而改變,更詳細的說明請參閱datasheet。以上說明,希望對你有幫助…
發表於: 2008/1/9 8:56
|
|||
|
Re: pwm
|
||||
---|---|---|---|---|
資深會員
|
我想應該是這樣子算的...
8MHz,內部頻率是8/4=2MIPS=0.5uS per instruction b’01111111’ = 0x1F --> 計數 0~127 = 128 0.5 * 128 = 64uS b’00011111’ = 0x1 F--> 計數 0~31 = 32 32 / 128 = 0.25 = 25%
發表於: 2008/1/9 8:48
|
|||
|
pwm
|
||||
---|---|---|---|---|
初級會員
|
你好:
請問該64uS .Duty Cycle 怎算出來的呢.有看datasheet...但他是根據什麼算出來還是不明白..煩請各位先進指導...謝謝 ;Set up Period and Duty Cycle using an 8MHz oscillator movlw b’01111111’ movwf PR2 ;Load a 64uS Period Value movlw b’00011111’ movwf CCPR1L ; Load Duty Cycle Value (25%) of PWM period
發表於: 2008/1/8 20:58
|
|||
|