Pulse Width Modulation Navarro Pierre pierre.navarro@imag.fr Roche Guillaume guillaume.roche@hikob.com
Pulse Width Modulation Besoin de TMRx_PS et Prx donc des timers! Ici timer2: Fosc = 64MHz TMR2_PS = ??? PR2 = 0xFF = ??? Commande entre 10KHz et 20KHz ~ 15KHz PWM
Pulse Width Modulation 1 – Header #include "pwm.h" #include "timers.h" 2 – Init // Fixed by timer2 // PR2 = 0xFF TMR2_PS = 4 Fosc = 64MHz // PWM Period = [(PR2)+1]*4*Tosc*TMR2_PS // PWM Period = 256 * 4 * 4 * 1/64MHz // PWM freq = 15,625 KHz OpenTimer2(T2_PS_1_4); PR2 = 0xff; // Config eccp1 eccp2 CCP1CON = 0x0C; // Mode PWM CCP2CON = 0x0C; // Mode PWM 3 – Use SetDCEPWM1(VITESSE_0_1024); SetDCEPWM2(VITESSE_0_1024); PWM