PWM with PIC16F877A

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Rabbit
Posts: 28
Joined: Wed Apr 04, 2012 1:33 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

PWM with PIC16F877A

Post 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
Attachments
Screenshot1.png
Project-Options
(40.57 KiB) Downloaded 2766 times
ADC Controlled PWM 16F877A-V1.fcf
(7.5 KiB) Downloaded 280 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM with PIC16F877A

Post 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
Attachments
ADC Controlled PWM 16F877A-V1a.fcf
(7.5 KiB) Downloaded 356 times
Martin

Rabbit
Posts: 28
Joined: Wed Apr 04, 2012 1:33 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: PWM with PIC16F877A

Post 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM with PIC16F877A

Post 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
Martin

Rabbit
Posts: 28
Joined: Wed Apr 04, 2012 1:33 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: PWM with PIC16F877A

Post 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

Post Reply