Page 1 of 1

Triac Control

Posted: 28 Aug 2010 13:57
by donnywong79
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

Re: Triac Control

Posted: 28 Aug 2010 14:15
by p.erasmus
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

Re: Triac Control

Posted: 28 Aug 2010 15:56
by donnywong79

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.
Dear P.erasmus,

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

Re: Triac Control

Posted: 28 Aug 2010 15:57
by donnywong79
i am using PIC16F88

Re: Triac Control

Posted: 28 Aug 2010 19:25
by Dany
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?
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 (**).

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...

Re: Triac Control

Posted: 12 Sep 2010 14:20
by roys29
Look up AN236 and PICREF-4 on the Microchip web site. These two documents include schematics and component lists and can probably be modified for what you need to do.

AN236
PICREF-4

Re: Triac Control

Posted: 13 Sep 2010 04:38
by donnywong79
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.

Re: Triac Control

Posted: 13 Sep 2010 07:57
by Dany
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?
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.
If you are not able to convert the project to mP PRO I will do it for you, please keep me informed.

Re: Triac Control

Posted: 13 Sep 2010 08:06
by Dany
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