Project For Engineers

Led effect

No comments




This project I made for my little daughter. It is 24 channel light illumination. The schematic is very simple – 24 LED’s, 1 MCU and some additional components. The main principle is dynamic indication, which is usually implemented for control of 7-segment digital indicators. Here is the same, as for indicators are used traditional 5-mm LED’s.
For control unit is implemented not expensive MCU ATTYNI2313 (Atmel), which can drive direct LED (up to 20 mA on each pin). As you can see on the schematic, 24 LED’s are grouped in 4 groups, each one consist 6 LED’s. LED’s in group 1 indicate the content of register r0 of MCU, LED’s in group 2 – r1, LED’s in group 3 – r3 and LED’s in group 4 indicate the content of register r3. Dynamic indication do this, as in each moment of time indicates content of one register and scans them consecutive. For instance, when the content of r1 is loaded in output port (PORTB), the transistor Q2 is switched "ON", and the LED of group 2 indicate the bits in r1.


There are 3 buttons – "F", "+" and "-". The button F is for change of effect, and buttons "+" and "–" are for increasing or decreasing the speed of effect. For example, each time when you press button "-" changing of lights go more slowly. For fast changing of speed you can press and hold the appropriate button.
The speed of effects is independent of speed of dynamic indication, which is constant.
The schematic can be powered by any DC adapter for 8 to 15 V / 100mA. I use 12V adapter and for the stabilizer 7805 there is no need of heat sink for them – this is one of advantages of implementation of dynamic indication. Others advantages are simple schematic and PCB, lower pin count of MCU etc.


Software is written in assembler of IDE AVRStudio 4. The program code is below. There are a lot of comments for explanation how the program works. With simple changes in code everyone can make different effects and/or add them. Each effect can be up to 24 stages.
If the LED pins are made longer with additional wires, LED effects can be used for Christmas tree or for advertising text on shop window (for instance). If there is need, LED number can be easy increased up to 32 LED’s and stages. Enjoy!





Schematic




Download design files in Proteus 7 format

Source Code


;*****************************************************************
;LED illumination
;rev. 4, 06/09/2010god
;MCU ATtiny2313 , internal RC generator, 4 MHZ
;*****************************************************************
.include "2313def.inc" ;Done some changes for ATtiny2313 !
; r0 - consits group 1
; r1 - consits group 2
; r2 - consits group 3
; r3 - consits group 4
; r4 - counter of groups for Effect 1
; r5 - counter of groups for Dynamic Indication
; r6 - counter of effects
.cseg
.org $000
                rjmp RESET ;Reset Handle
                reti ;LabINT0; External Interrupt0 Vector Address
                reti ;LabINT1; External Interrupt1 Vector Address
                reti ;TIM1_CAPT; Timer/Counter1 Capture Event
                reti ;TIM1_COMP; Timer/Counter1 Compare Match A
                reti ;TIM1_OVF; Timer/Counter1 Overflow
                rjmp TIM0_OVF; Timer/Counter0 Overflow
                reti
                reti
                reti
                reti
;************************************************
TIM0_OVF: ;it does dynimic indication
                mov r16, r5 ; couter is loaded
                clz
                cpi r16, 0 ; if is 0 then group 1
                breq Tvar1
                clz
                cpi r16, 1 ; if is 1 then group 2
                breq Tvar2
                clz
                cpi r16, 2 ; if is 2 then group 3
                breq Tvar3
                rjmp Tvar4 ; else group 4
Tvar1:  
                mov r16, r0
                out PORTB, r16
                cbi PORTD, PD3 ; clear group 4
                sbi PORTD, PD0 ; indicate group 1
                inc r5
                rjmp Tizhod
Tvar2:
                mov r16, r1
                out PORTB, r16
                cbi PORTD, PD0 ; clear group 1
                sbi PORTD, PD1 ; indicate group 2
                inc r5
                rjmp Tizhod
Tvar3:
                mov r16, r2
                out PORTB, r16
                cbi PORTD, PD1 ; clear group 2
                sbi PORTD, PD2 ; indicate group 3
                inc r5
                rjmp Tizhod
Tvar4:
                mov r16, r3
                out PORTB, r16
                cbi PORTD, PD2 ; clear group 3
                sbi PORTD, PD3 ; indicate group 4
                clr r5
Tizhod:
                sei
                reti
;************************************************
Efekt1:
                in r17, TIFR ;chek if TMR1 is overtime
                sbrs r17, TOV1
                rjmp E1izh ;if not overtime -> go out
                ldi r17, $80 ; clear interrupt flag
                out TIFR, r16
                sec ; flag C = 1
                rol r0 ; load 1 through flag C
                bst r0,6 ; load the bit through flag T into next register
                rol r1 ;
                bld r1,0
                bst r1,6
                rol r2
                bld r2,0
                bst r2,6
                rol r3
                bld r3,0
                bst r3,6
                brts E1Clr ; check for finishing (last bit in last register)
                rjmp E1izh
E1Clr:
                clr r0 ; clear all registers
                clr r1
                clr r2
                clr r3
E1izh:
                ret
;************************************************
Efekt2:
                in r17, TIFR ;;chek if TMR1 is overtime
                sbrs r17, TOV1
                rjmp E2izh ;if it is not -> go out
                ldi r17, $80 ;clear interrupt flag
                out TIFR, r16
                mov r17, r4 ; load counter
                clz
                cpi r17, 0 ; if 0 rolling r0
                breq E2var0
                clz
                cpi r17, 1 ; if 1 rolling r1
                breq E2var1
                clz
                cpi r17, 2 ; if 2 rolling r3
                breq E2var2
                rjmp E2var3 ; else rolling r3
E2var0:
                clc ; flag C = 0
                rol r0 ; load 1 through flag C
                sbrc r0, 6 ;check if first 6 bits are 0's
                rjmp E2izh ; if are not -> go out
                clc ; if it is -> rolling next register
                rol r1 ; (in this case r1)
                rjmp E2izINC
E2var1:
                clc ; flag C = 0
                rol r1 ; load 1 through flag C
                sbrc r1, 6 ;check if first 6 bits are 0's
                rjmp E2izh ; if are not -> go out
                clc ;if it is -> rolling next register
                rol r2 ; (in this case r2)
                rjmp E2izINC
E2var2:
                clc ; flag C = 0
                rol r2 ; load 1 through flag C
                sbrc r2, 6 ;check if first 6 bits are 0's
                rjmp E2izh ; if are not -> go out
                clc ;if it is -> rolling next register
                rol r3 ; (in this case r3)
                rjmp E2izINC
E2var3:
                clc ; flag C = 1
                rol r3 ; load 1 through flag C
                sbrc r3, 6 ;check if first 6 bits are 0's
                rjmp E2izh ; if are not -> go out
                ldi r17, $FF ;if they are -> each bit is set
                mov r0, r17
                mov r1, r17
                mov r2, r17
                mov r3, r17
E2izINC:
                inc r4 ;this fragment increase counter (r4)
                mov r17, r4
                clc
                cpi r17, 4 ;if it is = 4, then it is cleared
                brlo E2izh ;to start again
                clr r4 ;r4=0 , or it pointes r0
E2izh:
                ret
;************************************************
Prog1: ;Main program
                sbis PORTD, PD4 ;check for pressing button "+"
                rjmp IncTmr
                sbis PORTD, PD5 ;check for pressing button "-"
                rjmp DecTmr
                sbis PORTD, PD6 ;check for pressing button "F"
                rjmp EfSel ;(for change of effect
                mov r17, r6 ; load effect counter
                clz
                cpi r17, 0 ; if 0 then roll r0
                breq PRvar0
                rcall Efekt2
                rjmp Prog1
PRvar0:
                rcall Efekt1
                rjmp Prog1
IncTmr:
                ldi r17,TCNT1H
                clz
                cpi r17, $FC ;check for max value
                breq IncOut ;$FC is max value
                inc r17
                out TCNT1H, r17
IncOut:
                rjmp Prog1
DecTmr:
                ldi r17,TCNT1H
                clz
                cpi r17, $CC ;check for max value
                breq DecOut ;$CC is max value
                dec r17
                out TCNT1H, r17
DecOut:
                rjmp Prog1
EfSel:
                mov r17, r6
                clz
                cpi r17, 1 ;check for max value
                breq EfSel1 ;$1 is max value
                inc r6 ;(2 effects)
                rjmp Prog1
EfSel1:
                clr r6
                rjmp Prog1
;************************************************
Reset: ;Initiation section
                ldi r16, $DF ;STACK forming
                out SPL, r16        
                ldi r16,$FF ;Init. Port B
                out DDRB, r16 ;B0 - B7 are outputs
                ldi r16,$0F ;Init. Port D
                out DDRD, r16 ;D0 - D3 are outputs
; D4, D5 and D6 are inputs
                clr r16
                out PORTD, r16 ;clear all groups
                clr r0 ;clear all registers
                clr r1
                clr r2
                clr r3
                clr r4 ;clear counter for Effect 1
                clr r5 ;clear counter for Dynimic Indication
                clr r6 ;clear counter of effects
                ldi r16, 3  ; 8-bit Timer
                out TCCR0B, r16 ;Prescaler=1/64
                ldi r16, 3  ; 16-bit Timer
                out TCCR1B, r16 ;Prescaler=1/64
                ldi r16, $E7 ;load E795 for time interval 0,1s
                ldi r17, $FF
                out TCNT1H, r16 ; first is high Byte
                out TCNT1L, r17 ; second is low Byte
                sei  ; enable global interrupt
                ldi r16, 2 ; enable TMR0 interrupt
                out TIMSK, r16
                rjmp Prog1 ; end of initialisation section
.exit




PCB

No comments :

Post a Comment