I want build the triac firing angle control for lamp dimmer using PIC (12F1840) and zero crossing detecting circuit.
Basically I use timer0overflow. The program code is simple and the program is working, but there are nuances. Using analogue input for firing angle reference potentiometer , firing angle remains unstable - in each cycle varies by a few degrees. It can be seen that the lamp does not lit steadily, but little asymmetrical flashes.
. #chip 12f1840,4
.#config osc=int
. #define poti an1
.#define alpha gpio.5 '' triac firing angle
.#define sync gpio.4 '' zero crossing detect
dir alpha out
dir sync in
dir poti in
dir gpio.2 out
main:
alpha_ref=readad(poti)
if sync then
set alpha off
cleartimer 0
timer0=alpha_ref
end if
wait 10 us '' ????????
goto main
sub impuls
set alpha on
end sub
''==============================
I assume that the analog inputs the read error occurs and each cycle is changing. I then I tried not to use an analog input, but give a constant angle, the results are much better, but still the lamp is not lit steadily,but also little asymmetrical flashes.
alpha_ref=150 ''' const
HPWM is for pulse transformer. I've tried two variants - triac control with pulse transformers and using the optocouple, the results are similar. I understand that the need to use another interrupt.
I should be grateful for every idea!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You could try to use the Zero Cross Detect feature on some of the newer PIC devices.
Here is a brief description for firing a triac. http://microchip.wikidot.com/tip:13
You would have to switch to a new device such as the 12F1612 that has the ZCD peripheral. I'm not sure if that device is supported in GCB yet. You'll have to check.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't really understand your circuit, but I have made a device to dim then brighten (for chritmas lights).
It detects the zero cross using an unsmoothed full wave rectifier off a transformer (with a zener to avoid going over 5V).
Here is the program
David, do not think GPIO 3 can be an output. Do you have a schematic on the circuit. I would like to see it. Also I changed the code and removed the NR's
Maybe the OP will want to try your way, sounds simpler and cheaper.
Here is the schematic. In my actaul system I have 4 of these circuits running 50 lights each all on different timing cycles. {edited to correct schematic}
Just for amusement I compiled your modified program as I suspected it would give exactly the same as mine in ASM. The surprise is it didn't. Indeed as far as I can see we seem to have a loop that seems to be impossible to break out of. Maybe somebody with more experience with ASM can figure out what is going on here. I have marked the suspect loop with !!!!!!!!!!!!!!!!!!!!!!!!.
@David. You are using a compiler from (0.94 2015-04-02). Janis is using the latest Release Candidate. The results may be different and will be different. I can let you have the lastest copy if you want to be on the same release.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Many thanks to all! I did not know about the ZCD peripheries. Actually, I need a microcontroller with more ports that can operate with 7-segment display. Are there any examples for ZCD configuration?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you all for your suggestions !!!
In attachment is wiring diagramm in order to understand the program code. David Stephenson example does not suit me. Apologies Anobium, the new hot reliese includes files for controllers with ZCD . I think in my case are necessary PIC16F1709. I do not know how to configure the configuration registers ..
I think that the proper organization of the program code, the scheme need to work correctly.
May not need to use Timer 0? Now, seeing the scheme, maybe someone can corrections to my code? Soon I'll buy pic16f1709 and will then have to create another program code. But now I need made correct programmcode for this scheme. Help...
I exchange places ports in order to use RA2 for
Interrupt on rising edge.
Also, this idea is not working. :(((((
/ #chip 12f1840, 16
/ #config osc=int
CCP1SEL=1 ''PWM uz gpio.5 APFCON: ALTERNATE PIN FUNCTION CONTROL REGISTER page 112
/ #define poti an1
/#define alpha gpio.4
/#define sync gpio.2
/#define button gpio.0
dir gpio.5 out
dir button in
dir alpha out
dir sync in
dir poti in
dim pushtime as word
InitTimer0 Osc, PS0_128 ''PS0_32''
On Interrupt Timer0Overflow Call impuls
now=0
prev=0
pushtime=0
aa=0
INTF=0 '' bit 1 INTF: INT External Interrupt Flag bit
''''''''1 = The INT external interrupt occurred
''''''''0 = The INT external interrupt did not occur
INTE=1 '' bit 4 INTE: INT External Interrupt Enable bit
''''1 = Enables the INT external interrupt
''''0 = Disables the INT external interrupt
GIE=1 ''bit 7 GIE: Global Interrupt Enable bit
''''''''1 = Enables all active interrupts
''''''''''''0 = Disables all interrupts
hpwm 1,5, 127 ''HPWM channel, frequency, duty cycle
INTEDG=1 ' Interrupt on rising edge of RA2/INT/...... pin
on Interrupt ExtInt0 call ISR
main:
if !button then
pushtime++
else
pushtime=0
end if
if pushtime =>20000 then aa=0
now= !button & pushtime<20000
if now>prev then
aa++
end if
select case aa
case 0
alpha_ref=255
case 1
alpha_ref=220
case 2
alpha_ref=200
case 3
alpha_ref=180
case 4
alpha_ref=160
case 5
alpha_ref=140
case 6
alpha_ref=120
case 7
alpha_ref=100
case 8
alpha_ref=90
case 9
alpha_ref=80
case 10
alpha_ref=70
case 11
aa=0
end select
prev=now
''wait 10 us
goto main
''==========================
sub impuls
set alpha on
end sub
''==========================
sub ISR
if INTF then
set alpha off
cleartimer 0
timer0=alpha_ref ''uzstada timer0 laiku
INTF=0
end if
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank Anobium. I am using V3.0. What has been improved?
Prescalers in quotes is because I tried to use different combinations of clock frequency and prescaler. :)))
ps0_32 works in combination with the frequency of 4MHz and so on.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK. Let us get you on the latest build. Why? We have changed the Timers addresses to improve usage.
Please send me a Personal Message via SourceForge with your email address. Do not post here.
When you get the latest build DO NOT overwrite your existing setup. Take a backup etc. Then, use the installer to install the latests build. You WILL have to reconfig your programmer but that is relatively simple.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anobium,
I do not know what to do now. The program code now is compiled with syncwr and code not complex and running. When measuring with an oscilloscope, everything looks beautiful, as only a very small ripple. Probably I need to find some other solution.....
If the thyristor is opened fully (alpha ref = 255), then the lamp is burning steadily without ripple. But reducing the opening angle and the lamp remained dark as is visible in a small ripple. In fact, I will be provided for inductive load. Therefore optodiacs is not used, but the pulse transformer.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I want build the triac firing angle control for lamp dimmer using PIC (12F1840) and zero crossing detecting circuit.
Basically I use timer0overflow. The program code is simple and the program is working, but there are nuances. Using analogue input for firing angle reference potentiometer , firing angle remains unstable - in each cycle varies by a few degrees. It can be seen that the lamp does not lit steadily, but little asymmetrical flashes.
. #chip 12f1840,4
.#config osc=int
. #define poti an1
.#define alpha gpio.5 '' triac firing angle
.#define sync gpio.4 '' zero crossing detect
dir alpha out
dir sync in
dir poti in
dir gpio.2 out
InitTimer0 Osc, PS0_32''
On Interrupt Timer0Overflow Call impuls
hpwm 1,150, 127 ''pulse transformer
main:
alpha_ref=readad(poti)
if sync then
set alpha off
cleartimer 0
timer0=alpha_ref
end if
wait 10 us '' ????????
goto main
sub impuls
set alpha on
end sub
''==============================
I assume that the analog inputs the read error occurs and each cycle is changing. I then I tried not to use an analog input, but give a constant angle, the results are much better, but still the lamp is not lit steadily,but also little asymmetrical flashes.
alpha_ref=150 ''' const
HPWM is for pulse transformer. I've tried two variants - triac control with pulse transformers and using the optocouple, the results are similar. I understand that the need to use another interrupt.
I should be grateful for every idea!
You could try to use the Zero Cross Detect feature on some of the newer PIC devices.
Here is a brief description for firing a triac.
http://microchip.wikidot.com/tip:13
You would have to switch to a new device such as the 12F1612 that has the ZCD peripheral. I'm not sure if that device is supported in GCB yet. You'll have to check.
12F1612 is supported in v0.95 release (due for release December 2015)
I don't really understand your circuit, but I have made a device to dim then brighten (for chritmas lights).
It detects the zero cross using an unsmoothed full wave rectifier off a transformer (with a zener to avoid going over 5V).
Here is the program
David, do not think GPIO 3 can be an output. Do you have a schematic on the circuit. I would like to see it. Also I changed the code and removed the NR's
Maybe the OP will want to try your way, sounds simpler and cheaper.
Last edit: lhatch 2015-12-16
Here is the schematic. In my actaul system I have 4 of these circuits running 50 lights each all on different timing cycles. {edited to correct schematic}
Last edit: David Stephenson 2015-12-16
Just for amusement I compiled your modified program as I suspected it would give exactly the same as mine in ASM. The surprise is it didn't. Indeed as far as I can see we seem to have a loop that seems to be impossible to break out of. Maybe somebody with more experience with ASM can figure out what is going on here. I have marked the suspect loop with !!!!!!!!!!!!!!!!!!!!!!!!.
Last edit: David Stephenson 2015-12-16
@David. You are using a compiler from (0.94 2015-04-02). Janis is using the latest Release Candidate. The results may be different and will be different. I can let you have the lastest copy if you want to be on the same release.
Many thanks to all! I did not know about the ZCD peripheries. Actually, I need a microcontroller with more ports that can operate with 7-segment display. Are there any examples for ZCD configuration?
In my case can use PIC16F170x family
But it seems to me that GCB does not support pc16f170x series.
GCB does support16f170x devices. From v0.94.
Thank you all for your suggestions !!!
In attachment is wiring diagramm in order to understand the program code. David Stephenson example does not suit me. Apologies Anobium, the new hot reliese includes files for controllers with ZCD . I think in my case are necessary PIC16F1709. I do not know how to configure the configuration registers ..
I think that the proper organization of the program code, the scheme need to work correctly.
May not need to use Timer 0? Now, seeing the scheme, maybe someone can corrections to my code? Soon I'll buy pic16f1709 and will then have to create another program code. But now I need made correct programmcode for this scheme. Help...
I exchange places ports in order to use RA2 for
Interrupt on rising edge.
Also, this idea is not working. :(((((
/ #chip 12f1840, 16
/ #config osc=int
CCP1SEL=1 ''PWM uz gpio.5 APFCON: ALTERNATE PIN FUNCTION CONTROL REGISTER page 112
/ #define poti an1
/#define alpha gpio.4
/#define sync gpio.2
/#define button gpio.0
dir gpio.5 out
dir button in
dir alpha out
dir sync in
dir poti in
dim pushtime as word
InitTimer0 Osc, PS0_128 ''PS0_32''
On Interrupt Timer0Overflow Call impuls
now=0
prev=0
pushtime=0
aa=0
INTF=0 '' bit 1 INTF: INT External Interrupt Flag bit
''''''''1 = The INT external interrupt occurred
''''''''0 = The INT external interrupt did not occur
INTE=1 '' bit 4 INTE: INT External Interrupt Enable bit
''''1 = Enables the INT external interrupt
''''0 = Disables the INT external interrupt
GIE=1 ''bit 7 GIE: Global Interrupt Enable bit
''''''''1 = Enables all active interrupts
''''''''''''0 = Disables all interrupts
hpwm 1,5, 127 ''HPWM channel, frequency, duty cycle
INTEDG=1 ' Interrupt on rising edge of RA2/INT/...... pin
on Interrupt ExtInt0 call ISR
main:
if !button then
pushtime++
else
pushtime=0
end if
if pushtime =>20000 then aa=0
now= !button & pushtime<20000
if now>prev then
aa++
end if
select case aa
case 0
alpha_ref=255
case 1
alpha_ref=220
case 2
alpha_ref=200
case 3
alpha_ref=180
case 4
alpha_ref=160
case 5
alpha_ref=140
case 6
alpha_ref=120
case 7
alpha_ref=100
case 8
alpha_ref=90
case 9
alpha_ref=80
case 10
alpha_ref=70
case 11
aa=0
end select
prev=now
''wait 10 us
goto main
''==========================
sub impuls
set alpha on
end sub
''==========================
sub ISR
if INTF then
set alpha off
cleartimer 0
timer0=alpha_ref ''uzstada timer0 laiku
INTF=0
end if
end sub
Hi, what version of GCB compiler are you using? We have improved timers in v0.95 and it me best to get you on the latest release before responding.
But, try editing "ps0_32" to ps0_32. No quotes.
Hi, what version of GCB compiler are you using? We have improved timers in v0.95 and it me best to get you on the latest release before responding.
But, try editing "ps0_32" to ps0_32. No quotes.
Thank Anobium. I am using V3.0. What has been improved?
Prescalers in quotes is because I tried to use different combinations of clock frequency and prescaler. :)))
ps0_32 works in combination with the frequency of 4MHz and so on.
I would like you to look on the LST for you project. At the top it will show the date etc of te compiler. I would like this information.
Mine is 'GCASM List File (GCBASIC 0.94 2015-12-08)'
Evan
Aha. now I understand, Anobium.
GCB 0.9 11/5/2014
OK. Let us get you on the latest build. Why? We have changed the Timers addresses to improve usage.
Please send me a Personal Message via SourceForge with your email address. Do not post here.
When you get the latest build DO NOT overwrite your existing setup. Take a backup etc. Then, use the installer to install the latests build. You WILL have to reconfig your programmer but that is relatively simple.
Anobium, I did not know that personal letters is the limit here. I can not more sent You a personal letter.
Re personal messages. You can only send one response. :-(
@all helping Janis. He now has Release Candidate 031. Therefore, he has the latest and greatest build.
@janis. Should yoube clearing TMR1IF in method impul?
Anobium,
I do not know what to do now. The program code now is compiled with syncwr and code not complex and running. When measuring with an oscilloscope, everything looks beautiful, as only a very small ripple. Probably I need to find some other solution.....
If the thyristor is opened fully (alpha ref = 255), then the lamp is burning steadily without ripple. But reducing the opening angle and the lamp remained dark as is visible in a small ripple. In fact, I will be provided for inductive load. Therefore optodiacs is not used, but the pulse transformer.
Thank you! I'll try!