electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

IR light dimmer


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> IR light dimmer
Author Message
tomikan



Joined: 09 Oct 2006
Posts: 13


Post03 Dec 2006 21:11   

ir light dimmer


I want to build an IR light dimmer with pic microcontroller. For dimming I want to use a TV remote control. PIC have to read the code and change the brightness of the light. Reading the code takes a lot of time (25ms) and the light pulse when receiving the code. Does anybody know how to solve this problem?
Back to top
Jaspaa



Joined: 09 Jan 2005
Posts: 12
Helped: 1


Post03 Dec 2006 23:43   

addressable light dimmer ir


I don't fully understand what your problem is, but I made a circuit, doing about the same, some time ago

The main principle is to have a high priority function controlling the Triac. Easiest way to do this is by using a timer interrupt. And another function doing the IR decoding.
The Triac driving function should read the pulse timing from a register, which the IR receive and decode function can adjust when it decoded the data from the remote.
The decoding of your IR signal should take no longer then it takes the remote to transmit it fully. Just study the protocol used by your TV remote for the timing.

I got mine working in less then a day. I'm definatly not a skilled programmer so the code was crap, but it worked fine. Using a high level language such as C will work to create a quick decoder, for the Triac timing I'd suggest writing ASM.

Good luck!
Back to top
VSMVDD



Joined: 12 Jun 2005
Posts: 558
Helped: 55


Post03 Dec 2006 23:52   

#use delay(clock rc5 int_ext


tomikan wrote:
I want to build an IR light dimmer with pic microcontroller. For dimming I want to use a TV remote control. PIC have to read the code and change the brightness of the light. Reading the code takes a lot of time (25ms) and the light pulse when receiving the code. Does anybody know how to solve this problem?


your baud rate to com between is too low for the data packet size

your send/recieve data is too long and full of clutter not needed to com

25ms is a lifetime

i think your project has a problem

post it

so we can help further
Back to top
tomikan



Joined: 09 Oct 2006
Posts: 13


Post04 Dec 2006 18:11   

Re: IR light dimmer


Here is the code.


#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <stdio.h>
#include "rc5decode.h"

#byte Portb = 0x06
#byte TMR = 0x01


#byte Portb = 0x06
#define IR_IN portb,4//0

int save_w;
#locate save_w=0x7f
int save_status;
#locate save_status=0x20

#byte status = 3


/*--- globals ---*/
int command;
//unsigned char command;
unsigned char address;
unsigned char temp;
unsigned char timer;
unsigned char rc5valid;

int tipka=32;
int com;

int i=0,j=0,a=0,b=0,io=0;
int x=0,t3,t2;
int tomi=0;
unsigned int vred=0;

void pavza()
{
#asm

MOVLW 33
MOVWF T3
MOVF vred,W
MOVWF T2
PAV1:
DECFSZ T3,F
GOTO PAV1
MOVLW 33
MOVWF T3
DECFSZ T2,F
GOTO PAV1
#endasm
}

//#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))
//static bit IR_PIN @ PORTBIT(GPIO, 2);

/*--- rc5 decode function ---*/
//static void interrupt //


unsigned char rc5decode(void)
{
#asm

MOVWF save_w
SWAPF status,W
BCF status,5
BCF status,6
MOVWF save_status

;------ calibrate timing

bcf 3,5 ;select bank 0
clrf TMR ;start timer
call Wlow ;get the pulse length
call Whigh

btfsc TMR,7 ;test for timer overflow
goto codeError ;bail out

movf TMR,w ;save pulse length
clrf TMR ;start timer

movwf timer ;take the pulse length,
movwf temp ;save it
bcf 3,0 ;clear carry
rrf temp,f ;divide by 2
bcf 3,0 ;clear carry
rrf temp,f ;divide by 4
movf temp,w ;and subtract to get
subwf timer,f ;3/4 pulse length

movlw 0x0c
movwf temp ;init bit counter

;------ wait for start of data

nextBit: movf timer,w ;wait 3/4 pulse length
subwf TMR,w
btfss 3,2 ;take a look
goto nextBit

;------ start of data stream

btfss IR_IN ;if its high
goto waitlow ;gonna be an 0

;------ wait for high 1

call Whigh ;if its low
bsf 3,0 ;gonna be a 1
goto clock

;------ wait for low 0

waitlow: call Wlow
bcf 3,0 ;gonna be an 0

;------ clock data

clock: clrf TMR ;restart timer
rlf command,f ;save the bit
rlf address,f
decfsz temp,f ;done all bits?
goto nextBit

;------ get system address, toggle bit and command code

movf command,w ;copy low byte
movwf temp ;into temp
rlf temp,f ;need to shift 2 bits
rlf address,f ;into address
rlf temp,f
rlf address,f ;system address is 5 bits

movlw 0x3f ;mask system address + toggle bit
andwf address,f

movlw 0x3f ;mask command code
andwf command,f ;command code is 6 bits
goto rc5ok ;done ok

;------ wait while low

Wlow: btfsc TMR,7 ;test for timer overflow
return ;bail out
btfss IR_IN
goto Wlow
return

;------ wait while high

Whigh: btfsc TMR,7 ;test for timer overflow
return ;bail out
btfsc IR_IN
goto Whigh
return

rc5ok: movlw 0x01
movwf rc5valid
goto rc5end
codeError: clrf rc5valid
rc5end: nop

SWAPF save_status,W
MOVWF status
SWAPF save_w,F
SWAPF save_w,W

#endasm
return rc5valid;
}

