-6
\$\begingroup\$

i am trying to do an simple PWM example in mikroC program using ISIS simulator for pic16f877a and i used the code in the program help and it didnt work

for(;;)
{
    Pwm_Init(5000);
    pwm_start();
    delay_ms(500);
}
\$\endgroup\$
  • 1
    \$\begingroup\$ There is too little to go on here - is this the whole of your code? How didn't it work? What is the error message? \$\endgroup\$ – Oli Glaser Oct 7 '12 at 21:04
  • 1
    \$\begingroup\$ "Didn't work" is a useless description. \$\endgroup\$ – Olin Lathrop Oct 7 '12 at 21:12
  • \$\begingroup\$ i think this the code used to start the pwm in mikroC i want to use pwm in a project but first i need to see how it works first and make sure that it works \$\endgroup\$ – alone Oct 8 '12 at 16:24
  • \$\begingroup\$ it "didnt work" there is no errors in compiling but the problem that it do not work in the simulation ....i am sorry for being not clear in my question ..:) \$\endgroup\$ – alone Oct 8 '12 at 16:46
2
\$\begingroup\$

PWM needs at least 2 parameters. You only supply the 5000, which will probably be the frequency, but what about the duty cycle? If you don't initialize that and it defaults to 0 or 100 %, then you won't see anything.

edit
It appears you have to call the function Pwm_Change_Duty() with a value between 0 (minimum) and 255 (maximum) to set the duty cycle.
end of edit

Most microcontrollers with PWM will have more than 1 PWM channel, so you'll have to tell the program which channel you want to use as well.

Also, I don't know what Pwm_Init() and Pwm_start() do exactly, but normally they should be outside your main loop. Now you're executing them again and again. IMO should be

Pwm_Init(5000);  
pwm_start();  
for(;;)
{ 
  delay_ms(500); 
}, 

and then the delay() serves no function, so that you can omit it:

Pwm_Init(5000);   
pwm_start(); 
for(;;)
{ 
}. 
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ ok i am just asking.... this is the code i saw in the help i used the code pwm_change_duty(value) and it didnt work so i think there is another thing to do so the pwm work on the ISIS \$\endgroup\$ – alone Oct 8 '12 at 16:16
  • \$\begingroup\$ @alone - but have tried the Pwm_Change_Duty() I mention in my answer? And you also haven't answered Oli's question: what does "doesn't work" mean? What do you observe? If you can add details to the question it may be reopened. \$\endgroup\$ – stevenvh Oct 8 '12 at 16:22
  • \$\begingroup\$ of course .... the code compile very will and there is no error in compiling but in the simulation it do not work thats my problem \$\endgroup\$ – alone Oct 8 '12 at 16:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.