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 mikroC compiler for dsPIC30F microcontrollers. Fig. 13-6 shows the electric diagram of the realized continuous PWM of a LED diode connected to PORTE.0.
Fig. 13-6 The electric diagram of the realized continuous PWM of a LED diode connected to PORTE.0.
unsigned int i; unsigned int duty_50; void main(){ ADPCFG = 0xFFFF; PORTB = 0xAAAA; TRISB = 0; Delay_ms(1000); duty_50 = Pwm_Mc_Init(5000,1,0x01,0); // Pwm_Mc_Init returns 50% of the duty Pwm_Mc_Set_Duty(i = duty_50,1); Pwm_Mc_Start(); do { i--; Pwm_Mc_Set_Duty(i,1); Delay_ms(1); if (i == 0) i = duty_50 * 2 - 1; // Let us not allow overflow PORTB = i; } while(1); }//~