ECE 376 - Homework #3 Flow Charts, Binary Inputs, Binary Outputs (LEDs). Due Monday, January 29th The temperature sensor in your lab kits has the temperature-resistance relationship of R = 1000 exp 3965 3965 T 298 Ω where T is the temperature in degrees Kelvin (C + 273) 1) Design a circuit which outputs 0V when the temperature is below 0C when the temperature is above 0C At 0C, R = 3381Ω Assume a voltage divider with a 3300 Ohm resistor. Then V = R R+3300 As temperature goes up... = 2.5306V R goes down Vin goes down Vout goes up Connect the divider to the - input Connect 2.4306V to the + input 3300 2.5306V MCP602 Y R Vin 0V 0V 2.53V Hot 0C Cold
2) Design a circuit with hysteresis which outputs 0V when the temperature goes below 0C and when the temperature goes above 5C Assume a voltage divider with a 3300 Ohm resistor like problem #1 At 0C R = 3381 Ohms Vin = 2.5306V Vout goes low At 5C R = 2604 Ohms Vin = 2.205 Vout goes high As Vin goes low, Vout goes high. Connect the voltage divider to the - input The gain you need is gain = V out V in gain = 0V 2.5306V 2.205 = 15.38 When the output is 0V, you switch at 2.205. Set the + input to 2.205 153k 3300 Vin 2.20V 10k Y Vout R 10k Vin 0V 0V 2.20V 2.53V 153k hot 5C 0C cold
The characteristics for a piranha RGB LED is Red: Vf = 1.8V @ 20mA 10,000 mcd @ 20mA Green: Vf = 3.0V @ 20mA 10,000 mcd @ 20mA Blue: Vf = 3.0V @ 20mA 10,000 mcd @ 20mA 3) Design a circuit so that the PIC can turn on and off each LED at 20mA. Assign the I/O pins to: RC0: Red RC1: Green RC2: Blue Red Green Blue R r = 1.8V 20mA = 160Ω R g = 3.0V 20mA = 100Ω R b = 3.0V 20mA = 100Ω RC2 RC1 RC0 anode Rb Rg Rr cathode 3.0V 3.0V 1.8V blue green red Piranah Package common cathode + cathode + 3.0V - + blue 3.0V green 1.8V - + - red anode Rb Rg Rr RC2 RC1 RC0 Piranah Package common anode
The following program turns your PIC into an multi-function flashlight: Requirements: Input: Buttons RB0.. RB5 Output: Piranha RGB LED connected to pins RC0..RC1 Relationship: When you press a button, the color changes to: RB0: All colors off RB1 Red RB2 Green RB3 Blue RB4 White (R, G, B all on) RB5: Random color "On" is defined as 20mA +/- 5mA. Analysis:
4) Write an assembler program to implement this LED flashlight #include <p18f4620.inc> COLOR equ 0 ; Start of code: org 0x800 clrf TRISA movlw 0xFF movwf TRISB clrf TRISC clrf TRISD clrf TRISE clrf COLOR movlw 0x0F movwf ADCON1 Main: movf COLOR, W btfsc PORTB,0 ; off movlw 0 btfsc PORTB,1 ; red movlw 1 btfsc PORTB,2 ; green movlw 2 btfsc PORTB,3 ; blue movlw 4 btfsc PORTB,4 ; white movlw 7 btfss PORTB,5 ; random goto Output Random: addlw 1 btfsc PORTB,5 goto Random andlw 0x07 Output: movwf COLOR movff COLOR, PORTC goto Main RB0 RB1 RB2 Start Initialize PORTC = Input PORTC = Output Recall Present Color Button Pressed? none Off Red Green Blue White Random Output Color to PORTC RB3 RB4 RB5 end Compilation Results: Loaded C:\Documents and Settings\Administrator\My Documents\ECE376\Assembler\Flashlight.cof. Debug build of project `C:\Documents and Settings\Administrator\My Documents\ECE376\Assembler\1234.mcp' succeeded. Language tool versions: MPASMWIN.exe v5.51, mplink.exe v4.49, mplib.exe v4.49 Preprocessor symbol ` DEBUG' is defined.mon Jan 22 07:00:47 2018 BUILD SUCCEEDED
If you look at the.lst file: LOC OBJECT CODE VALUE LINE SOURCE TEXT 00001 #include <p18f4620.inc> 00001 LIST 00002 00003 ;========================================================================== 00004 ; MPASM PIC18F4620 processor include 00005 ; 00006 ; (c) Copyright 1999-2013 Microchip Technology, All rights reserved 00007 ;========================================================================== 00008 01439 LIST 00002 00000000 00003 COLOR equ 0 00004 00005 ; Start of code: 00006 000800 00007 org 0x800 00008 000800 6A92 00009 clrf TRISA 000802 0EFF 00010 movlw 0xFF 000804 6E93 00011 movwf TRISB 000806 6A94 00012 clrf TRISC 000808 6A95 00013 clrf TRISD 00080A 6A96 00014 clrf TRISE 00080C 6A00 00015 clrf COLOR 00016 00080E 0E0F 00017 movlw 0x0F 000810 6EC1 00018 movwf ADCON1 00019 000812 00020 Main: 000812 5000 00021 movf COLOR, W 00022 000814 B081 00023 btfsc PORTB,0 000816 0E00 00024 movlw 0 000818 B281 00025 btfsc PORTB,1 00081A 0E01 00026 movlw 1 00081C B481 00027 btfsc PORTB,2 00081E 0E02 00028 movlw 2 000820 B681 00029 btfsc PORTB,3 000822 0E04 00030 movlw 4 000824 B881 00031 btfsc PORTB,4 000826 0E07 00032 movlw 7 000828 AA81 00033 btfss PORTB,5 00082A EF1C F004 00034 goto Output 00082E 00035 Random: 00082E 0F01 00036 addlw 1 000830 BA81 00037 btfsc PORTB,5 000832 EF17 F004 00038 goto Random 000836 0B07 00039 andlw 0x07 000838 00040 Output: 000838 6E00 00041 movwf COLOR 00083A C000 FF82 00042 movff COLOR, PORTC 00083E EF09 F004 00043 goto Main 00044 MPASM 5.51 FLASHLIGHT.ASM 1-22-2018 7:00:45 PAGE 2
If you look at the.hex file :020000040000FA :10080000926AFF0E936E946A956A966A006A0F0E5A :10081000C16E005081B0000E81B2010E81B4020E93 :1008200081B6040E81B8070E81AA1CEF04F0010FF7 :1008300081BA17EF04F0070B006E00C082FF09EFCA :0208400004F0C2 :00000001FF That's your program. It taks 29 lines of assembler to make a flashlight. Validation: 5) Compile and download your code to your PIC board. Collect data to verify that you met the requirements: The current through each color is 20mA +/- 5mA Each button changes the output color RB5 produces a 'random' color (i.e. a random number from 0 to 7 is output to PORTC when you release RB5)
6) For your resulting program... How long does it take your program to loop? (toggle a bit you're not using, such as RC4, in the main loop. Check on the oscilloscope how fast this bit is toggling). How many lines of assembler does it take to implement an LED flashlight?