Hi,
i am trying to use PWM to control 230VAC by using triac, is there any one of you
have an example for me to refer?
regards
donny
Triac Control
-
- Posts: 22
- Joined: 06 Mar 2008 12:55
- Location: Malaysia
Triac Control
Happy to use mikroelektronika
Re: Triac Control
donny
it is more helpfull if you post your code and show us what difficulties you have
we can then try to help clear your problems
Please also use the code tags when posting code
it is more helpfull if you post your code and show us what difficulties you have
we can then try to help clear your problems
Please also use the code tags when posting code
- Attachments
-
- Code.png (10.08 KiB) Viewed 6040 times
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------
-
- Posts: 22
- Joined: 06 Mar 2008 12:55
- Location: Malaysia
Re: Triac Control
Code: Select all
program test_as_control
' this program is to give PWM signal to triac controler where
' input source is 50Hz, PWM will turn on when signal is high, and turn of
' when signal is low.
' Declarations section
Dim current_duty as byte
sub procedure incdec()
if Button(porta,0,250,1) then
'portb.2 = 1
'Delay_ms(40)
Inc(current_duty)
PWM1_SET_DUTY(current_duty)
end if
if Button(porta,1,250,1) then
'portb.2 = 0
'Delay_ms(40)
DEC(current_duty)
PWM1_SET_DUTY(current_duty)
end if
end sub
main:
' Main program
ANSEL = 0
OPTION_REG = %11100000
current_duty = 100
trisa = %1111111
trisb = %0000000
portb = 0
pwm1_init(500)
portb.1 = 1 'high portb.1 as indicator only
PWM1_set_duty(current_duty)
while true
' porta.4 is an input from a 50Hz source
if porta.4 = 1 then
PWM1_set_duty(current_duty)
PWM1_start()
else
PWM1_stop
end if
incdec()
wend
end.
i have managed to give PWM signal, but it seem pwm is shifting or unstable, and when i press RA0 or RA1 to increse or decrese duty cycle, the output RB3 sometime will blink,
any advice?
regards
donny
Happy to use mikroelektronika
-
- Posts: 22
- Joined: 06 Mar 2008 12:55
- Location: Malaysia
Re: Triac Control
Hi, one can not use the Pic's PWM output to control a 230V ac triac (*). In stead one needs a phase control synchronised with the 230Vac zero crossings (**).donnywong79 wrote:i am trying to use PWM to control 230VAC by using triac, is there any one of you
have an example for me to refer?
The output power is then controlled by changing the time between the zero crossing and the ignition moment of the triac.
So, your PIC program has to do 3 things:
- detect the zero crossing of the 230Vac
- wait a while (0..10 msecs) (the smaller the time, the bigger the output power)
- ignite the triac.
- repeat above
An example can be found inhttp://www.mikroe.com/forum/viewtopic.php?f=147&t=23742 or http://users.edpnet.be/rosseel01/DRO/PI ... Dimmer.zip Ignore the "touch" part of it. Timer0 has to be set to a certain value to obtain the wanted power (see code).
I think also MicroChip has an example of how to do this.
(*) unless the PWM can be set to make 100Hz synchronised with the 230Vac zero crossings...
(**) which is in fact an 100Hz PWM synchronised with the 230Vac zero crossings...
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
-
- Posts: 22
- Joined: 06 Mar 2008 12:55
- Location: Malaysia
Re: Triac Control
Dear roys29,
thanks for your info, i will experiment with it, currently i able to use PWM to chop sine wave, but not able to synchro with it,
Danny, thanks for your advice, i have down load your sample code, but not able to open it,
i have try using pascal, but still unable to open it. any advice?
Regards
donny.
thanks for your info, i will experiment with it, currently i able to use PWM to chop sine wave, but not able to synchro with it,
Danny, thanks for your advice, i have down load your sample code, but not able to open it,
i have try using pascal, but still unable to open it. any advice?
Regards
donny.
Happy to use mikroelektronika
Re: Triac Control
This is (most probably) due to the fact that the sources are for the non PRO version of mP. I suggest you open them with a standard editor (like notepad) and copy/paste them into the mP PRO IDE in which you will have to create the project.donnywong79 wrote:Danny, thanks for your advice, i have down load your sample code, but not able to open it,
i have try using pascal, but still unable to open it. any advice?
If you are not able to convert the project to mP PRO I will do it for you, please keep me informed.
Last edited by Dany on 13 Sep 2010 08:07, edited 1 time in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Re: Triac Control
Here another example of triac control. Be aware for electric shock: no mains isolation in this circuit diagram: http://www.microchip.com/stellent/idcpl ... e=en021266
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)