Outils pour utilisateurs

Outils du site


Toddlers blow-out LED

A toddlers-safe variant of the blow-out LED light featured recently on HaD. The tiny LED on thin wires is a bit fragile, but a tea infuser makes a good mechanical protection, provides a handle, and lets enough air through to make it work!

Hardware

The hardware is based on:

  • PIC12F1572, PDIP-8, baute PIC assembly is sooo much fun
  • 0603 LED (red), plenty at PTL, relatively easy to solder and light enough
  • 0603 resistor (value? somewhere between 100-220 Ω, IIRC), 0603 goes nicely between the pins of the PIC
  • 0.1mm elam. copper wire
  • battery case with switch, housing, well, the power source, and the PIC+resistor for the magic
  • tea infuser as mechanical protection of the LED.

Schematics?

RTCL.

Code

First, good news: running the PIC on the slow internal oscillator makes the ADC precise enough to be able running without averaging.

Here the – quickly hacked – code. Do not remove debug output if you do not want to screw with the timing ;-)

; blow -- the PIC version of the blow-out LED light.
; Copyright (C) 2018 Magnus (magnustron)
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
	PROCESSOR 12F1572
        INCLUDE <p12f1572.inc>

        __CONFIG _CONFIG1,_FOSC_INTOSC & _WDTE_SWDTEN & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _BOREN_NSLEEP & _CLKOUTEN_OFF
        __CONFIG _CONFIG2,_WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LPBOREN_ON & _LVP_OFF

	CBLOCK	 0x70
last1h:		1
last1l:		1
last2h:		1
last2l:		1
last3h:		1
last3l:		1
holdoff:	1
inhibit:	1
	ENDC

	ORG 0
; 0 - CONFIGURE CLOCK
	banksel	OSCCON
	clrf	OSCCON
; 1 - CONFIGURE I/Os
 	banksel	TRISA
	movlw	1<<TRISA4
	movwf	TRISA
; 2 - SET DEBUG UART
	banksel	TXSTA
	bsf	TXSTA,TXEN
	bsf	RCSTA,SPEN
; 3 - ENABLE ADC
	banksel	ADCON0
	movlw	1<<ADON|1<<CHS1|1<<CHS0
	movwf	ADCON0
	bsf	ADCON1,ADFM
; INIT DONE
	clrf	holdoff	
	movlw	D'10'
	movwf	inhibit
forever:
	movlw	'm'
	call	send
	movlw	'a'
	call	send
	movlw	'g'
	call	send
	movlw	'n'
	call	send
	movlw	'u'
	call	send
	movlw	's'
	call	send
; check if holdoff
	movf	holdoff,W
	call	send
	btfss	STATUS,Z
	decf	holdoff
	banksel	LATA
	btfsc	STATUS,Z
	bsf	LATA,LATA5

; ADC conversion!
	banksel	ADCON0
	bsf	ADCON0,ADGO
wait_adc:
	btfsc	ADCON0,ADGO
	bra	wait_adc

; substract result from the one taken 3 steps ago (bit arbitrary)
	banksel	ADRESL
	movf	ADRESL,W
	call	send
	subwf	last3l,F
	banksel	ADRESH
	movf	ADRESH,W
	call	send
	subwfb	last3h,F
; check if inhibit
	movf	inhibit,W
	call	send
	btfss	STATUS,Z
	decf	inhibit
	btfss	STATUS,Z
	bra	noblow
; check if result is <-1
	movlw	1
	addwf	last3l,F
	clrw	
	addwfc	last3h,F
	btfss	last3h,7
	bra	noblow
	movlw	0xF0
	call	send
	movlw	0x01
	call	send
switchoff:
	banksel	LATA
	bcf	LATA,LATA5
	movlw	D'20'
	movwf	holdoff
	movlw	D'30'
	movwf	inhibit
noblow:
	movf	last3h,W
	call	send
	movf	last3l,W
	call	send
	movf	last2h,W
	movwf	last3h
	movf	last2l,W
	movwf	last3l
	movf	last1h,W
	movwf	last2h
	movf	last1l,W
	movwf	last2l
	banksel	ADRESH
	movf	ADRESH,W
	movwf	last1h
	movf	ADRESL,W
	movwf	last1l

	clrw
wait:
	decf	WREG
	btfss	STATUS,Z
	bra	wait
	bra	forever

send:
	banksel TXSTA
send_wait:
	btfss	TXSTA,TRMT
	bra	send_wait
	movwf	TXREG
	return

        END

The code prints some debug info on serial, at a weird baud rate. I was using a PicoScope 2204A to read it.

Liens externes

projects/electronics/toddler-blowout-led.txt · Dernière modification: 2018/10/21 22:24 par magnustron