inverted pwm

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
greentech
Flowcode V4 User
Posts: 158
Joined: Mon Jan 31, 2011 2:11 pm
Has thanked: 10 times
Been thanked: 2 times
Contact:

inverted pwm

Post by greentech »

Hi,
Is there any way i can create a normal & inverted pwm using 16f877a?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: inverted pwm

Post by Benj »

Hello,

You could have the PWM output pin connected to an input pin with interrupt on change enabled. This way every time the PWM pin changes the interrupt will fire and you can read the state on the input pin and then toggle another output pin to be the mirror of the first PWM pin.

Obviously there will be a slight delay in doing this and the faster your PWM the more work your processor will have to do to keep up.

A better way might be to do the inversion using external hardware such as a couple of transistors to give you a push pull control signal.

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: inverted pwm

Post by medelec35 »

Hi greentech,
What about adapting this for your target device?
http://www.matrixmultimedia.com/mmforum ... 84&#p26295
Martin

User avatar
greentech
Flowcode V4 User
Posts: 158
Joined: Mon Jan 31, 2011 2:11 pm
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: inverted pwm

Post by greentech »

transistor option is better? will it cause some delays too? pls recommend a good circuit benj. Problem with pic 12 is less io's martin.

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: inverted pwm

Post by medelec35 »

greentech wrote:Problem with pic 12 is less io's martin.
The advantage of using Flowcode is you can change target device to suit your application.
I'm not stating it perfect as there is about 15 to 35 microseconds between one pwm inversion to the other one.
inverted 16F877A.png
(117.05 KiB) Downloaded 6855 times
Attached is a flowchart for 16F877a
At least you can see if it works for your application, if not then its Ben's method.

Martin
Attachments
PWM 180 inv 16F877A.fcf
(7 KiB) Downloaded 443 times
Martin

User avatar
greentech
Flowcode V4 User
Posts: 158
Joined: Mon Jan 31, 2011 2:11 pm
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: inverted pwm

Post by greentech »

Martin i wanna use pwm for driving an H-Bridge. H-Bridge is used to power a stepup transformer. Is it ok to have this much delay?

User avatar
greentech
Flowcode V4 User
Posts: 158
Joined: Mon Jan 31, 2011 2:11 pm
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: inverted pwm

Post by greentech »

Plenty of signals are lost too while outputting other instructions. How much time these flowcode macros take? Macros such as ADC, PWM, LCD Display, etc.

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: inverted pwm

Post by medelec35 »

Hi greentech,
For the inverted signal to be as accurate as possible then interrupt needs to be running very fast.
Due to that, there is not much time in between services for running other macros.
Interrupt is slowed down too much, then inversion could be missed.
Therefore I do not recommend this method being used for H bridge.

The alternatives I can think of is either Bens suggestion or using a different target device with ECCP h-bridge driving already built in.
Since Flowcode does not support this, then C block will have to be used to generate H-bridge signals.

Martin
Martin

User avatar
greentech
Flowcode V4 User
Posts: 158
Joined: Mon Jan 31, 2011 2:11 pm
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: inverted pwm

Post by greentech »

martin can u suggest me a chip having equal as much IO's as 16f877a have?
another problem in Flowcode 5 ADC Conversion i am posting sc's for details.
Attachments
report fc4.jpg
(180.69 KiB) Downloaded 3707 times

User avatar
greentech
Flowcode V4 User
Posts: 158
Joined: Mon Jan 31, 2011 2:11 pm
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: inverted pwm

Post by greentech »

program compiled with fc4 runs ok but adc prog compiled by fc5 gives this error

{"ADC Conversion started before wait time has expired following previous conersion or channel change"} i dont know why?

program speed set on both fcv4 & 5= 20MHZ
Attachments
report to MM.jpg
(242.32 KiB) Downloaded 3705 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: inverted pwm

Post by medelec35 »

greentech wrote:martin can u suggest me a chip having equal as much IO's as 16f877a have?
16F1934 has same number of pins, 35 i/o pins 14 of which are ADC. Full bridge capability of which I have not had any dealings with.

Martin
Martin

User avatar
greentech
Flowcode V4 User
Posts: 158
Joined: Mon Jan 31, 2011 2:11 pm
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: inverted pwm

Post by greentech »

I have been searching google for a transistor circuit that could invert my pwm signals from uC couldnt find one. Benj can u suggest me a resource for this circuit?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: inverted pwm

Post by Benj »

Hello,

Transistors can normally operate at several hundred MHz so should be no noticeable delay issues.

Here is a circuit that may do it for you. When one load is active the other is not.
v1.jpg
v1.jpg (13.52 KiB) Viewed 11311 times
R2 has current flowing through it when the PWM signal is high.
R4 has current flowing through it when the PWM signal is low.

For this circuit to work correctly the positive power rail must be equal to VCC eg 5V to allow the PNP type transistor to switch off.

If you need more voltage then this is possible.

Also if the load is inductive (motors / coils etc) then you needs diodes in parallel with the load to stop any back EMF reaching the microcontroller.

Or do you need a push pull type configuration for a single load like a motor H-bridge?

User avatar
greentech
Flowcode V4 User
Posts: 158
Joined: Mon Jan 31, 2011 2:11 pm
Has thanked: 10 times
Been thanked: 2 times
Contact:

Re: inverted pwm

Post by greentech »

Benj thanks alot for your post. Your posts are always enlightening.I am trying to create pwm to control and H-Bridge which would then drive 10-0-10 step-up transformer.

Post Reply