Page 1 of 1

pwm tutorial

Posted: Thu Oct 04, 2012 9:28 pm
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

Re: pwm tutorial

Posted: Thu Oct 04, 2012 9:38 pm
by JohnCrow

Re: pwm tutorial

Posted: Fri Oct 05, 2012 12:51 am
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.

Re: pwm tutorial

Posted: Fri Oct 05, 2012 9:40 pm
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

Re: pwm tutorial

Posted: Sun Oct 07, 2012 11:24 am
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

Re: pwm tutorial

Posted: Sun Oct 07, 2012 5:11 pm
by Steve001
i have some scribbles of drawings and idea's will scan them tomorrow at work and post

Steve

Re: pwm tutorial

Posted: Mon Oct 08, 2012 9:16 pm
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

Re: pwm tutorial

Posted: Mon Oct 08, 2012 9:25 pm
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

Re: pwm tutorial

Posted: Tue Oct 09, 2012 7:16 am
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

Re: pwm tutorial

Posted: Tue Oct 09, 2012 9:45 am
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.

Re: pwm tutorial

Posted: Tue Oct 09, 2012 9:18 pm
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

Re: pwm tutorial

Posted: Sun Oct 14, 2012 9:26 am
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

Re: pwm tutorial

Posted: Sun Oct 14, 2012 10:21 am
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)

Re: pwm tutorial

Posted: Sun Oct 14, 2012 10:42 am
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

Re: pwm tutorial

Posted: Sun Oct 14, 2012 2:54 pm
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.

Re: pwm tutorial

Posted: Sun Oct 14, 2012 4:10 pm
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

Re: pwm tutorial

Posted: Mon Oct 15, 2012 7:03 am
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

Re: pwm tutorial

Posted: Mon May 27, 2013 9:58 pm
by Steve001
Evening all,
was thinking of something like this circuit it's not yet finished but you get the jist

Steve