pwm tutorial

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
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

pwm tutorial

Post by Steve001 »

looking for a tutorial on Pwm function if anybody can point me in the right direction please i can remember seeing something on this a while ago but cannot find it . .

i have some questions if someone can help

1. Can the PWM be syncd to another signal I.E a pulse input so as to act as a zero crossing ? would i be better using a look up table for this or is that going to open a big can of worms ?

2. Can a ADC val be fed back into it as to act as feedback to alter the position of the signal compared to another adc val for a ref.

3. where do these ideas come from ?? :lol:

Steve
Success always occurs in private and failure in full view.

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: pwm tutorial

Post by JohnCrow »

1 in 10 people understand binary, the other one doesn't !

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: pwm tutorial

Post by Enamul »

Can the PWM be syncd to another signal I.E a pulse input so as to act as a zero crossing ?
This could be used with RB0/INT but better if PWM frequency is not very high..I guess it will work..By the way why you are looking for this.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: pwm tutorial

Post by Steve001 »

Thanks for your replys guys will look at those and have a play when i get a bit of time ,

The reason for this because at work one of the things that we do is to verify that Ct's ( Current Transformers ) are connected in there correct orientation and that the ratio's are correct and have to record this on a test report for the metering been tested L1,L2,L3 (sometimes N) one of the major problems that i have is we also have a AMADA Vipros 358 Queen next door in our fab shop which upsets the mains somewhat . . (mesured at between 60 and 80 Amps a HIT !) if the factory is lightly loaded then this disturbance becomes a right royal pain.

This project is an atempt to stablise the test as the mains volts can move about around 1 volt or so this results in a current increase or decrease of several amps sometimes more on the tests if they are chomping out say a transformer housing it can be 2 - 3 hits a secound . :(

Steve
Success always occurs in private and failure in full view.

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 tutorial

Post by medelec35 »

PWM is triggered when tmr2 = pr2

So If you use INT interrupt (B0) as Enamul suggested then you could place a C box with:

Code: Select all

tmr2=pr2;
Within interrupt.

Then PWM will be forced to go high when signal changes on B0 from high to low or low to high depending on interrupt settings.

If PWM is already high when interrupt is triggered, then the PWM will remain high for the whole on duration.
E.g if PWM is normally high for 1ms, suppose pwm has been triggered 500us ago , then PWM will be high for a total of 1.5ms

Can you give more details e.g PWM frequency and duty.
target device & osc frequency.
All the details you can.

I guess you could alter the position of PWM by disabling timer2, wait until yo require triggering, then re-enable timer2 with again tmr2=pr2
to force PWM to go high.

Alternatively if a lower frequency is required for PWM than built in PWM can produce, then you would need to use bit bang method.

It should still be possible to sync with an external trigger signal

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: pwm tutorial

Post by Steve001 »

i have some scribbles of drawings and idea's will scan them tomorrow at work and post

Steve
Success always occurs in private and failure in full view.

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: pwm tutorial

Post by Steve001 »

first of all sorry for the poor quality had to reduce resolution so that i can upload them the drawing are a bit rough and the resistor values are not yet worked out.
I will try and make better drawing and work some values out this week hope you can get the jist of what i am tring to do.

Some of the drawings i scanned uside down you can rotate then in adobe ( View - Rotate view)

some notes are :-

In the original drawing the ct ratio is shown as 250:5 it should be 300:5

The voltage detection circuit the resistor values need to be adjusteted somewhat for 5 volts the circuit shown was for another project i did that fed in 110 Vdc
i was thinking of either adding some more resistance to the front end to monitor the input the the load transformer as the output voltage is only 0 - 5 vac.
or making a buffer amp to look at the output voltage i am not too sure witch would be best as the input to the load transformer has a greater range of voltage adjustment.

the zero crossing crossing circuits.

Both circuits work the one with the 555 i did some years ago when i did my HNC it produces a 720 Hz pulse train which i then used ripple counters and an oscillator for phase control .

the triac driver is not tried and tested but comes from the MOC3021 Data sheet

I have decided against using the two thyristor and pluse transformers - getting to complex

Any comments / sujestions welcome will try and make a proper drawing this week

Steve
Attachments
flow chart.pdf
(62.43 KiB) Downloaded 524 times
circuit scribbles.pdf
(159.89 KiB) Downloaded 558 times
block diagram.pdf
(36.49 KiB) Downloaded 513 times
Success always occurs in private and failure in full view.

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: pwm tutorial

Post by Steve001 »

got asked this in a pm
How do you know that it takes that much current per hit ?
We have access to power quality messuring equipment at work as i work in the electrical power industry for a company that manufatures electrical substations.

The machine was temporary wired to an ION 7650 .

Any infomation that you may require can be obtained !

steve
Success always occurs in private and failure in full view.

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 tutorial

Post by medelec35 »

Hi Steve,
there are several was to provide a pulse during zero crossing.

One way is use two transistors one NPN and the other PNP connected to a secondary of a step down transformer (via current limiting resistors)
Since you are probably using a transformer to supply microcontroller?

Note: Only bases are connected via AC side, since transistors CE will work from DC only.

Idea being transistors will be on during positive or negative 1/2 cycles which can pull an output down.
When both are off during zero crossing, then o/p will be allowed to go high thereby producing a pulse.

Not got time now, but I can draw and post a circuit later today.

Martin
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: pwm tutorial

Post by medelec35 »

Hi Steve,
Attached is one way of using transistors for zero crossing.
Another way is to use a high value resistor connected between ac and i/p to microcontroller.
I have successfully used this method by connecting 1Meg directly to mains so it does work.
But for safety reasons it will be better to connect resistor to ac via sec of transformer, just like it is with transistors.
The single resistor version relies on the internal clamp diodes of micro, but detection routine is a bit more complex as with detecting voltage, it can only detect when positive ½ cycle reduces to just under 1V.
Also after negative ½ cycle there will not be a change detected until voltage goes though whole negative ½ cycle though zero and though positive ½ cycle above about 2V.
Attachments
Zero Crossing.png
(17.09 KiB) Downloaded 8194 times
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: pwm tutorial

Post by Steve001 »

thanks for that martin , got a couple of hectic days ahead of me so i am unable to spend much time on it.
I hope to have a good go at it at the weekend

Steve
Success always occurs in private and failure in full view.

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: pwm tutorial

Post by Steve001 »

morning all,

Bit of a dum question . can anybody tell me which pin(s) dose the PWM output come from please ? as i have no idea whatsoever :(

Is it pin 16 & 17 the RC1/T1OSI/CCP2 & RC2/CCP1 pins ?

http://uk.farnell.com/microchip/pic16f7 ... dp/9760679

I have done some test mesurement this week with the test kit and i am redoing the circuit

steve
Success always occurs in private and failure in full view.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: pwm tutorial

Post by Enamul »

Hi Steve,
Is it pin 16 & 17 the RC1/T1OSI/CCP2 & RC2/CCP1 pins ?
PWM 1 is CCP1 which means RC2 (PIN17)

PWM2 is CCP2 which is RC1 (PIN16)
Enamul
University of Nottingham
enamul4mm@gmail.com

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 tutorial

Post by medelec35 »

Steve001 wrote:thanks for that martin , got a couple of hectic days ahead of me so i am unable to spend much time on it.
I hope to have a good go at it at the weekend

Steve
No problem Steve,
If you need any help just let us know.

Some time ago, I did create a flowchart that ran an AC motor that relied on zero crossing.
I will see if I still have it.

It may be on a different PC in which I can't gain access to it until Monday.

As soon as I can find it I will post it.

Martin
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: pwm tutorial

Post by medelec35 »

Found attached flowchart that was created sometime ago
It creates a 1ms pulse at the zero crossing points.
If I remember correctly, this design used a 1Meg resistor connected from Mains to An1
Also a 1Meg resistor from PIC GND to Mains GND

Make sure resistor is mains rated.

Anyone using this Idea MUST be confident and experienced with AC mains since People have been killed or seriously injured by mains supplies.
Attachments
12f615 Zero crossing pulse FC4.fcf
(7.5 KiB) Downloaded 454 times
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: pwm tutorial

Post by Steve001 »

Thanks for those martin i have lots to look at now going to look at the info i have and various circuits and think about on what to do next

Steve
Success always occurs in private and failure in full view.

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 tutorial

Post by medelec35 »

You welcome Steve.

The Flowchart I posted was original developed with Flowcode V3, so you can imagine how long ago it was created.
So there may be better way?

Good luck with your project.

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: pwm tutorial

Post by Steve001 »

Evening all,
was thinking of something like this circuit it's not yet finished but you get the jist

Steve
Attachments
Phase control circuit rev 1.pdf
(26.88 KiB) Downloaded 329 times
Success always occurs in private and failure in full view.

Post Reply