Computer Engineers

 
Home | Computer engineering other top | Fiber / Wireless / Copper Tran | Semiconductor engineering
  Position:HOME>Programming language engineeri>Article Content
PIC code for triac light dimmer
Source:Internet Author:Unknow Pubdate:2008-04-14  
fuseshut (Electrical) 19 Oct 05 21:30
I am learning how to program a PIC. DOes anyone know where I can find sample code to learn from for a light dimmer project?

MikeHalloran (Mechanical) 19 Oct 05 23:33
Start with something that doesn't involve line voltage, e.g. dimming an LED or an incandescent bulb run from a DC supply.  

Post mortems are easier that way.

Mike Halloran
Pembroke Pines, FL, USA

zeitghost (Computer) 20 Oct 05 3:59
Yes.

But the shortcuts are on another computer...

And what Mike says above is very true...

zeitghost (Computer) 20 Oct 05 4:15
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011202
字串6



VisiGoth (Electrical) 31 Oct 05 23:10
The vendors supply code examples.  Look under PWM or frequency modulation.

Ditto for the warnings of zeitghost and MikeHalloran.

You were asking for SW so I assume you know what your HW control and feedback mechanisms are?

You need to build a one shot timer.  A PIC would be an interesting way of doing that.

zeithost has supplied an excellent detailed answer for you.  Please, let us know if you need more info.

embedded1 (Computer) 3 Mar 06 19:52
Hi.

Please accept the following personal-opinions or tips as a guide to help you understand and seek further researched and reliable references to this popular subject.

When dealing with mains, you should get assistance and perhaps get your circuit checked before powering it up and if available, use an AC supply running from isolated mains sources to reduce the risk of shock.

字串5


Always make sure someone knows you are experiementing with mains (in your room??)

The PIC micro can indeed be used to control a light dimming circuit.

You will need to have a good understanding of how your particular electronic circuit or system works. Then you can decide how you are going to drive it based on some intelligence input to your PIC.

The PIC provides all the 'hardware' (timers, i/o control pins under the control of your software). For Assembler programmers, each family of PIC PIC12xxx PIC14xxx .....PIC18xxx has what is called an Instruction Set for the appropriate RISC architecture. This is like a list of commands to control the hardware and manipulate data or signals to and from the PIC.


What your system needs to do is to be able to determine roughly where in the mains cycle the ac waveform is. Some electronic interface (resistive potential divider network **) interfacing the mains to your PIC. You can imagine this as a sinewave with 0 volts at t=0. Then we can determine the magnitude at any time using formula (1) below;

字串6



v = Vmax.Sin(w.t)    -  (1)  note: w = omega

also, w = 2.pi.f     -  (2)  note: pi = 3.14

        _                           f = 50Hz
       /  \
      /    \
     |      |      |
     t0     t1    /
              \  /
                -

Recall (from calculus) that 'the area under curve' of a sinusoid is INTEGRAL of Sin(x) with limits at t0 and t1.

字串2



So INTEGRAL = [INTEGRATE Sin(t1) - INTEGRATE Sin(t0)]

So if the switching on of the triac can be delayed by a finite time (by up to or >9mS)from the point of zero crossing (when t0=0), we can control the amount of power delivered to the lamp and so, fewer photons come out of the lamps' filament as t0 tends to t1, away from t=0


The micro needs to be configured with;

1) Zero Cross detection / input pin (preferably to an interrupt pin (RB0). **

2) Triac Switch output(or what ever is actually switching the power to the light) **

3) i/o switches as input from Man Machine Interface, to increase and decrease brightness of the lamp.

You would usually use one of the PIC timers to start as soon as a zero cross is detected and when the timer overflows, you fire the triac - which automatically cuts out when the mains waveform reaches a minimum voltage (component dependent - several volts?).

The values you load into your timers depend on what oscillator frequecy you are running your PIC. 字串2

You could then get the PIC to poll a keypad (MMI) to change the brightness of the lamp.

Conclusion:
Once you understand the problem, draw a flow chart of your software.

Then write a Pseudo-Code of you program;

Intialize peripherals (timers, ports)
Wait until zero cross occurs.
When it does, start timer.
Wait until timer overflows.
when it does, turn on triac
wait several micro-seconds until Triac latches
Poll the MMI pins.
If pressed, change timer overflow value accordingly up to maximum value -

You can see that the 'software' is picking up shape already (in the form of the above Pseudo-code)and the rest is down to becoming familiar with the Instruction set of the PIC you're using and translating the pseudo-code into a PIC program.

Obviously, many poeople are using C-compilers these days and so Assembly may not be the way to go.

Try the PICs home for Student edition compilers and lots of examples and free development tools:- 字串2

                http://www.microchip.com


Hope this helps.
Good luck!

____________________
**(Remember, this involves connecting pic i/o pin through appropriate electonics - seek advice)





(Click:

Previous:IBM VisualAge C++ 3.0   Next:Newbie here
[Add TO Favorites] [TOP] [PRINT] [CLOCE WINDOWS]  
  Hot Article
·Connecting a Footswitch to an
·Siemens s7-200 PLC & Visua
·TETRIS source code is availabl
·XML Files and Terramodel
·controlling GPIB from VBA
·LINKING MSC PATRAN WITH INTRAN
·How to interface RS-485 / Modb
·VBA WITH AB PLC
·SIEMENS: I/O, NCDDE AND DCTL
·getch() function
·Visual Basic Serial Comms To S
·Symax PLC
  Related Articles
·Newbie here
·How to trigger a function in V
·IBM Visual Age C++ v3.5
·Java + multiport serial card
·Compiler and Matlab
·MDI in .NET
·Parallel Port, XP, and Perl
·Will memory stick work on USB
·thermal motion detector
·how to do triple numerical int
·Software to Program With Graph
·how to open an obj file?
Power by DedeCms