Author Topic: My first PIC program  (Read 19794 times)

0 Members and 1 Guest are viewing this topic.

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 20515
  • Country: gb
  • 0999
Re: My first PIC program
« Reply #25 on: February 03, 2011, 06:44:50 pm »
On a positive halfwave you'll be trying to impose a positive gate current using 2.5V on the gate but having a high voltage on the lower anode (the motor is running and has its B-EMF). Since the MCU is fed by a supply referenced to neutral, this won't work, IMHO.
Yes, I forgot, the motor will act as a generator once running.

Quote
I'm not really experienced, but I think a little RC snubber would be a good thing there, since you don't know how current-voltage phase shift will be under all conditions.
This could be useful, I'll take a look, since I'd like to learn it too: http://www.st.com/stonline/books/pdf/docs/6785.pdf
Looks like a good idea but the trouble is, I've got no idea what the inductance of the motor is.

I'm now thinking about how to perform the zero crossing which I've never done with an MCU. The mains is connected to an input via a 1M resistor so I'll get a 50Hz pulse train. It seems pretty simple, all it needs to do is wait for pin 7 to change state (from high to low or low to high), apply a >20µs pulse to the TRIAC and repeat until the TRIAC needs to be turned off.

I realised one potential problem: on the falling edge the MCU will register a zero whilst the mains voltage is still slightly above zero so the trigger pulse will occur earlier than I would like. Here's my calculations which determine that it's not a problem, as long as the pulse is longer than 23.9µs but could someone please check them.
I'll be using 220V for the mains as it's the bottom end of the tolerance in my area.

v = instantaneous voltage
VPK = peak mains voltage
t = time, in this case I'll be calculating the time for zero crossing to occur after the PIC has registered a zero.
F = frequency
VOFF = the mains voltage when the MCU will register a low, which is 0.15VDD = 0.15 * 2.5 = 0.375V
Theta = angle in o

VPK = 220V sqrt(2) = 311V
v = VPK sin Theta

Rearrange to make Theta the subject:
Theta = arcsin v/VPK = arcsin (0.375/311) = 0.07o

Theta = F360t

Rearrange to make t the subject:
t = Theta/(360F) = 0.07/(360*50) = 3.9µs

So it the gate of the TRIAC is held high for >23.9µs it won't matter and the capacitor is more than large enough not to make any difference. I'll make the gate pulses 25µs just to ensure the TRIAC always triggers consistently.

I can't see an easy way to monitor the counter whilst doing zero crossing so I think I'll change the timer routines to use the mains frequency as it'll be more compatible with my zero crossing set up.
« Last Edit: February 03, 2011, 07:33:51 pm by Hero999 »
 

Offline scrat

  • Frequent Contributor
  • **
  • Posts: 608
  • Country: it
Re: My first PIC program
« Reply #26 on: February 03, 2011, 09:58:18 pm »
My first thought was that there is a main(s :)) mistake in your calculation: the sensed voltage isn't really all the mains, since the MCU pin sees a voltage divider between 1M and Zin (otherwise there would be 300V on that pin!).

While reading, I caught what I think is the real behaviour of the sense net: the MCU pin voltage can follows the mains voltage as soon as it goes over Vdd, then the protection diode start to clamp voltage, with a current which is at max (about) 300uA.

So the truth stays in the middle, IMO: the voltage is the mains scaled by the ohmic divider (Zin, 1M), until Vdd is reached.
The datasheet doesn't report an accurate value for Zin, but the leakage current is max 1uA, so impedance should be >5.5M, and then the ohmic divider is almost negligible for your purpose, or you could redo your calculation with a 5/6 scaling factor.

One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. - Elbert Hubbard
 

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 20515
  • Country: gb
  • 0999
Re: My first PIC program
« Reply #27 on: February 04, 2011, 08:19:56 pm »
311*5.5/6.5 = 263V

Theta = arcsin (0.375/263) = 0.082o
t = 0.082/(360*50) = 4.56µs

So it appears 25µs is more than enough leeway and in any case, I think 1µA is a worst case scenario, a PIC has CMOS inputs which can be taken to be open circuit for all intents and purposes.

 

Offline scrat

  • Frequent Contributor
  • **
  • Posts: 608
  • Country: it
Re: My first PIC program
« Reply #28 on: February 05, 2011, 09:07:18 am »
With the available data, I think this is the best you can do to estimate that delay.
However, should it be even 10 times higher, it would represent about 1.25% of one period.
Is the controller intended to chop the mains for variable speed or simply an on/off control?
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. - Elbert Hubbard
 

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 20515
  • Country: gb
  • 0999
Re: My first PIC program
« Reply #29 on: February 05, 2011, 10:41:15 am »
It's simply and on/off control.
 

Offline scrat

  • Frequent Contributor
  • **
  • Posts: 608
  • Country: it
Re: My first PIC program
« Reply #30 on: February 05, 2011, 10:44:33 am »
One reason more for trying a snubber and not worry about a 25us delay.
However, delay is a thing you can measure without even programming the PIC nor switching the triac, so you can go quite safe then.
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. - Elbert Hubbard
 

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 20515
  • Country: gb
  • 0999
Re: My first PIC program
« Reply #31 on: February 06, 2011, 12:20:21 pm »
I won't be delaying the pulse, just making it 5µs longer than it needs to be.

How will a snubber make any difference to the triggering? I thought it only improved the turn off.

I was thinking about doing in circuit programming but then I realised it would be a pain. I'd have to put a diode in series with D3 and between D3 and C3 so the programmer's VDD isn't clamped to 2.5V and changing some of the IO pin positions. I decided it's not worth the bother, after all, once the PIC is programmed and debugged on a breadboard, it will never be changed.
 

Offline scrat

  • Frequent Contributor
  • **
  • Posts: 608
  • Country: it
Re: My first PIC program
« Reply #32 on: February 06, 2011, 10:18:37 pm »
I was thinking about measurign the actual delay between mains zero crossing and 0.375V crossing on the MCU pin.

My sentence about the snubber was quite confused, I'm not sure if what I was trying to say is right. However, you're right, it has nothing to do with triggering.

With almost any programmer you should be able to self-power the device circuit, at least by disconnecting the Vdd pin.
In-circuit programming is perhaps overkill for the purpose, but maybe in the future you could use the same circuit for something more complicated...
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. - Elbert Hubbard
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf