Docsity

Programmable Remote Control - Lecture Notes | ECE 395, Study Guides, Projects, Research of Electrical and Electronics Engineering

Toggle sidebar
bg1
Programmable Remote Control
ECE 395
Spring 2006
Mark Jiang
Mike Yelin
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Programmable Remote Control - Lecture Notes | ECE 395 and more Study Guides, Projects, Research Electrical and Electronics Engineering in PDF only on Docsity!

Programmable Remote Control

ECE 395

Spring 2006

Mark Jiang

Mike Yelin

Abstract

The purpose of the project was to implement a remote control that could memorize signal

patterns from external remotes and then repeat them. The report will detail the

implementation of our plans, logic and progress in recording signals and replaying them.

Getting Started

As with the beginning of any project, it is important to get started by learning as much as

possible about the general topic. We started by taking as much time as possible to learn

generally about how remotes and infrared technology function. Once we had a good

overview of the topic, we built a state diagram.

The State Diagram

Figure 1: The State Diagram

Our state diagram begins at a main menu, at which point the user can choose to either

output a signal already stored on our remote control or record a signal to the remote. If

the user chooses to output, they simply need to push the corresponding button, and the

remote will output the correct signal. If the user wants to record a signal, they must push

the record button, which brings them to the next state – choosing which button to record.

Upon pressing the corresponding button, our remote will be ready to input a signal from

another remote. After the signal is sent to our remote, the remote will be ready to output

by pressing the corresponding button. In addition, the remote can record up to 15

consecutive signals (so the recording process can be repeated as desired).

Learning how to use a PIC

When we started, we planned on using a PIC 16F84A as we had some experience with it.

Although we were familiar with the PIC16, we needed more memory and functions than

the PIC16 contained, so we switched to the PIC18f2520. We spent a good amount of our

time getting used to the new PIC, which offered more than just additional memory. It

also had multiple timers as well as a user-friendly compare function. The datasheet was

