Mainul
Newbie
Offline
Posts: 15
Thank You
-Given: 31
-Receive: 5
|
|
« on: March 13, 2009, 04:36:45 16:36 » |
|
I was planning a remote controlled lamp dimmer to be operated at 220VAC, 50Hz. The main components are PIC12F675, 38KHz IrDA receiver, MOC3021 Optocoupler and BT134 TRIAC - using PICBasic pro compiler. I am using two interrupts, GPIO.2 external Interrupt to detect Zero crossing and GPIO.5 pin change interrupt to read IrDA data. I am using a SONY TV remote to generate necessary code.
When GPIO.2 detects AC Mains zero crossing, generates interrupt, and jumps to Interrupt Sub Routine (ISR) where appropriate delay is generated to fire TRIAC at the desired level. Up to this the program is working fine. But when the IrDA generates Interrupt, The interrupt sub-routine reads the train of pulses, âPULSINâ is used to measure pulse duration and accordingly series of 1 and 0âs are constructed to form a âPacketâ. This is also perfectly working. But the problem starts when these two interrupts come into play together. The lamp flickers when I press a button on the remote. I can understand the problem (but donât understand the solution) - when PULSIN is being executed to respond GPIO.5 pin change interrupt request, the Zero crossing interrupt request not being addressed and thus, the TRIAC missing a complete cycle (or may be more).
A huge number of my hairs have become white in last few days for a solution, but no luck! I understand that using assembly to generate Interrupt might solve the problem but my knowledge about âassembly languageâ is only a little more than the spelling of the word.
I am NOT a native English speaker, and am afraid that the above may not explain the problem clearly, but am sincerely expecting that someone knowledgeable will come forward (I know that there are many in this forum) to help me in this and thus the rest of my hairs will remain black for long time.
Mainul
|
|
« Last Edit: March 17, 2009, 07:23:43 19:23 by Mainul »
|
Logged
|
|
|
|
leptro
V.I.P
Junior Member
Offline
Posts: 93
Thank You
-Given: 618
-Receive: 26
|
|
« Reply #1 on: March 13, 2009, 06:45:36 18:45 » |
|
hello, first i'm not a pic user and dont know if this theory solution can be apply to your target.
A solution ( not tested) is to use a timer to measure the time between two zero cross detection and store this value in a variable (cross_interval).
in this timer isr, you can use an other variable containing the delay to fire the triac and reset your timer if is value is above the cross_interval value. in this case if your soft miss a zero cross detection your lamp will not flick.
i hope this will help.
|
|
|
Logged
|
|
|
|
Mainul
Newbie
Offline
Posts: 15
Thank You
-Given: 31
-Receive: 5
|
|
« Reply #2 on: March 14, 2009, 07:37:12 07:37 » |
|
leptro,
Thanks for the reply. Probably this is not the solution. The problem is that the program must trigger TRIAC in every 10ms and the delay has to be synchronized with zero crossing. But when it is processing PULSIN command, it cannot stop immediately and come back to trigger TRIAC at the event of 'Zero Crossing', so that cycle is missed and the lamp flickers. For a train of pulse of say 16 bits, the fliker is really irritating. I'am still struggling for a solution and waiting for a better suggestion.
Mainul
|
|
« Last Edit: March 17, 2009, 07:28:54 19:28 by Mainul »
|
Logged
|
|
|
|
pickit2
Moderator
Hero Member
Offline
Posts: 4667
Thank You
-Given: 834
-Receive: 4322
There is no evidence that I muted SoNsIvRi
|
|
« Reply #3 on: March 15, 2009, 04:50:59 16:50 » |
|
did you search microchip apps http://ww1.microchip.com/downloads/en/AppNotes/91094A.pdfTake care as they don't do a good job on safty.
|
|
|
Logged
|
Note: I stoped Muteing bad members OK I now put thier account in sleep mode
|
|
|
Mainul
Newbie
Offline
Posts: 15
Thank You
-Given: 31
-Receive: 5
|
|
« Reply #4 on: March 17, 2009, 07:14:38 19:14 » |
|
Thanks for the link pickit2, I have downloaded and carefully gone through the document. It is almost similar to what I am planning. It has a major focuse on power saving and also has included several equations for triggering TRIAC gate, very useful for me. But the description in SOFTWARE section is a bit confusing to me. It says âWhen an AC zero voltage crossing is detected on the GP1 inputâ while the schematic shows GP1 is connected to IrDA Output. Again it says âIf the output of the IR receiver module is low, the microcontroller first counts the low state and then moves to generate the delay and pulse.â It is not clear to me how the delay is generated from a single pulse. In fact, though I have learned several other things from the document but so far my problem is concerned, I am still in darkness and struggling to compromise between the two interrupts.
I have a commercial version of a similar product that has no flicker on the lamp output while receiving IR Data. I have checked it with an oscilloscope for confirmation. That means what I am trying, is achievable!
I am including my schematic for those willing to help me in solving the problem.
|
|
« Last Edit: March 18, 2009, 12:01:55 12:01 by Mainul »
|
Logged
|
|
|
|
pickit2
Moderator
Hero Member
Offline
Posts: 4667
Thank You
-Given: 834
-Receive: 4322
There is no evidence that I muted SoNsIvRi
|
|
« Reply #5 on: March 17, 2009, 08:19:04 20:19 » |
|
Not read the full article in detail, but It looks like TB094 is a rewrite from an earlier work. look at component numbering R2,3, 6,7,8 (no R1,4,5) same for Caps. starting at C2. but if you look at citcuit, you can / should beable to follow it. 1. Note 5v for pic chip. to get this voltage 110V mains is dropped by R2.3 & D1 (5V is at high side of mains.. see my warning on Safety Issue - Microchip are well known for trying to kill people) 2. D1 & D2 plus C2 smooth supply to pic chip. 3. Zero Crossing is detected via R6 on GP3. (not as in text GP1) 4. Gp0 is power out for IrDA 5. Gp1 is IrDA output have you downloaded the Code for TB094 ?
|
|
« Last Edit: March 17, 2009, 08:26:43 20:26 by pickit2 »
|
Logged
|
Note: I stoped Muteing bad members OK I now put thier account in sleep mode
|
|
|
j0k3r
Junior Member
Offline
Posts: 40
Thank You
-Given: 44
-Receive: 18
|
|
« Reply #6 on: March 18, 2009, 12:02:59 00:02 » |
|
Try to use:
1º-> use one timer to trigger the triac. 2º-> use the INT Ext to clear the output, and them, here you have two options: a) charge the timer with the appropiate delay to trigger the triac. b) Clear a variable, on that timer will increment on every interrupt of timer. 3º-> use an variable to indicate a IR command, and them process the command on main.
So for example situation 2a): When a int ext is match, the interrupt enable a timer and charge the timer with the delay, and get out. When the timer "explode" turn on the triac and get out. The instructions to do this is minimal and the pic does not stay´s on a interrupt waiting to do something more.
Example situation 2b): Add 2 variables: counts , power. Make power to a value of dimmer. Adjust the timer to count counts. Them on timer interrupt make this counts++; if(counts==power)Turn_ON_Triac.
On every zero-cross, the counts is clear and Turn_OFF_Triac. .
So on this situations the interrupts generated is the most simple code. I think you have time to process the IR code based on a flag (generated by interrupt) on the main code, even when a interrupt is generated for the dimmer, the cycles to process this(dimmer) don´t have long routines.
Of course you have to calc the correct value of the timer´s and prescallers.
For me the 2b) situation is my choice on some projects, for example one recent, A power dimmer 3 phases, a 4 seven digits display , a countdown timer, and 4 keys.
Cumps J0K3R
|
|
|
Logged
|
|
|
|
Mainul
Newbie
Offline
Posts: 15
Thank You
-Given: 31
-Receive: 5
|
|
« Reply #7 on: March 18, 2009, 12:14:46 12:14 » |
|
Sorry, the schematic that I posted earlier was not the updated one, I am deleting it. Here is the update. Thanks.
Posted on: March 18, 2009, 11:58:18 11:58 - Automerged
Pickit2, I didn't find the link to download code for TB094.
J0K3R, I am trying to follow your suggestion, shall come back with more questions soon. Thanks.
|
|
|
Logged
|
|
|
|
pickit2
Moderator
Hero Member
Offline
Posts: 4667
Thank You
-Given: 834
-Receive: 4322
There is no evidence that I muted SoNsIvRi
|
|
« Reply #8 on: March 18, 2009, 02:06:31 14:06 » |
|
|
|
« Last Edit: March 18, 2009, 02:21:41 14:21 by pickit2 »
|
Logged
|
Note: I stoped Muteing bad members OK I now put thier account in sleep mode
|
|
|
Mainul
Newbie
Offline
Posts: 15
Thank You
-Given: 31
-Receive: 5
|
|
« Reply #9 on: March 18, 2009, 02:20:33 14:20 » |
|
Thanks, I have downloaded the code. It's in Assembly and the description, I guess is in 'C'. Unfortunately, I cannot do much with these. I appreciate your awareness about working with mains power. I am double conscious, as I have to work on 220V mains supply. I always use a 'Mains Isolation Transformer' for such experiments.
The suggestion of J0K3R seems to be very interesting, I am experimenting with it. Shall inform the progress, if any. In the mean time, any better suggestion will be highly appreciated.
|
|
« Last Edit: March 18, 2009, 02:34:17 14:34 by Mainul »
|
Logged
|
|
|
|
bbarney
Moderator
Hero Member
Offline
Posts: 2429
Thank You
-Given: 405
-Receive: 545
Uhm? where did pickit put my mute button
|
|
« Reply #10 on: March 18, 2009, 02:44:37 14:44 » |
|
heres a dimmer circuit that might be of help and a link that might be helpful http://www.picbasic.nl/indexes_uk.htm click on projects
|
|
« Last Edit: March 18, 2009, 02:57:56 14:57 by bbarney »
|
Logged
|
Ever wonder why Kamikaze pilot's wore helmet's ?
|
|
|
alien
Junior Member
Offline
Posts: 56
Thank You
-Given: 30
-Receive: 7
|
|
« Reply #11 on: March 19, 2009, 04:49:30 16:49 » |
|
|
|
|
Logged
|
|
|
|
maiasj
Junior Member
Offline
Posts: 48
Thank You
-Given: 226
-Receive: 13
|
|
« Reply #12 on: March 20, 2009, 12:11:20 12:11 » |
|
Hi. I was building a IR LED dimmer and have almost the same problem when using F675 (INT0 and TIMER0 ints) so I change to F628 and use hardware PWM (only INT0 int) to control the LED brightness. This way when INT0 occurs I only have to increment or decrement the PWM duty cycle. Regards, Maia
|
|
|
Logged
|
|
|
|
Mainul
Newbie
Offline
Posts: 15
Thank You
-Given: 31
-Receive: 5
|
|
« Reply #13 on: March 20, 2009, 07:38:49 19:38 » |
|
bbarney and alien, thanksfor the links.
Actually my plan is to build a remote controlled dimmer/fan regulator and replace the existing switch and manual regulator with it. The circuit has to be as small as possible, using through hole standard components. And I have to fit the whole thing into a very small casing. So it seems that there is no alternative to use 8 pin microcontroller (12F675 in this case). I already have one (commercial version), it is excellent in performance. They have wiped out the chip number but the pin configuration says it is either F629 or F675. For the last couple of days I was studying the circuit. Few of my observations are - - it is not using the External Interrupt, GPIO.2 is being used as a switch (push button) input - it detects zero crossing once per cycle, only at the rising edge (20ms interval) - it generates continuous clock pulse to trigger the TRIAC at 10ms interval I am still working on it, and willing to continue until a good solution is found.
|
|
« Last Edit: March 20, 2009, 07:47:03 19:47 by Mainul »
|
Logged
|
|
|
|
Mainul
Newbie
Offline
Posts: 15
Thank You
-Given: 31
-Receive: 5
|
|
« Reply #14 on: March 30, 2009, 07:00:28 19:00 » |
|
SUCCESS!
After almost 2 weeks nonstop work has brought me the success. Now I can set the lamp at any desired level and turn on/off a relay without any flickering.
The problem was in interrupt handling with PICBasic Pro. The latency of PBP Interrupt Handler does not allow the program to serve an interrupt request immediately. For example, if it was processing a âPAUSEUS 10â command while interrupt occurred, it may wait about 240us (at 4MHz) before jumping into ISR. I had to use âPULSEINâ command several times to read remote, the zero crossing Interrupt and TMR0 interrupts was not being synchronized due to this latency. I just included Assembly Language Interrupt routine to solve the problem. There is good example in the PBP compiler manual, which helped me a lot. I am also thankful to those great guys came forward with useful suggestions and good links.
|
|
|
Logged
|
|
|
|
raham
Junior Member
Offline
Posts: 70
Thank You
-Given: 13
-Receive: 18
|
|
« Reply #15 on: May 07, 2009, 10:32:06 10:32 » |
|
can u provide the details and source code as i was trying with ccs c compiler still having problem on decoding the ir ,i have to press atlest 5 -8 times to decode the IR code.The Zerocrossing and lamp dimming works nice.
|
|
|
Logged
|
|
|
|
Mainul
Newbie
Offline
Posts: 15
Thank You
-Given: 31
-Receive: 5
|
|
« Reply #16 on: May 07, 2009, 11:48:27 11:48 » |
|
Unfortunately, I cannot publish the complete code here. But I can quote part of it and willing to help anyone interested in this through discussion.
Following is IR Data receiving section in PICBasic. Once the complete packet is received, you can write appropriate code to perform various functions.
------------------------------------------------------------------------------------------------------------------------- Bitcnt var byte P_Val var byte Packet var word For Bitcnt=0 to 2 ' Detect 3 bit Header Pulse Pulsin GPIO.5,1,P_Val If P_Val < 140 then Return ' Verify a good header, If not then return If P_Val > 170 then Return Next
For Bitcnt=0 to 15 ' Receive the 16 data bits and convert them into a packet Pulsin GPIO.5,1,P_Val ' Receive the IR pulse
If P_Val >= 140 then ' If it's >= 140ms then we've received a 1 Packet.0[Bitcnt]=1 ' So set the appropriate bit Else Packet.0[Bitcnt]=0 ' Clear the appropriate bit Endif Next ' Close the loop ----------------------------------------------------------------------------------------------------------------------------
But the size of packet and length of data largely varies between manufacturers. I am not using SONY remote any more, because SONY protocol is widely used and can easily conflict with my device. The above code is written to decode a Chinese remote (I don't know the protocol name).
And also be extremely careful in the 'Zero Crossing' detection and handling the routine. Use of 'PAUSE' in any form will affect the 'PULSEIN' command.
Don't hesitate to come back with more questions (if any), and also let us know about your success.
|
|
« Last Edit: May 07, 2009, 12:20:38 12:20 by Mainul »
|
Logged
|
|
|
|
|