Triac Control

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
donnywong79
Posts: 22
Joined: 06 Mar 2008 12:55
Location: Malaysia

Triac Control

#1 Post by donnywong79 » 28 Aug 2010 13:57

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
Happy to use mikroelektronika

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: Triac Control

#2 Post by p.erasmus » 28 Aug 2010 14:15

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
Attachments
Code.png
Code.png (10.08 KiB) Viewed 5931 times
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

donnywong79
Posts: 22
Joined: 06 Mar 2008 12:55
Location: Malaysia

Re: Triac Control

#3 Post by donnywong79 » 28 Aug 2010 15:56

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
Happy to use mikroelektronika

donnywong79
Posts: 22
Joined: 06 Mar 2008 12:55
Location: Malaysia

Re: Triac Control

#4 Post by donnywong79 » 28 Aug 2010 15:57

i am using PIC16F88
Happy to use mikroelektronika

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Triac Control

#5 Post by Dany » 28 Aug 2010 19:25

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

roys29
Posts: 106
Joined: 13 Oct 2009 15:09

Re: Triac Control

#6 Post by roys29 » 12 Sep 2010 14:20

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

donnywong79
Posts: 22
Joined: 06 Mar 2008 12:55
Location: Malaysia

Re: Triac Control

#7 Post by donnywong79 » 13 Sep 2010 04:38

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.
Happy to use mikroelektronika

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Triac Control

#8 Post by Dany » 13 Sep 2010 07:57

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

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Triac Control

#9 Post by Dany » 13 Sep 2010 08:06

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)

Post Reply

Return to “mikroBasic PRO for PIC General”