Hello again!
This is a continuation of the thread I have posted on the Projects Forum section. As I am now concerned about code , I have decided to move it here.
I posted this same thread on AVR-freaks , but i'm interested to hear the input of the people on AAC.
I'm trying to make this thing as realiable as possible so any comments are welcome.
*******
So i've been working on a simple laser alarm system that I'm going to be installing in my parents house and after some nice suggestions from some people on this forum I have completed my code for it.
Enclosed I have a Block-diagram of the system in a PNG.
I am not sure what Micro i'm going to be using , but for now I've programmed the code to suit the Atmega32 which is currently sitting on my breadboard .
Functionality:
I am going to be sending an IR laser which will be modulated at 10-40khz (Haven't decided on that yet , suggestions?)
and recieved by an IR sensor on the other side of the garden. The reciever is going to be fed into a schmitt trigger via ac coupling to get rid of ambient light ( the moon and some street lights which are about 20 meters away )and I should be getting a 0-5V 'square' signal into the AVR INT0 pin.
The idea is that I have a timer running and everytime the AVR recieves a pulse from the laser ( 40khz ), it resest the timer.
If the Laser beam is obstructed , then the timer will count up to OCR0 (which will be pre-adjusted by a pot and read by the ADC) and when a compare happens then the alarm will be activated for a preset amount of time (ie 6-10 seconds) and then deactivated .
The avr will only be sending a logic voltage to the alarm circuit ( which is analog ) and it will turn it on / off .
There also a few LED's : Laser status , POWER on( from psu) and ALARM led which will flash at about 5hz when the alarm is activated .
I've also included a manual shutdown button which will be connected to RESET for testing and calibration purposes
What do you guys think? Will there be any issues?
I'm thinking of using an attiny85 , I think that it
has all the necessary requirements for this project.
Question 0:
Should I use the internal oscillator or an external 16Mhz XTAL ?
Can I use timer/adc prescalers when using an external XTAL?
Thanks in advance for your time and Help
Tim
Here is an Updated Block-diagram of the system:
This is a continuation of the thread I have posted on the Projects Forum section. As I am now concerned about code , I have decided to move it here.
I posted this same thread on AVR-freaks , but i'm interested to hear the input of the people on AAC.
I'm trying to make this thing as realiable as possible so any comments are welcome.
*******
So i've been working on a simple laser alarm system that I'm going to be installing in my parents house and after some nice suggestions from some people on this forum I have completed my code for it.
Enclosed I have a Block-diagram of the system in a PNG.
I am not sure what Micro i'm going to be using , but for now I've programmed the code to suit the Atmega32 which is currently sitting on my breadboard .
Functionality:
I am going to be sending an IR laser which will be modulated at 10-40khz (Haven't decided on that yet , suggestions?)
and recieved by an IR sensor on the other side of the garden. The reciever is going to be fed into a schmitt trigger via ac coupling to get rid of ambient light ( the moon and some street lights which are about 20 meters away )and I should be getting a 0-5V 'square' signal into the AVR INT0 pin.
The idea is that I have a timer running and everytime the AVR recieves a pulse from the laser ( 40khz ), it resest the timer.
If the Laser beam is obstructed , then the timer will count up to OCR0 (which will be pre-adjusted by a pot and read by the ADC) and when a compare happens then the alarm will be activated for a preset amount of time (ie 6-10 seconds) and then deactivated .
The avr will only be sending a logic voltage to the alarm circuit ( which is analog ) and it will turn it on / off .
There also a few LED's : Laser status , POWER on( from psu) and ALARM led which will flash at about 5hz when the alarm is activated .
I've also included a manual shutdown button which will be connected to RESET for testing and calibration purposes
Rich (BB code):
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
int alarmstatus = 0;
int alarmdelay = 0;
int Flash_Red_Led = 0;
int main(void)
{
TCCR0 = ( 1 << CS02) | ( 1 << CS01 ) | ( 1 << CS00) | ( 1 << WGM01) | ( 1 << COM01 ) | ( 1 << COM00 ); // setting 1012 prescaler , CTC mode and OC01 Set on Compare
TIMSK = ( 1 << OCIE0 ); // Enabling Compare interrupts
sei(); // enabling global interrupts
OCR0 = 200 ; // setting the delay after which the alarm will sound ( this parameter will adjusted by experimentation )
MCUCR = ( 1 << ISC11 ) | ( 1 << ISC10); // setting the Laser input interrupt
DDRB = ( 1 << PINB2) | ( 1 << PINB0) | ( 1 << PINB1 ); // Setting the outputs: PINB2 = Alarm activation / PINB1 = Alarm status / PINB0 = Laser status
// setting the ADC:
ADMUX = ( 1 << ADLAR) | ( 1 << REFS0); // Setting Reference voltage to VCC (+5V) , Left-shifting ADCH for an 8 bit result
ADCSRA = ( 1 << ADEN ) | ( 1 << ADPS1 ) | ( 1 << ADPS0); // setting a prescaler of 8 for a 125khz adc rate , enabling the ADC
TCNT0 = 0; // starting timer
while(1)
{
ADCSRA |= ( 1 << ADSC) // start conversion
while (ADCSRA & ( 1 << ADIF)) // waiting for conversion
OCR0 = ADCH; // set OCR0 to ADCH
if(Flash_Red_Led == 1) // if alarm is triggered
{
PORTB ^= ( 1 << PINB1); // flash the alarm LED at about 5hz + interrupt delays ??
_delay_ms(200);
}
}
}
ISR(TIMER0_COMP_vect) // Enabling the alarm when timer reaches 0CR0
{
PORTB &= ~( 1 << PINB0); // Turn off Laser status LED signifying that the laser has been broken
Flash_Red_Led = 1;
if(alarmstatus == 0)
{
PORTB = 1 << PINB2; // activate alarm
MCUCR &= ~ ( ( 1 << ISC11) | ( 1 << ISC10) ) // disable Laser interrupts
alarmstatus = 1 ;
}
else
{
alarmdelay ++ ; // checking if the alarm has been ringing for a preset amount of time
if(alarmdelay > 700)
{
PORTB &= ~( 1 << PINB2); // Deactivate the alarm
MCUCR |= ( 1 << ISC11 ) | ( 1 << ISC10); // Turn interrupts back on and resume
alarmstatus = 0; // return variables to initial state
Flash_Red_Led = 0; // return variables to initial state
}
}
}
ISR(INT0_vect) // Resetting timer with every rising laser pulse
{
TCNT0 = 0; // reset timer
PORTB |= ( 1 << PINB0); // turn on Laser status LED
}
I'm thinking of using an attiny85 , I think that it
has all the necessary requirements for this project.
Question 0:
Should I use the internal oscillator or an external 16Mhz XTAL ?
Can I use timer/adc prescalers when using an external XTAL?
Thanks in advance for your time and Help
Tim
Here is an Updated Block-diagram of the system:
Last edited: