Home › Forums › Microcontrollers › PIC Microcontroller › PWM by pic 16F877A
- This topic has 5 replies, 4 voices, and was last updated 9 years, 5 months ago by Ligo George.
-
AuthorPosts
-
March 1, 2015 at 12:39 am #10940YashParticipant
Hey guys,
I am using 16F877A to output PWM, increasing and decreasing it via two push buttons its based on the code used in DC Motor Speed Control using PWM with PIC Microcontroller in MikroC but the problem is that after a certain PWM value the PWM will not decrease and I have also added a switch with instantly makes duty value zero but it also doesn’t work after a certain pwm value and I have tried it on Proteus as well as with leds in real life but they give the same result. Only way it goes low is to keep pressing the UP button then some how it come down to a low value then other two switches start working and I then can switch it pwm off. Don’t know whats wrong.
Here is the code:-
{ adc = ADC_Read(1); // Get 10-bit results of AD conversion rpm_temp = adc * 2; //converting analog value to rpm WordToStr(rpm_temp, speed_out); //converting integer to string to disply on LCD Lcd_Out(2,9,speed_out);//Write speed in 2st row 6th col Delay_ms(100); if (RD0_bit ==0 && duty<250) //if button on RD0 pressed { Delay_ms(100); duty = duty + 10; //increment current_duty PWM1_Set_Duty(duty); //Change the duty cycle } if (RD1_bit ==0 && duty >0) //button on RD1 pressed { Delay_ms(100); duty = duty - 10; //decrement duty PWM1_Set_Duty(duty); } if (RD2_bit ==0 && duty >0) //button on RD2 pressed { Delay_ms(100); duty = 0; //reset duty PWM1_Set_Duty(duty); }
March 1, 2015 at 11:10 am #10943Ligo GeorgeKeymasterMikroC libraries are working fine without any problem. Try the following link.
March 1, 2015 at 11:53 pm #10953sandeepParticipantHi Ligo,
As i also have problem on pwm, so i thought posting my doubt over here is fine.but i work on mplab.
I just tried to run a pwm with the duty cyle of 78% of the period, but it is not working on proteous, suggestions pls.
void main() { PR2=0xFF;//setting period=0.0002048 CCP1CON=0b00001100;//setting to pwm mode<3:0> and duty value<5:4> CCPR1L=0xC8; //setting value of 800 to make duty=0.00016,which //is 78% of period. //T2CON=0b00000001;//prescale<1:0> of1:4 T2CKPS0=1; T2CKPS1=0; TMR2ON=1; //timer2 is on i.e clock pulses are provided. }
March 2, 2015 at 11:36 am #10954Ligo GeorgeKeymasterFor MPLAB you can use the following link.
Generating PWM with PIC Microcontroller – MPLAB Hi-Tech C
That code is working fine for me.
July 3, 2015 at 12:37 pm #11538ShubhamParticipantHi Ligo
i want a generate a pulse with 1 uS ON time. the total time period is 255 uS. the duty cycle for this wave is 0.003984. but when i try to stimulate it in proteus the ON period comes out to be 0.1 uS. the code which i have written is as follows:
void main(void)
{
TRISC2_bit=0;
PWM1_Init(3920);
PWM1_Start();
while(1)
{
PWM1_Set_Duty(0.09996);
}
}please help me out as i m novice in using PIC Microcontroller.
July 3, 2015 at 2:36 pm #11539Ligo GeorgeKeymasterHi,
You can’t use parameter 0.09996 in that function. The parameter duty can be any value ranging from 0 to 1023 corresponding to 0 to 100% duty cycle.
Please don’t post your problems in someone else’s topic, open a new topic.
-
AuthorPosts
- You must be logged in to reply to this topic.