#int_ext
isr(){


if(vred==0)goto ss;
output_low(pin_a1);
if(vred==180)goto ns;

pavza();


ss:
output_high(pin_a1);
ns:
x=1;


}


#int_rb
isr_i(void)
{

if(rc5decode())
{
address &= 0x1F;

if(command==32) a=1;
if(command==33) b=1;
rc5valid=0;
}
}





void main(void)
{
set_tris_b(0xff);
ext_int_edge( h_to_l );
setup_timer_0 (RTCC_DIV_128|RTCC_internal);
port_b_pullups(true);



enable_interrupts(global);
enable_interrupts(int_ext);
enable_interrupts(int_rb);

a=0;
i=0;
j=0;
x=0;
io=0;
vred=180;


do
{



if(a==1)
{
a=0;
delay_ms(200);


if((a==0)&&(vred==180)) {vred=0; a=0; goto nap;}


po: if((a==1)) {vred=vred-10; a=0; if(vred==-10)vred=0;}


delay_ms(100);

if(a==1) goto po;
nap: delay_us(1);
}

if(b==1)
{
b=0;
delay_ms(200);


if((b==0)) {vred=180; b=0; goto nap1;}

po1: if((b==1)) {vred=vred+10; b=0; if(vred==190) vred=180; }

delay_ms(100);

if(b==1) goto po1;
nap1: j=1;
}

}while(1);


}

/*--- End of File ---*/
Back to top
Google
AdSense
Google Adsense




Post04 Dec 2006 18:11   

Ads




Back to top
manish12



Joined: 21 Nov 2006
Posts: 1020
Helped: 31


Post05 Dec 2006 6:44   

Re: IR light dimmer


You can also ref the application note from microchip for rc5 remote code analyzer for ready second option .
After this you have to work with hv be careful.
Back to top
microsim



Joined: 15 Jul 2007
Posts: 4


Post19 Jul 2007 8:18   

Re: IR light dimmer


There was a project published on th web, I worked on, published on the web for the author william Boucher, his e-mail boucher(at)mnsi.net

I am unable to open his home page, (http://www.mnsi.net/~boucher/emporium.htm)
it seems he closed it, you may contact him to give you the full article.

thanks, I have the drawings and the schematics, But I have to look for them first! I have no time.


Sam
Back to top
kelvin_foru



Joined: 19 Jul 2007
Posts: 5
Helped: 1


Post19 Jul 2007 10:18   

IR light dimmer


There is a website which has a project of remote controlling 6devices and a fan with speed control which can be used as dimmer, but the circuit is based on Atmel microcontroller.

www.8051projects.info/projects.asp

Kelvin
Back to top
jamenyang



Joined: 14 Jul 2007
Posts: 12


Post23 Jul 2007 4:18   

IR light dimmer


good idea,you are great
Back to top
otuzsubat



Joined: 07 Jun 2004
Posts: 45
Helped: 2
Location: istanbul, Turkey


Post25 Jul 2007 11:55   

Re: IR light dimmer


h**p://innovexpo.itee.uq.edu.au/2001/projects/s369398/index.html

it is a complete project about IR Remote Room Light Switch
Back to top
segmex



Joined: 25 Oct 2006
Posts: 223
Helped: 6


Post01 Sep 2007 13:34   

IR light dimmer


thanks for links !
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> IR light dimmer
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Light dimmer.... (8)
Light Dimmer (2)
Remote Light dimmer (3)
light dimmer circuit (1)
remote controlled light dimmer (12)
Help Needed... Light dimmer (1)
audio controlled light dimmer (3)
3 steps touch light dimmer (3)
Dome Light Dimmer for cars (2)
Dimmer for Energy Saving Light Bulbs ? (4)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS