0 item/s in cart
The example shows the realization of continuously varying pulse width modulation (PWM). The continously modulated output is on the PORTE.0 pin which is monitored by a LED diode. The realization is carried out by using the mikroBasic compiler for dsPIC30F microcontrollers. Fig. 13-6 shows the electric diagram of the realized continuous PWM of a LED diode connected to PORTE.0.
program MC_PWM_Test dim i, duty_50 as word main: ADPCFG = 0xFFFF TRISE = 0 PORTB = 0xAAAA TRISB = 0 Delay_ms(1000) duty_50 = Pwm_Mc_Init(5000,1,0x01,0) ' Pwm_Mc_Init returns 50% of the duty i = duty_50 Pwm_Mc_Set_Duty(i, 1) Pwm_Mc_Start() while true i = i - 1 Pwm_Mc_Set_Duty(i,1) Delay_ms(1) if (i = 0) then i = duty_50 * 2 - 1 ' Do not allow the overflow end if PORTB = i wend end.