inverted pwm
Moderator: Benj
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
Hi greentech,
What about adapting this for your target device?
http://www.matrixmultimedia.com/mmforum ... 84&#p26295
What about adapting this for your target device?
http://www.matrixmultimedia.com/mmforum ... 84&#p26295
Martin
- 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
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.
-
- 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
The advantage of using Flowcode is you can change target device to suit your application.greentech wrote:Problem with pic 12 is less io's martin.
I'm not stating it perfect as there is about 15 to 35 microseconds between one pwm inversion to the other one. 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 444 times
Martin
- 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
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?
- 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
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.
-
- 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
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
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
- 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
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.
another problem in Flowcode 5 ADC Conversion i am posting sc's for details.
- Attachments
-
- report fc4.jpg
- (180.69 KiB) Downloaded 3707 times
- 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
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
{"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
-
- 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
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.greentech wrote:martin can u suggest me a chip having equal as much IO's as 16f877a have?
Martin
Martin
- 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
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?
- 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
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.
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?
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.
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?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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
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.