Page 1 of 1

inverted pwm

Posted: Wed Mar 20, 2013 10:39 am
by greentech
Hi,
Is there any way i can create a normal & inverted pwm using 16f877a?

Re: inverted pwm

Posted: Wed Mar 20, 2013 10:52 am
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.

Re: inverted pwm

Posted: Wed Mar 20, 2013 11:41 am
by medelec35
Hi greentech,
What about adapting this for your target device?
http://www.matrixmultimedia.com/mmforum ... 84&#p26295

Re: inverted pwm

Posted: Sat Mar 23, 2013 8:06 am
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.

Re: inverted pwm

Posted: Sat Mar 23, 2013 4:34 pm
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

Re: inverted pwm

Posted: Fri Mar 29, 2013 8:28 am
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?

Re: inverted pwm

Posted: Fri Mar 29, 2013 8:50 am
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.

Re: inverted pwm

Posted: Fri Mar 29, 2013 10:31 am
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

Re: inverted pwm

Posted: Fri Mar 29, 2013 12:30 pm
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.

Re: inverted pwm

Posted: Fri Mar 29, 2013 12:38 pm
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

Re: inverted pwm

Posted: Fri Mar 29, 2013 2:43 pm
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

Re: inverted pwm

Posted: Fri Apr 05, 2013 1:39 pm
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?

Re: inverted pwm

Posted: Fri Apr 05, 2013 4:28 pm
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 11501 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?

Re: inverted pwm

Posted: Sun Apr 07, 2013 8:27 am
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.