PDA

View Full Version : Ideas on ir-code for dimmer



tirithen
- 13th February 2009, 23:22
I'm trying to write code for a dimmer controlled by ir, I'm trying to adapt the ir code from the http://www.rentron.com/PicBasic/IR_Chips.htm example. I have used this ir-code before as ir-proximity sensors on two robots. The basic dimmer code that works fine by it self is:

' Dimmer for 50hz AC for pic12f683 or pic12f675
@ DEVICE INTRC_OSC, MCLR_OFF, PROTECT_OFF, WDT_ON
ANSEL = 0 ' A/D OFF -- Port pins all digital
TRISIO = %001100 ' Set I/O
GPIO = %000000 ' All 0 on boot

AC_wave var gpio.2
TRIAC var gpio.5
fired var bit
fired = 0
dim_value var byte
dim_value = 200

OPTION_REG = %10000101 ';presc 1:64
intcon.2 = 0 ' TMR0 Overflow Interrupt Flag
intcon.5 = 1 ' TMR0 Overflow Interrupt Enable
tmr0 = 100 ' Set timer to ~10ms
pause 100 ' Stabilize on power-up
intcon.7 = 1 ' Turn on intterupts

ON INTERRUPT GOTO interrupt_rutine
goto mainloop

disable
interrupt_rutine:
if intcon.2 = 1 then ' If Timer0 Overflow
intcon.2 = 0 ' Clear TMR0 Overflow Interrupt Flag
fired = 0 ' Set TRIAC fired to 0
while AC_wave = 1 ' If AC_wave is 1 wait until negative to sync
wend
tmr0 = 100 ' Set tmr0 for ~10ms
endif
resume
enable

mainloop:
if fired = 0 then ' If TRIAC is not yet fired
if tmr0 > dim_value then ' If it's time to fire TRIAC
high TRIAC ' Fire TRIAC
pauseus 100
low TRIAC
fired = 1 ' Set TRIAC fired to 1
endif
endif
goto mainloop

But the problem is that when I try to integrate the ir-code into this code the ir-reception takes way to much time, one ir-transmission is ~10-18ms + the time to verify the signal. If the pic would get the transmission right every time a interruption of 20ms would be acceptable but when I try to set GPIE to detect an incoming signal it seems like picbasics interrupt check takes to much time for the pic to get to the function that records the signal and the verification fails.

I have seen several projects somehow managing to both send TRIAC signals with pic12f675 or similar without the light flickering when the pic receives the ir-signal, how do they do? I can't get the pic to be at two places in the program at once. Do I need to use hardware interrupts instead?

I know that there are a lot of dimmer threads i this forum but I did not find anything on a dimmer with ir-reception. Any other ir-code would be fine as long as I'm able to receive a 4-5 bit header and a 8 bit value.

Any good ideas?