invaluable to us ( http://ww1.microchip.com/downloads/en/DeviceDoc/39631a.pdf ) and

we referenced it constantly. A lot of learning the PIC was just trial and error. We

approached it as when either of us first learned the PIC16s. We started with the headings

then wrote simple code that would just blink an LED back and forth. Slowly we read

about different functions and then added them one by one. Once we had an idea of how

we wanted our code to work, we wrote it in parts and simulated that specific code in

For simplicity sake here is a general idea about how the rest of the code functions.

Our code ran in a continuous loop, doing nothing, until a button was pressed. This

interrupt made the code break from the loop and check for which button was pressed.

After seeing which pin’s signal was flipped, the code did one of two things.

If any button other than the record button was pressed, then the code jumped to

the output code, and through a comparison of timers and stored high/low signal lengths,

toggled the output pin to send out the correct signal. Since the signal had to be precise,

and was oscillating very fast, we had to take the time it takes for a line of code to execute

into account.

If the record button was pressed, then the code jumped to the record code. Here

the code recorded the lengths of every high and low time. This was done by running the

PIC’s timer and recording its value every time the input pin is toggled. The timer was

then reset and the process was repeated until the signal was done (which we knew

because we had a very long down time).

As soon as the process corresponding to the button pressed was over, the code

jumped back into the main loop – ready for another button to be pressed.

Final Hardware

Our final design started with a read signal (cleaned up by capacitors and transistors) from

an external remote control. The signal went into an infrared LED. This external remote

input signal was hooked up to one of our PIC18f2520’s input pins. The other input pins

were hooked up to buttons. The output pin was hooked up to an LED which would blink

the corresponding signal. To power our circuit, we used a 5V power supply, plugged into

the wall. Pictures of our hardware work are posted below.

Picture 1: the Invaluable ICD 2 kit

Picture 2: Our Hardware Schematic

Picture 3: Our final Circuit boards (left, post-etching: right: post-sautered)

Suggestions and Problems we Encountered

Our biggest problem was that we started out with the wrong PIC. We spent a lot of time

working on the PIC16, until we realized that it did not have the necessary amount of

OUR CODE

list p=pic18F #include <p18F2520.inc> #include <TVinclude.inc> CONFIG OSC = ECIO ; __CONFIG _CONFIG1H, _ECIO_OSC_1H ; __CONFIG _CONFIG2H, _WDT_OFF_2H

; bsf PORTC, 2 ; bsf INTCounter, 1 ; return movlw DataStorage>>8 ; point to buffer movwf FSR0H movlw DataStorage movwf FSR0L movlw d'63' movwf COUNTER ClearRam CLRF POSTINC0 ; present data to table latch ; write data, perform a short write DECFSZ COUNTER ; loop until buffers are full BRA ClearRam ;************ Main Loop ************************* MainLoop call CheckButton MainLoop movlw 0xFF cpfseq pointerl goto Output MainLoop call CheckButton movlw 0xFF cpfseq pointerl goto Record goto MainLoop ;************ Interruption Process ************** Interupt btfsc PORTB, 4 goto _continue bcf INTCON, RBIF retfie _continue btfsc INTCounter, 0 goto _Interrupt bsf T0CON, TMR0ON btfsc INTCounter, 2 call _Downtime bsf T1CON, TMR1ON bsf INTCounter, 0 bcf INTCON, RBIF retfie _Interrupt btfss INTCounter, 1 call setPWM clrf TMR0L clrf TMR0H

bcf INTCON, RBIF retfie _Downtime btg PORTB, 1 movf TMR1L, 0 ; addlw 0x0C movwf POSTINC ; clrf WREG ; addwfc TMR1H, 0 movf TMR1H, 0 movwf POSTINC ; movff TMR1H, PORTA ; movff TMR1L, PORTC clrf TMR1H movlw 0x movwf TMR1L return setPWM movff TMR0L, Store rrncf Store0, W andlw b'01111111' movwf Halfmod ; ************************** ; PWM setup ; rlncf Store0, W ; movff Store0, PR ; movf CCP1CON, ; andlw b'11001111' ; movwf CCP1CON ; btfsc Store0, 0 ; bsf CCP1CON, 4 ; btfsc Store0, 1 ; bsf CCP1CON, 5 ; rrncf Halfmod, 0 ; movwf CCPR1L ; movlw b'00000101' ; movwf T2CON ; movlw b'00001111' ; movwf CCP1CON ; bsf PORTC, 2 bsf INTCounter, 1 return ;************ CheckButton ************************ ;(returns starting memory address into pointerh and pointerl) CheckButton ; btfsc PORTC, 3 ; goto _button ; btfsc PORTC, 1 ; goto _button

_button movlw 0x0B movwf pointerh clrf pointerl return _button movlw 0x0C movwf pointerh clrf pointerl return _button movlw 0x0D movwf pointerh clrf pointerl return _button movlw 0x0E movwf pointerh clrf pointerl return _button movlw 0x0F movwf pointerh clrf pointerl return _button movlw 0x movwf pointerh clrf pointerl return _buttonVU movlw 0x movwf pointerh clrf pointerl return _buttonVD movlw 0x movwf pointerh clrf pointerl return _buttonCU movlw 0x movwf pointerh clrf pointerl return _buttonCD movlw 0x

movwf pointerh clrf pointerl return _buttonPW movlw 0x movwf pointerh clrf pointerl return _buttonREC movlw 0xff movwf pointerl return ;************* Output ***************************** Output movlw 0x movwf TBLPTRU movff pointerh, TBLPTRH movff pointerl, TBLPTRL bcf T0CON, TMR0ON clrf TMR0H clrf TMR0L movf TMR0H movf TMR0L movlw d'63' movwf counter bsf PORTB, 1 bsf T0CON, TMR0ON setlength TBLRD+ movff TABLAT, outputl ; 0x30 high TBLRD+ movff TABLAT, outputh ; 0x31 low movlw 0xFF cpfseq outputh goto gooddata movlw 0x movwf outputh gooddata movlw 0xFF cpfseq outputl goto Running movlw 0x movwf outputl Running movf TMR0L, W movf outputh, 0 cpfseq TMR0H goto Running clrf TMR0H

goto _INTLoop movlw 0x cpfslt TMR1L goto _EndSignal goto _INTLoop _Store BTG PORTB, 1 ; movff TMR1H, PORTA ; movff TMR1L, PORTC bcf T1CON, TMR1ON movf TMR1L, 0 ; addwf Halfmod, 0 ; sublw 0x0C movwf POSTINC ; movff TMR1H, dummy ; movlw 0x ; addwfc dummy, dummy ; decf dummy, 0 movf TMR1H, 0 movwf POSTINC bcf INTCounter, 0 bsf T1CON, TMR1ON bcf T0CON, TMR0ON clrf TMR1H movlw 0xF subfwb Halfmod, 0 movwf TMR1L clrf TMR0H clrf TMR0L bsf INTCounter, 2 return _EndSignal bcf INTCounter, 0 bcf INTCounter, 2 movlw 0x movwf TBLPTRU movff pointerh, TBLPTRH movff pointerl, TBLPTRL ; TBLPTR_Config DataStart BSF EECON1, EEPGD ; point to Flash program memory BCF EECON1, CFGS ; access Flash program memory BSF EECON1, WREN ; enable write to memory BSF EECON1, FREE ; enable Row Erase operation BCF INTCON, GIE ; disable interrupts MOVLW 55h MOVWF EECON2 ; write 55h MOVLW 0AAh MOVWF EECON2 ; write 0AAh BSF EECON1, WR ; start erase (CPU stall) ; BSF INTCON, GIE ; re-enable interrupts TBLRD*- ; dummy read decrement

WRITE_BUFFER_BACK

MOVLW D'32' ; number of bytes in holding register MOVWF COUNTER LFSR FSR0, DataStorage movlw 0x movwf TBLPTRU movff pointerh, TBLPTRH movff pointerl, TBLPTRL ; TBLPTR_Config DataStart WRITE_BYTE_TO_HREGS MOVFF POSTINC0, TABLAT ; present data to table latch TBLWT+ ; write data, perform a short write DECFSZ COUNTER ; loop until buffers are full BRA WRITE_BYTE_TO_HREGS PROGRAM_MEMORY movlw 0x movwf TBLPTRU movff pointerh, TBLPTRH movff pointerl, TBLPTRL ; TBLPTR_Config DataStart BSF EECON1, EEPGD ; point to Flash program memory BCF EECON1, CFGS ; access Flash program memory BSF EECON1, WREN ; enable write to memory MOVLW 55h MOVWF EECON2 ; write 55h MOVLW 0AAh MOVWF EECON2 ; write 0AAh BSF EECON1, WR ; start program (CPU stall) BSF INTCON, GIE ; re-enable interrupts BCF EECON1, WREN ; disable write to memory nop WRITE_BUFFER_BACK MOVLW D'32' ; number of bytes in holding register MOVWF COUNTER LFSR FSR0, DataStorage movlw 0x movwf TBLPTRU movff pointerh, TBLPTRH movff pointerl, TBLPTRL ; TBLPTR_Config DataStart WRITE_BYTE_TO_HREGS MOVFF POSTINC0, TABLAT ; present data to table latch TBLWT+ ; write data, perform a short write DECFSZ COUNTER ; loop until buffers are full BRA WRITE_BYTE_TO_HREGS PROGRAM_MEMORY ; movlw 0x ; movwf TBLPTRU ; movff pointerh, TBLPTRH ; movff pointerl, TBLPTRL ; TBLPTR_Config DataStart BSF EECON1, EEPGD ; point to Flash program memory BCF EECON1, CFGS ; access Flash program memory BSF EECON1, WREN ; enable write to memory