vendredi 12 décembre 2014
L'eau
Vidéo surveillance
Adaptation d'un détecteur PIR sur caméra avec un microcontrôleur ATTiny13.
ATTiny13 Camera PIR control.
ATTiny13 Camera PIR control.
Chasse sauvages
Efficacité confirmée en test sur sangliers en culture de céréales et oiseaux prédateurs sur fruitiers.
PIR detector linked to a bell to protect crops from wild attac.
mercredi 26 novembre 2014
jeudi 10 avril 2014
Temperature cellular bipper : Atmel Assembler AT tiny45
This circuit when it is called, hangs up and beep according to the ambient temperature.
Because market farmer have to be permanently cautious of the right climate of their green house. This tool has to be cheap according to the poor income that marketgrowing generate.
This is a first first personnal experience on circuit building. From recovering from scratch components, getting to know how µC work, and soldering with a small solar unit.
The first project was made with a sensor recovered from a Petrol heater but I couldn't get a right accurate temperature curve.So I redid the circuit with a sensor included in the chip (ATtiny45).
The ring in is connected to the vibrating motor of the cellular. Because of the low voltage on this last, it is connected to a transistor which pulls the µC pin on the ground on function.
Hang up pin is directly wired though an additionnal push-button so it is still possible to use the keyboard.
Buzzer is activated though a PWM pin (4,5 Mhz).
The solders are made with a 12v 35 W iron with a 60 W solar panel. Inspite of the power available, it really has to sun shine to do proper solders.
BIps
|
Température °C
|
1
|
~ under 0
|
2
|
0 à 6
|
3
|
6 à 9
|
4
|
9 à 16
|
5
|
16 à 20
|
6
|
20 à 24
|
7
|
24 à 30
|
8
|
30 à 35
|
12
|
More than de 35°C
|
/*
* at45PROJET.asm
*
* Created: 10/03/2014 16:56:44
* Author: fg
*/
; ********************************************
; * [Add Project title here] *
; * [Add more info on software version here] *
; * (C)20xx by [Add Copyright Info here] *
; ********************************************
;
; Included header file for target AVR type
.NOLIST
.INCLUDE "tn45def.inc" ; Header for ATTINY45
.LIST
;
; ============================================
; H A R D W A R E I N F O R M A T I O N
; ============================================
;
; [Add all hardware information here]
; ============================================
; P O R T S A N D P I N S
; ============================================
;
; [Add names for hardware ports and pins here]
; Format: .EQU Controlportout = PORTA
; .EQU Controlportin = PINA
; .EQU LedOutputPin = PORTA2
;
; ============================================
; C O N S T A N T S T O C H A N G E
; ============================================
;
; [Add all constants here that can be subject
; to change by the user]
; Format: .EQU const = $ABCD
;
; ============================================
; F I X + D E R I V E D C O N S T A N T S
; ============================================
;
; [Add all constants here that are not subject
; to change or calculated from constants]
; Format: .EQU const = $ABCD
;
; ============================================
; R E G I S T E R D E F I N I T I O N S
; ============================================
;
; [Add all register names here, include info on
; all used registers without specific names]
; Format: .DEF rmp = R16
.DEF loop1r = R9
.DEF loop2r = R10
.DEF loop3r = R11 ; Loops registers for 0,5 second timer
.DEF rmp = R16 ; Multipurpose register
.DEF Result = R17 ; 20 min Result of Store 1 to 4
.DEF buzzcounter =R18;
.DEF Mesureaverage = R20 ; Average of 4 checks then stored in a Store register
.DEF COUNTER = R21
.DEF Flags = R23
.DEF mesure = R24 ; multipurpose counters
;
; ============================================
; S R A M D E F I N I T I O N S
; ============================================
;
.DSEG
.ORG 0X0060
; Format: Label: .BYTE N ; reserve N Bytes from Label:
; ============================================
; R E S E T A N D I N T V E C T O R S
; ============================================
;
.CSEG
.ORG $0000
rjmp Main ; Reset vector
reti ; Int vector 1
rjmp PCINT0INTERRUPT ; Triggered when a ring come in
reti ; Int vecTOR 3
rjmp TImerend
reti ; Int vector 5
RETI ; Large prescaler timer loop interrupt
reti ; Int vector 7
reti ; Int vector 8
reti ; A/N conversion end interrupt which wakes-up the µC
;
; ============================================
; I N T E R R U P T S E R V I C E S
; ============================================
PCINT0INTERRUPT :
ldi mesure, 1
rcall secondtimer025 ; This routine because the timer didn't work properly in the interrupt
wdr
reti
TImerend :
ldi flags, 1
reti ; Set timer end flag to follow down the program.
; ============================================
; M A I N P R O G R A M I N I T
; ============================================
;.Avr-Asm-Tutorial 15 http://www.avr-asm-tutorial.net
Main:
; Init stack************************************************************
LDI rmp, LOW(RAMEND) ; Lower byte
OUT SPL,rmp ; to stack pointer
; Init Port B Directions************************************************
ldi rmp, 0b000001 ; Direction of Port B
; 0 = BUZZER
; 1 =
; 2 =
; 3 = rINGIN
; 4 = Hang up set to in because the controller just has to act as a switch the touch to ground.
; 5 = Reset
out DDRB,rmp
; Init Port B levels******************************************************
ldi rmp, 0b001110
out PortB, rmp; Unused port 1 and 2 Pull-ups enabled
; Set watchdog timer *****************************************************
ldi rmp, 1< out WDTCR, rmp ; Watchdog enable
ldi rmp, (1< out WDTCR, rmp ; Set WDT to 8 s
; Interrup ring
ldi rmp, 1< out GIMSK, rmp
ldi rmp, 1< out PCMSK, rmp ; Port 3 interrupt enable
; ============================================
; P R O G R A M
; ============================================
rcall buzzer
rcall secondtimer025
rcall secondtimer025
ldi rmp, (0< out TCCR0B, rmp ; , Beep 0,5 second, off buzzer
rcall secondtimer025
rcall secondtimer025 ; Wait 0,5 second
; Measure routine ***********************************************************************
Measureroutine :
ldi rmp, 0
sei ; Enable interrupts
loop :
WDR
sbrs Mesure, 0
rjmp loop ; Wait for ringing in flag setting
cli
ldi counter, 4
loopone :
rcall second
dec counter
brne loopone ; Wait 4 Second to avoid to fast hanging up execution
sbi DDRB, 4 ;
rcall second
cbi DDRB, 4 ; Hang up
ldi counter, 3
looptwo :
rcall second
dec counter
brne looptwo ; Wait the time the line is on
wdr ;
; First fake conversion to led the AD starting
ldi rmp, (1< out ADMUX, rmp
ldi rmp, (1< out DIDR0, rmp ; AD in disable
ldi rmp, (0< out MCUCR, rmp ; ADC noise réduction mode
ldi rmp, (1< out ADCSRA, rmp ; Start conversion, interrupt enable
SEI
SLEEP ; Wait for done conversion interrupt
CLI
in rmp, ADCL
in rmp, ADCH ; Load out the data to allow new Datas measurement.
ldi rmp, (1< out ADMUX, rmp
ldi rmp, (1< out DIDR0, rmp ; AD in disable
ldi rmp, (0< out MCUCR, rmp ; ADC noise réduction mode
ldi rmp, (1< out ADCSRA, rmp ; Start conversion, interrupt enable
SEI
SLEEP
CLI
ldi rmp, (0< out ADMUX, rmp
ldi rmp, (0< out MCUCR, rmp ; off ADC noise réduction mode
ldi rmp, (0< out ADCSRA, rmp ; Stop conversion,
; answer************************************************************
ans :
ldi Result, 0
ldi buzzcounter,0
in Result, ADCL
in rmp, ADCH; Load in High to allow next measurement. This part is not needed because it doesn't change at those temperatures.
cpi Result, 25
brmi buzzerone ; Compare with thresholds .
cpi Result, 30
brmi buzzertwo ; under 6 °c
cpi Result, 34
brmi buzzerthree ; under 9°c
cpi Result, 42 ;
brmi buzzerfour ; 16
cpi Result, 48
brmi buzzerfive ; 20
cpi Result, 56
brmi buzzersix ; 24
cpi Result, 62
brmi buzzerseven ; 30
cpi Result, 66
brmi buzzereight
rjmp buzzertwelve ;over 35
; Corresponding number of buzzer bip Loading **********************************************************
buzzerone :
ldi buzzcounter, 1
rjmp buzz
buzzertwo :
ldi buzzcounter, 2
rjmp buzz
buzzerthree :
ldi buzzcounter, 3
rjmp buzz
buzzerfour:
ldi buzzcounter, 4
rjmp buzz
buzzerFIVE:
ldi buzzcounter, 5
rjmp buzz
buzzerSIX :
ldi buzzcounter, 6
rjmp buzz
buzzerSEVEN :
ldi buzzcounter, 7
rjmp buzz
buzzereight :
ldi buzzcounter, 8
rjmp buzz
buzzertwelve :
ldi buzzcounter, 12
rjmp buzz
;buzz *****************************************************************************
buzz :
rcall buzzer
buzzloop :
WDR
ldi rmp, (1< out TCCR0B, rmp ; on buzzer
rcall secondtimer025
ldi rmp, (0< out TCCR0B, rmp ; off buzzer
rcall second
dec buzzcounter
cpi buzzcounter, 0
brne buzzloop ; Beep according to the threshold
ldi mesure, 0 ; Reset Ring in bit
rjmp Measureroutine
;**********************************************************************************
secondtimer025 :
ldi rmp, 2
mov loop3r, rmp
ldi rmp, 77
mov loop2r,rmp
mov loop1r,rmp
loop3 :
dec loop3r
BRNE loop2 ; 0,25 second timer
ret
loop2 :
dec loop2r
breq loop3
loop1 :
dec loop1r
breq loop2
rjmp loop1
; Buzzer *************************************************************************************
buzzer :
ldi rmp, 0
out TCCR0A, rmp
out TCCR0B, rmp
out OCR0A, rmp
ldi rmp, (1< out TCCR0A, rmp ; Toggle OC0A on compare match, CTC mode
ldi rmp, 60 ;
out OCR0A, rmp ; OC0A on in a 4khz frequency
ldi rmp, (1< out TCCR0B, rmp ; , Timer on & 8 prescaling
ret
; 1 second timer 1 set
second :
sei
ldi rmp,60
out OCR1C, rmp
ldi rmp, 0
out TCNT1, rmp
ldi rmp, (1< out TIMSK, rmp ; enable overflow interrupt to prompt the end
ldi rmp, (1< out TCCR1, rmp ; clock/16384
ldi rmp,(1< out GTCCR, rmp ; reset prescaler to start timer immediately
CLR FLAGS
endwait :
sbrs flags, 0 ; Check overflow bit, skip if set
rjmp endwait ; Wait for timer overflow
ret
; End
* at45PROJET.asm
*
* Created: 10/03/2014 16:56:44
* Author: fg
*/
; ********************************************
; * [Add Project title here] *
; * [Add more info on software version here] *
; * (C)20xx by [Add Copyright Info here] *
; ********************************************
;
; Included header file for target AVR type
.NOLIST
.INCLUDE "tn45def.inc" ; Header for ATTINY45
.LIST
;
; ============================================
; H A R D W A R E I N F O R M A T I O N
; ============================================
;
; [Add all hardware information here]
; ============================================
; P O R T S A N D P I N S
; ============================================
;
; [Add names for hardware ports and pins here]
; Format: .EQU Controlportout = PORTA
; .EQU Controlportin = PINA
; .EQU LedOutputPin = PORTA2
;
; ============================================
; C O N S T A N T S T O C H A N G E
; ============================================
;
; [Add all constants here that can be subject
; to change by the user]
; Format: .EQU const = $ABCD
;
; ============================================
; F I X + D E R I V E D C O N S T A N T S
; ============================================
;
; [Add all constants here that are not subject
; to change or calculated from constants]
; Format: .EQU const = $ABCD
;
; ============================================
; R E G I S T E R D E F I N I T I O N S
; ============================================
;
; [Add all register names here, include info on
; all used registers without specific names]
; Format: .DEF rmp = R16
.DEF loop1r = R9
.DEF loop2r = R10
.DEF loop3r = R11 ; Loops registers for 0,5 second timer
.DEF rmp = R16 ; Multipurpose register
.DEF Result = R17 ; 20 min Result of Store 1 to 4
.DEF buzzcounter =R18;
.DEF Mesureaverage = R20 ; Average of 4 checks then stored in a Store register
.DEF COUNTER = R21
.DEF Flags = R23
.DEF mesure = R24 ; multipurpose counters
;
; ============================================
; S R A M D E F I N I T I O N S
; ============================================
;
.DSEG
.ORG 0X0060
; Format: Label: .BYTE N ; reserve N Bytes from Label:
; ============================================
; R E S E T A N D I N T V E C T O R S
; ============================================
;
.CSEG
.ORG $0000
rjmp Main ; Reset vector
reti ; Int vector 1
rjmp PCINT0INTERRUPT ; Triggered when a ring come in
reti ; Int vecTOR 3
rjmp TImerend
reti ; Int vector 5
RETI ; Large prescaler timer loop interrupt
reti ; Int vector 7
reti ; Int vector 8
reti ; A/N conversion end interrupt which wakes-up the µC
;
; ============================================
; I N T E R R U P T S E R V I C E S
; ============================================
PCINT0INTERRUPT :
ldi mesure, 1
rcall secondtimer025 ; This routine because the timer didn't work properly in the interrupt
wdr
reti
TImerend :
ldi flags, 1
reti ; Set timer end flag to follow down the program.
; ============================================
; M A I N P R O G R A M I N I T
; ============================================
;.Avr-Asm-Tutorial 15 http://www.avr-asm-tutorial.net
Main:
; Init stack************************************************************
LDI rmp, LOW(RAMEND) ; Lower byte
OUT SPL,rmp ; to stack pointer
; Init Port B Directions************************************************
ldi rmp, 0b000001 ; Direction of Port B
; 0 = BUZZER
; 1 =
; 2 =
; 3 = rINGIN
; 4 = Hang up set to in because the controller just has to act as a switch the touch to ground.
; 5 = Reset
out DDRB,rmp
; Init Port B levels******************************************************
ldi rmp, 0b001110
out PortB, rmp; Unused port 1 and 2 Pull-ups enabled
; Set watchdog timer *****************************************************
ldi rmp, 1<
ldi rmp, (1<
; Interrup ring
ldi rmp, 1<
ldi rmp, 1<
; ============================================
; P R O G R A M
; ============================================
rcall buzzer
rcall secondtimer025
rcall secondtimer025
ldi rmp, (0<
rcall secondtimer025
rcall secondtimer025 ; Wait 0,5 second
; Measure routine ***********************************************************************
Measureroutine :
ldi rmp, 0
sei ; Enable interrupts
loop :
WDR
sbrs Mesure, 0
rjmp loop ; Wait for ringing in flag setting
cli
ldi counter, 4
loopone :
rcall second
dec counter
brne loopone ; Wait 4 Second to avoid to fast hanging up execution
sbi DDRB, 4 ;
rcall second
cbi DDRB, 4 ; Hang up
ldi counter, 3
looptwo :
rcall second
dec counter
brne looptwo ; Wait the time the line is on
wdr ;
; First fake conversion to led the AD starting
ldi rmp, (1<
ldi rmp, (1<
ldi rmp, (0<
ldi rmp, (1<
SEI
SLEEP ; Wait for done conversion interrupt
CLI
in rmp, ADCL
in rmp, ADCH ; Load out the data to allow new Datas measurement.
ldi rmp, (1<
ldi rmp, (1<
ldi rmp, (0<
ldi rmp, (1<
SEI
SLEEP
CLI
ldi rmp, (0<
ldi rmp, (0<
ldi rmp, (0<
; answer************************************************************
ans :
ldi Result, 0
ldi buzzcounter,0
in Result, ADCL
in rmp, ADCH; Load in High to allow next measurement. This part is not needed because it doesn't change at those temperatures.
cpi Result, 25
brmi buzzerone ; Compare with thresholds .
cpi Result, 30
brmi buzzertwo ; under 6 °c
cpi Result, 34
brmi buzzerthree ; under 9°c
cpi Result, 42 ;
brmi buzzerfour ; 16
cpi Result, 48
brmi buzzerfive ; 20
cpi Result, 56
brmi buzzersix ; 24
cpi Result, 62
brmi buzzerseven ; 30
cpi Result, 66
brmi buzzereight
rjmp buzzertwelve ;over 35
; Corresponding number of buzzer bip Loading **********************************************************
buzzerone :
ldi buzzcounter, 1
rjmp buzz
buzzertwo :
ldi buzzcounter, 2
rjmp buzz
buzzerthree :
ldi buzzcounter, 3
rjmp buzz
buzzerfour:
ldi buzzcounter, 4
rjmp buzz
buzzerFIVE:
ldi buzzcounter, 5
rjmp buzz
buzzerSIX :
ldi buzzcounter, 6
rjmp buzz
buzzerSEVEN :
ldi buzzcounter, 7
rjmp buzz
buzzereight :
ldi buzzcounter, 8
rjmp buzz
buzzertwelve :
ldi buzzcounter, 12
rjmp buzz
;buzz *****************************************************************************
buzz :
rcall buzzer
buzzloop :
WDR
ldi rmp, (1<
rcall secondtimer025
ldi rmp, (0<
rcall second
dec buzzcounter
cpi buzzcounter, 0
brne buzzloop ; Beep according to the threshold
ldi mesure, 0 ; Reset Ring in bit
rjmp Measureroutine
;**********************************************************************************
secondtimer025 :
ldi rmp, 2
mov loop3r, rmp
ldi rmp, 77
mov loop2r,rmp
mov loop1r,rmp
loop3 :
dec loop3r
BRNE loop2 ; 0,25 second timer
ret
loop2 :
dec loop2r
breq loop3
loop1 :
dec loop1r
breq loop2
rjmp loop1
; Buzzer *************************************************************************************
buzzer :
ldi rmp, 0
out TCCR0A, rmp
out TCCR0B, rmp
out OCR0A, rmp
ldi rmp, (1<
ldi rmp, 60 ;
out OCR0A, rmp ; OC0A on in a 4khz frequency
ldi rmp, (1<
ret
; 1 second timer 1 set
second :
sei
ldi rmp,60
out OCR1C, rmp
ldi rmp, 0
out TCNT1, rmp
ldi rmp, (1<
ldi rmp, (1<
ldi rmp,(1<
CLR FLAGS
endwait :
sbrs flags, 0 ; Check overflow bit, skip if set
rjmp endwait ; Wait for timer overflow
ret
; End
Libellés :
45 assembler,
agriculture,
AT,
atmel,
cellular,
cropping,
green house,
programming,
project,
temperature,
tiny
mercredi 8 janvier 2014
Little system made with a Petrol heater sensor and an this AVR.
When the A/D converter voltage is over threshold, the Mic sends 3 pulses on the call cell phone button (this wakes him up, and calls the last number called stored in the calling list).
After 15 sec, it hooks down.
It waits then a call in to stop the routine. If no answer, the routine is repeated 4 times.
If still no answer, the Mic wait a while (10mn) to redo the operation if the temperature is still up.
Temperature threshold to be set.
/*
* Tempcellularalarm.asm
*
* Created: 25/07/2013 14:33:48
* Author: fg
*/
; ********************************************
; * [Add Project title here] *
; * [Add more info on software version here] *
; * (C)20xx by [Add Copyright Info here] *
; ********************************************
;
; Included header file for target AVR type
.NOLIST
.INCLUDE "tn13Adef.inc" ; Header for ATTINY13
.LIST
;
; ============================================
; H A R D W A R E I N F O R M A T I O N
; ============================================
;
; [Add all hardware information here]
;
; ============================================
; P O R T S A N D P I N S
; ============================================
;
; [Add names for hardware ports and pins here]
; Format: .EQU Controlportout = PORTA
; .EQU Controlportin = PINA
; .EQU LedOutputPin = PORTA2
;
; ============================================
; C O N S T A N T S T O C H A N G E
; ============================================
;
; [Add all constants here that can be subject
; to change by the user]
; Format: .EQU const = $ABCD
;
; ============================================
; F I X + D E R I V E D C O N S T A N T S
; ============================================
;
; [Add all constants here that are not subject
; to change or calculated from constants]
; Format: .EQU const = $ABCD
;
; ============================================
; R E G I S T E R D E F I N I T I O N S
; ============================================
;
; [Add all register names here, include info on
; all used registers without specific names]
; Format: .DEF rmp = R16
.DEF loop1r = R9
.DEF loop2r = R10
.DEF loop3r = R11 ; Loops registers for 0,5 second timer
.DEF Tmaxl = R12
.DEF Tmaxh = R13 ; Low and high bytes for the threshold comparing
.DEF ENDMS = R15 ; 0 register to compare with a counter register (CPI and Skip or branch if equal)
.DEF rmp = R16 ; Multipurpose register
.DEF Ring = R17 ; Ring flag
.DEF Flags = R19 ; End conversion flag
.DEF COUNTER = R21
.DEF COUNTERVAL = R23
.DEF Timerloopcounter = R24 ; multipurpose counters
;
; ============================================
; S R A M D E F I N I T I O N S
; ============================================
;
.DSEG
.ORG 0X0060
; Format: Label: .BYTE N ; reserve N Bytes from Label:
; ============================================
; R E S E T A N D I N T V E C T O R S
; ============================================
;
.CSEG
.ORG $0000
rjmp Main ; Reset vector
reti ; Int vector 1
rjmp PIN0INTERRUPT ; Triggered when a ring come in
reti ; Int vecTOR 3
reti ; Int vector 4
reti ; Int vector 5
rjmp Timerreloadinterrupt ; Large prescaler timer loop interrupt
reti ; Int vector 7
reti ; Int vector 8
rjmp endconversion ; A/N conversion end interrupt
;
; ============================================
; I N T E R R U P T S E R V I C E S
; ============================================
PIN0INTERRUPT :
clr ring
reti ; This routine clears the ring flag so the program stop calling or hang up.
Timerreloadinterrupt :
dec Timerloopcounter
sbi Pinb, 0 ; Toggle led
reti
endconversion :
inc Flags
reti ; Set the flag to follow down when conversion is done
; ============================================
; M A I N P R O G R A M I N I T
; ============================================
;.Avr-Asm-Tutorial 15 http://www.avr-asm-tutorial.net
Main:
; Init stack************************************************************
LDI rmp, LOW(RAMEND) ; Lower byte
OUT SPL,rmp ; to stack pointer
; Init Port B Directions************************************************
ldi rmp, 0b00001000 ; Direction of Port B
; 0 = Led/Ring in
; 1 = Phone pick-up
; 2 = Hook down
; 3 = none
; 4 = Sensor
; 5 = Reset
out DDRB,rmp
; Init Port B levels******************************************************
ldi rmp, 0b0000000
out PortB, rmp
; Set watchdog timer *****************************************************
ldi rmp, 1< out WDTCR, rmp ; Watchdog enable
ldi rmp, (1< out WDTCR, rmp ; Set WDT to 8 s
; ============================================
; P R O G R A M
; ============================================
ldi Timerloopcounter, 6
loopV :
rcall secondtimer05
dec Timerloopcounter
brne loopV
start :
WDR
sbi DDRB,0
sbi PORTB,0 ; Switch on led (DDRB to out and PortB to + 5 V)
;measureloop :
ldi Flags, 0 ; reset done conversion flag
;Check :
ldi rmp, (1< out DIDR0, rmp ; Enable buffer on pin 4 only
ldi rmp, (0< out ADMUX, rmp ; Switch off the other multiplexers
ldi rmp, 0b11001000
out ADCSRA, rmp ; Enable conversion complete interruption
; Enable analog converter
; Start conversion
sei ; Enable interrupts
Loopwaitconv :
cpi Flags,1 ; Compare flags register with 1 (Flag register-1)
brne Loopwaitconv ; If not 0 loop back
cli ; If flag set, disable interrupts
ldi rmp, 0
out ADCSRA, rmp ; Disable conversion complete interruption
; Disable analog converter
; No conversion
;ldi rmp, 0x43
ldi rmp, -6
mov Tmaxl, rmp
;ldi rmp, 0x01
ldi rmp, -6
mov Tmaxh, rmp ; Load threshold
in rmp, adcl
sub rmp, Tmaxl ; Compare
in rmp, adch
sbc rmp, Tmaxh ; Compare
brpl Phonecall ; Over? => Call
; otherwise, follow down
; LARGEPRESCALERTIMER 10 min Settings****************************************************************************
LARGEPRESCALERTIMER :
LDI Timerloopcounter, 100
LDI COUNTERVAL, 220
RCALL LARGEPRESCALERTIMER ; Set to ~10 min wait
rjmp start
;LARGEPRESCALERTIMER*************************************************************************
; Settings to count with 0,027 second per cycle
; Time = ([312,52 to 392,56 ) + [COUNTERVAL*27322 µs+ 10*26,6 µs ]*Timerloopcounter
; If Timerloopcounter = 0 => Time = 339,12 µs +COUNTERVAL*27307 µs
ldi rmp, (1< out TCCR0A, rmp ;CTC MODE
ldi rmp, (1< out TIMSK0, rmp ;OCA INTERRUPT ENABLE
out OCR0A, COUNTERVAL ;OcA value
ldi rmp, (1< out GTCCR , rmp ;Set synchro bit GTCCR 7 which synchro the TIMER prescaler
ldi rmp, 1< out CLKPR ,rmp ;Set ClkPRES enable ;
ldi rmp, (1< out CLKPR ,rmp ;Set CLkpres to /256 ;0,83 µs * (4+12) = 13,28 µs
ldi r16, 5
out TCCR0B, r16 ;Set timer prescaler to /1024
ldi rmp, 0< out GTCCR , rmp ;Clear GTCCR 7
sei ;5*26,6µs = 133µs Nb : The timer starts counting from here
; Init = 146,28 µs
WaittimerTEN :
wdr ; Watchdog reset.
cpse Timerloopcounter, ENDMS ;[OCR0A*27307 µs+(4+2+4)*26,6]*Timerloopcounter
rjmp WaittimerTEN
sbi PINB,0 ; TOGGLE PIN SO THE LED BLINKS WHILE WAITING
EXIT:
cli
ldi rmp, 1< out CLKPR ,rmp ;Set ClkPRES enable ;2
ldi rmp, (0< out CLKPR ,rmp ;Set CLkpres to /8 ;4 = (6 to 9)*26,6 µs = 159,6 to 239,4 µs
ldi rmp, (0< out TIMSK0, rmp ;OCA INTERRUPT DISABLE ;2
nop ;3
ret ;4+4)*0,83µs = 6.64 µs
; Exit = (159,6 to 239,4 µs)+ 6.64 µs = 166,24 to 246,04 µs
;Pheaune kall*************************************************************************
Phonecall :
ldi counter, 5 ; Set 4 times calling
ldi ring, 1 ; Set ring flag
Phonecallloop :
dec counter
breq lp ; If 4 Times call, go to end
sbi DDRb, 1
rcall secondtimer05
cbi DDRb, 1
rcall secondtimer05
sbi DDRb, 1
rcall secondtimer05
cbi DDRb, 1
rcall secondtimer05
sbi DDRb, 1
rcall secondtimer05
cbi DDRb, 1
rcall secondtimer05 ; Hang up (This model needs 3 times Hang up pushing,
; Wake-up from sleep, last number dialled display, and pick-up)
ldi Timerloopcounter, 20
loopIV :
WDR
rcall secondtimer05
dec Timerloopcounter
brne loopIV ; ; Wait (4 tones or the messagebox)
sbI DDRB, 2
rcall secondtimer05
cbi DDRB, 2 ; Hook down
;Wait & Answer check********************************************************
cbi portb, 0
cbi DDRB, 0 ; Pin0 to in on ring receive mode
ldi rmp, 1< out GIMSK, rmp ; Enable interrupts
ldi rmp, 1< out PCMSK, rmp ; Set Interrupt on pin 0
SEI
ldi COUNTERVAL, 2
loopVI :
ldi Timerloopcounter, 230
LDI Timerloopcounter, 10
loopIII :
WDR
rcall secondtimer05
dec Timerloopcounter
brne loopIII
dec COUNTERVAL
brne loopVI
cli ; Wait ~ 5 min an answer
ldi rmp, 0< out GIMSK, rmp
ldi rmp, 0< out PCMSK, rmp ; Off Interrupt on pin 0
cpi Ring, 0 ; Compare Ring with 0 (Ring-0)
breq lp ; If answer (Ring register decreased) GOto end
rjmp Phonecallloop ; If not finished, phone again
; secondtimer05***************************************************
secondtimer05 :
ldi rmp, 4
mov loop3r, rmp
ldi rmp, 77
mov loop2r,rmp
mov loop1r,rmp
loop3 :
dec loop3r
BRNE loop2 ; 0,5 second timer
ret
loop2 :
dec loop2r
breq loop3
loop1 :
dec loop1r
breq loop2
rjmp loop1
; End of source code
;
When the A/D converter voltage is over threshold, the Mic sends 3 pulses on the call cell phone button (this wakes him up, and calls the last number called stored in the calling list).
After 15 sec, it hooks down.
It waits then a call in to stop the routine. If no answer, the routine is repeated 4 times.
If still no answer, the Mic wait a while (10mn) to redo the operation if the temperature is still up.
Temperature threshold to be set.
/*
* Tempcellularalarm.asm
*
* Created: 25/07/2013 14:33:48
* Author: fg
*/
; ********************************************
; * [Add Project title here] *
; * [Add more info on software version here] *
; * (C)20xx by [Add Copyright Info here] *
; ********************************************
;
; Included header file for target AVR type
.NOLIST
.INCLUDE "tn13Adef.inc" ; Header for ATTINY13
.LIST
;
; ============================================
; H A R D W A R E I N F O R M A T I O N
; ============================================
;
; [Add all hardware information here]
;
; ============================================
; P O R T S A N D P I N S
; ============================================
;
; [Add names for hardware ports and pins here]
; Format: .EQU Controlportout = PORTA
; .EQU Controlportin = PINA
; .EQU LedOutputPin = PORTA2
;
; ============================================
; C O N S T A N T S T O C H A N G E
; ============================================
;
; [Add all constants here that can be subject
; to change by the user]
; Format: .EQU const = $ABCD
;
; ============================================
; F I X + D E R I V E D C O N S T A N T S
; ============================================
;
; [Add all constants here that are not subject
; to change or calculated from constants]
; Format: .EQU const = $ABCD
;
; ============================================
; R E G I S T E R D E F I N I T I O N S
; ============================================
;
; [Add all register names here, include info on
; all used registers without specific names]
; Format: .DEF rmp = R16
.DEF loop1r = R9
.DEF loop2r = R10
.DEF loop3r = R11 ; Loops registers for 0,5 second timer
.DEF Tmaxl = R12
.DEF Tmaxh = R13 ; Low and high bytes for the threshold comparing
.DEF ENDMS = R15 ; 0 register to compare with a counter register (CPI and Skip or branch if equal)
.DEF rmp = R16 ; Multipurpose register
.DEF Ring = R17 ; Ring flag
.DEF Flags = R19 ; End conversion flag
.DEF COUNTER = R21
.DEF COUNTERVAL = R23
.DEF Timerloopcounter = R24 ; multipurpose counters
;
; ============================================
; S R A M D E F I N I T I O N S
; ============================================
;
.DSEG
.ORG 0X0060
; Format: Label: .BYTE N ; reserve N Bytes from Label:
; ============================================
; R E S E T A N D I N T V E C T O R S
; ============================================
;
.CSEG
.ORG $0000
rjmp Main ; Reset vector
reti ; Int vector 1
rjmp PIN0INTERRUPT ; Triggered when a ring come in
reti ; Int vecTOR 3
reti ; Int vector 4
reti ; Int vector 5
rjmp Timerreloadinterrupt ; Large prescaler timer loop interrupt
reti ; Int vector 7
reti ; Int vector 8
rjmp endconversion ; A/N conversion end interrupt
;
; ============================================
; I N T E R R U P T S E R V I C E S
; ============================================
PIN0INTERRUPT :
clr ring
reti ; This routine clears the ring flag so the program stop calling or hang up.
Timerreloadinterrupt :
dec Timerloopcounter
sbi Pinb, 0 ; Toggle led
reti
endconversion :
inc Flags
reti ; Set the flag to follow down when conversion is done
; ============================================
; M A I N P R O G R A M I N I T
; ============================================
;.Avr-Asm-Tutorial 15 http://www.avr-asm-tutorial.net
Main:
; Init stack************************************************************
LDI rmp, LOW(RAMEND) ; Lower byte
OUT SPL,rmp ; to stack pointer
; Init Port B Directions************************************************
ldi rmp, 0b00001000 ; Direction of Port B
; 0 = Led/Ring in
; 1 = Phone pick-up
; 2 = Hook down
; 3 = none
; 4 = Sensor
; 5 = Reset
out DDRB,rmp
; Init Port B levels******************************************************
ldi rmp, 0b0000000
out PortB, rmp
; Set watchdog timer *****************************************************
ldi rmp, 1<
ldi rmp, (1<
; ============================================
; P R O G R A M
; ============================================
ldi Timerloopcounter, 6
loopV :
rcall secondtimer05
dec Timerloopcounter
brne loopV
start :
WDR
sbi DDRB,0
sbi PORTB,0 ; Switch on led (DDRB to out and PortB to + 5 V)
;measureloop :
ldi Flags, 0 ; reset done conversion flag
;Check :
ldi rmp, (1<
ldi rmp, (0<
ldi rmp, 0b11001000
out ADCSRA, rmp ; Enable conversion complete interruption
; Enable analog converter
; Start conversion
sei ; Enable interrupts
Loopwaitconv :
cpi Flags,1 ; Compare flags register with 1 (Flag register-1)
brne Loopwaitconv ; If not 0 loop back
cli ; If flag set, disable interrupts
ldi rmp, 0
out ADCSRA, rmp ; Disable conversion complete interruption
; Disable analog converter
; No conversion
;ldi rmp, 0x43
ldi rmp, -6
mov Tmaxl, rmp
;ldi rmp, 0x01
ldi rmp, -6
mov Tmaxh, rmp ; Load threshold
in rmp, adcl
sub rmp, Tmaxl ; Compare
in rmp, adch
sbc rmp, Tmaxh ; Compare
brpl Phonecall ; Over? => Call
; otherwise, follow down
; LARGEPRESCALERTIMER 10 min Settings****************************************************************************
LARGEPRESCALERTIMER :
LDI Timerloopcounter, 100
LDI COUNTERVAL, 220
RCALL LARGEPRESCALERTIMER ; Set to ~10 min wait
rjmp start
;LARGEPRESCALERTIMER*************************************************************************
; Settings to count with 0,027 second per cycle
; Time = ([312,52 to 392,56 ) + [COUNTERVAL*27322 µs+ 10*26,6 µs ]*Timerloopcounter
; If Timerloopcounter = 0 => Time = 339,12 µs +COUNTERVAL*27307 µs
ldi rmp, (1<
ldi rmp, (1<
out OCR0A, COUNTERVAL ;OcA value
ldi rmp, (1<
ldi rmp, 1<
ldi rmp, (1<
ldi r16, 5
out TCCR0B, r16 ;Set timer prescaler to /1024
ldi rmp, 0<
sei ;5*26,6µs = 133µs Nb : The timer starts counting from here
; Init = 146,28 µs
WaittimerTEN :
wdr ; Watchdog reset.
cpse Timerloopcounter, ENDMS ;[OCR0A*27307 µs+(4+2+4)*26,6]*Timerloopcounter
rjmp WaittimerTEN
sbi PINB,0 ; TOGGLE PIN SO THE LED BLINKS WHILE WAITING
EXIT:
cli
ldi rmp, 1<
ldi rmp, (0<
ldi rmp, (0<
nop ;3
ret ;4+4)*0,83µs = 6.64 µs
; Exit = (159,6 to 239,4 µs)+ 6.64 µs = 166,24 to 246,04 µs
;Pheaune kall*************************************************************************
Phonecall :
ldi counter, 5 ; Set 4 times calling
ldi ring, 1 ; Set ring flag
Phonecallloop :
dec counter
breq lp ; If 4 Times call, go to end
sbi DDRb, 1
rcall secondtimer05
cbi DDRb, 1
rcall secondtimer05
sbi DDRb, 1
rcall secondtimer05
cbi DDRb, 1
rcall secondtimer05
sbi DDRb, 1
rcall secondtimer05
cbi DDRb, 1
rcall secondtimer05 ; Hang up (This model needs 3 times Hang up pushing,
; Wake-up from sleep, last number dialled display, and pick-up)
ldi Timerloopcounter, 20
loopIV :
WDR
rcall secondtimer05
dec Timerloopcounter
brne loopIV ; ; Wait (4 tones or the messagebox)
sbI DDRB, 2
rcall secondtimer05
cbi DDRB, 2 ; Hook down
;Wait & Answer check********************************************************
cbi portb, 0
cbi DDRB, 0 ; Pin0 to in on ring receive mode
ldi rmp, 1<
ldi rmp, 1<
SEI
ldi COUNTERVAL, 2
loopVI :
ldi Timerloopcounter, 230
LDI Timerloopcounter, 10
loopIII :
WDR
rcall secondtimer05
dec Timerloopcounter
brne loopIII
dec COUNTERVAL
brne loopVI
cli ; Wait ~ 5 min an answer
ldi rmp, 0<
ldi rmp, 0<
cpi Ring, 0 ; Compare Ring with 0 (Ring-0)
breq lp ; If answer (Ring register decreased) GOto end
rjmp Phonecallloop ; If not finished, phone again
; secondtimer05***************************************************
secondtimer05 :
ldi rmp, 4
mov loop3r, rmp
ldi rmp, 77
mov loop2r,rmp
mov loop1r,rmp
loop3 :
dec loop3r
BRNE loop2 ; 0,5 second timer
ret
loop2 :
dec loop2r
breq loop3
loop1 :
dec loop1r
breq loop2
rjmp loop1
; End of source code
;
Inscription à :
Articles (Atom)