Page 1 of 1
PWM with PIC16F877A
Posted: Fri Jul 25, 2014 10:53 am
by Rabbit
Hello experts,
I modified a PWM-Programm from the forum. The ADC-input is correctly 0...5V at AN0 = Pin2.
But there is no output at Pin 17 (CCP1).
Project-Options and fcf-file are at the attachments.
I would be pleased about your help.
Best Regards
Rabbit
Re: PWM with PIC16F877A
Posted: Fri Jul 25, 2014 11:33 am
by medelec35
Hi Rabbit, I have modified your flowchart slightly so PWM enable is outside the main loop.
I have also added a small delay.
How is pin 1 connected?
It must have 5V (well logic 1) in order for hardware to work.
I would use a 10K resistor connected to +5V
for hardware What osc are you using?
you have got flowchart configuration set to HS therefore a crystal + caps or resonator of 19.66MHz should be wired up correctly .
You will need to check its working properly so flashing an led at 1Hz is always a good starting point, before developing anything else.
Perhaps you can post a circuit diagram?
Tiny Cad
Looks good for producing circuit diagrams and it's free!
Tiny Cad Download Link
Martin
Re: PWM with PIC16F877A
Posted: Mon Jul 28, 2014 8:03 am
by Rabbit
Hi Medelec35,
Have many thanks for your fast solution.
You are right, I tested the EB006-board with a 1Hz flashing LED. All ok - only the PWM-part of my programm do nothing.
So I downloaded your modified flowchart. Yes, it's running well.
But I have a question:
First I'm testing your programm with the 50ms Delay - running.
Now I delete the Delay - programm is running!
So I think the Delay is not necessary.
Do you know in which cases I should use the Delay?
Best Regards
Rabbit
Re: PWM with PIC16F877A
Posted: Mon Jul 28, 2014 11:55 am
by medelec35
Hi Rabbit,
I use the delay as a matter of habit since without the delay I have had an issue in the past when controlling two CCP pwm modules.
Also If re-read ADC too quickly and internal cap not discharged fully before ADC is re-read then there could be an ADC error.
You may indeed get away without using any delays, but since I did not try flowchart on hardware first, I thought I would be safer than sorry.
Martin
Re: PWM with PIC16F877A
Posted: Mon Jul 28, 2014 12:28 pm
by Rabbit
Hi Martin,
Thank you for your answer. In my future flowchart the loop will be much longer. So I will try to read the ADC without Delay.
Klaus