| Author |
Message |
|
|
Posted: Jun 19, 2012 - 01:50 PM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
tnanx Mr.mtaschl
i changed the code and compile but again it shows error
B
Quote:
uild started 19.6.2012 at 18:17:29
avr-gcc -mmcu=atmega168 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT protector_circuit.o -MF dep/protector_circuit.o.d -c ../protector_circuit.c
In file included from ../protector_circuit.c:4:0:
c:\program files\atmel\avr tools\avr toolchain\bin\../lib/gcc/avr/4.5.1/../../../../avr/include/util/delay.h:89:3: warning: #warning "F_CPU not defined for <util/delay.h>"
../protector_circuit.c:7:0: warning: "F_CPU" redefined
c:\program files\atmel\avr tools\avr toolchain\bin\../lib/gcc/avr/4.5.1/../../../../avr/include/util/delay.h:90:0: note: this is the location of the previous definition
../protector_circuit.c: In function '__vector_21':
../protector_circuit.c:95:7: error: expected ';' before '}' token
../protector_circuit.c:98:5: error: expected expression before '}' token
../protector_circuit.c:100:4: error: expected 'while' before 'else'
../protector_circuit.c:104:4: error: expected '}' before 'else'
../protector_circuit.c:143:7: error: expected ';' before '}' token
../protector_circuit.c:146:5: error: expected expression before '}' token
../protector_circuit.c:147:4: error: expected 'while' before 'else'
../protector_circuit.c:151:4: error: expected '}' before 'else'
../protector_circuit.c:190:7: error: expected ';' before '}' token
../protector_circuit.c:193:5: error: expected expression before '}' token
../protector_circuit.c:194:4: error: expected 'while' before 'else'
../protector_circuit.c:198:4: error: expected '}' before 'else'
make: *** [protector_circuit.o] Error 1
Build failed with 12 errors and 2 warnings...
|
|
|
| |
|
|
|
|
|
Posted: Jun 19, 2012 - 01:54 PM |
|

Joined: Aug 21, 2002
Posts: 895
Location: Austria
|
|
do - while constructs need to be terminated with a semikolon.
Code:
do {
// code
} while (/* condition */);
They are all missing in your ISR. |
_________________ /Martin.
|
| |
|
|
|
|
|
Posted: Jun 19, 2012 - 01:59 PM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
|
|
|
|
|
Posted: Jun 19, 2012 - 02:01 PM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
can i use mutiple adc along with analog comparator with inturrupts
in a project? |
|
|
| |
|
|
|
|
|
Posted: Jun 19, 2012 - 02:03 PM |
|

Joined: Aug 21, 2002
Posts: 895
Location: Austria
|
|
| You can, but your concept is a polling-concept. IMO forget about interrupts and continue or rethink and start from the scratch again. |
_________________ /Martin.
|
| |
|
|
|
|
|
Posted: Jun 19, 2012 - 02:05 PM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
if an interrupt occur then then the control will go to ISR_()of that paricular interrupt.
after the process in the ISR , where to go the control? |
|
|
| |
|
|
|
|
|
Posted: Jun 19, 2012 - 02:09 PM |
|

Joined: Aug 21, 2002
Posts: 895
Location: Austria
|
|
| It will return to the instruction next to that one that has been executed before the ISR. |
_________________ /Martin.
|
| |
|
|
|
|
|
Posted: Jun 19, 2012 - 10:18 PM |
|


Joined: Sep 04, 2002
Posts: 21258
Location: Orlando Florida
|
|
Get it working without interrupts. A conversion takes about 120usec. Write a subroutine that inits the a/d converter. Do not use free running mode. Write a subroutine that reads the given channel of the a/d converter by settting the channel in the ADMUX without stomping on the top 2 bits that set the ref, the poll the ADSC bit until it goes low. This only takes about 120usec. Read the result and return. Store the result.
Perhaps we can gain some insight to how to best solve your design problem if you explain why you require simultaneous reading of the 3 channels. This feature is used in sonar (search for simultaneous sampling converter on chip mfgr sites) where the time arrival of the returns must be grabbed on all inputs with the same usec timing relation. Using an AVR you read channel 0 then 1 then 2 120usec apart. Good enough? |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 05:31 AM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
| how can i make my avr clock into 16MHz |
|
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 05:42 AM |
|


Joined: Sep 04, 2002
Posts: 21258
Location: Orlando Florida
|
|
| Use a 16 MHz crystal. |
_________________ Imagecraft compiler user
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 06:41 AM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
| how can i simulate my adc using atmel studio4 gcc compiler? |
|
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 07:50 AM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
| how can i compare between two analog voltages using adc, for ensure that there must be a constant vge differece two between 2 signal. if the vge difference between the signal exceeds then an led must glow. |
|
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 08:30 AM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
| ! or ~ which is meant for NOT operation in avr studio 4, gcc compiler |
|
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 08:41 AM |
|


Joined: Mar 27, 2002
Posts: 18560
Location: Lund, Sweden
|
|
That depends what kind of NOT operation you want. Both are supported by the avr-gcc compiler, and are applicable in different scenarios.
Open your C textbook and read about it. |
|
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 08:48 AM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
code shows error again and i cant predict the behaviour
Code:
#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <util/delay.h>
//system clock @1MHz
#define F_CPU 1000000
//Global variable
int adc_result[3]={0,0,0};//for storing the adc out put
uint8_t ch=0;
/* PORT INIT */
void port_init (void)
{
//set portB.1 as output drive for relay
DDRB |=(1<<PB1);
PORTB&=~(1<<PB1);
//set portC0-4 as input and enable the pull up resistor
DDRC &=~((1<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC3)|(1<<PC4));// ADC i/p R,B,Y & Gnd, neutral
PORTC |=((1<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC3)|(1<<PC4));
//set up port D 0-3 as output
DDRD &=~((1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD3));//o/p led for R,B,Y and GLP
}
void init_adc(void)
{
// Set ADC prescaler to 8 - 125KHz sample rate @ 1MHz
ADCSRA |= ((1 << ADPS1) | (1 << ADPS0));
// Enable ADC Interrupt
ADCSRA |= (1 << ADIE);
// Enable ADC
ADCSRA |= (1 << ADEN);
// Enable Global Interrupts
sei();
ADCSRA |= (1<<ADSC);
}
/* Interrupt service routine for Analog comparator*/
ISR(ANA_COMP)
{
}
/* Interrupt service routines */
ISR(ADC_vect)
{
//delay for discarding first conversion result
//_delay_ms(10);
//Read the adc result
switch(ch)
{
case 0:
{
adc_result[0]=ADCW;
if(adc_result[0]>823) //checking for vge >265V
{
do
{
PORTD|=(1<<PD0);//glow the led corresponding to signal 1
_delay_ms(3);
//Start next conversion with same channel
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[0]=ADCW;
if(adc_result[0]>837) //checking for vge >270V
{
do
{
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[0]=ADCW;
PORTB|=(1<<PB1);// o/p drive ON if the state at adc0 exist for a particular time
}while (adc_result[0]<823);//do until the vge reduced to 265V
}
}while(adc_result[0]>823);
PORTD&=~(1<<PD0);//off the led corresponding to signal 1
PORTB&=~(1<<PB1);// o/p drive off for ON the relay
}
else if (adc_result[0]<713)//checking for vge <230V
{
do
{
PORTD|=(1<<PD3);//glow the led corresponding to UV indication
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[0]=ADCW;
}while(adc_result[0]<713);//do until vge >230V
PORTD&=~(1<<PD3);//off the led corresponding to UV indication
}
else
{
if(ch<3)
{
ch++;//change adc channel
ADMUX=ch;
}
}
break;
}
case 1:
{
adc_result[1]=ADCW;
if(adc_result[1]>823)//checking for vge >265V
{
do
{
PORTD|=(1<<PD1);//glow the led corresponding to signal 2
//Start next conversion with same channel
_delay_ms(3);
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[0]=ADCW;
if(adc_result[0]>837) //checking for vge >270V
{
do
{
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[0]=ADCW;
PORTB|=(1<<PB1);// o/p drive if the state at adc1 exist for a particular time
}while (adc_result[1]>862);
}
}while(adc_result[1]>823);
PORTD|=(1<<PD1);//off the led corresponding to signal 2
PORTB&=~(1<<PB1);// o/p drive off for ON the relay
}
else if(adc_result[1]<713)//checking for vge <230V
{
do
{
PORTD|=(1<<PD3);//glow the led corresponding to UV indication
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[0]=ADCW;
}while(adc_result[0]<713);//do until vge >230V
PORTD&=~(1<<PD3);//off the led corresponding to UV indication
}
else
{
if(ch<3)
{
ch++;
ADMUX=ch;
}
}
break;
}
case 2:
{
adc_result[2]=ADCW;
//Start next conversion
ADCSRA |= (1<<ADSC);
if(adc_result[2]>862)//checking for vge >265V
{
do
{
PORTD|=(1<<PD2);//glow the led corresponding to signal 3
//Start next conversion with same channel
_delay_ms(3);
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[0]=ADCW;
if(adc_result[2]>837) //checking for vge >270V
{
do
{
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[0]=ADCW;
PORTB|=(1<<PB1);// o/p drive if the state at adc2 exist for a particular time
}while (adc_result[2]<862);
}
}while(adc_result[2]<862);
PORTD|=(1<<PD2);//glow the led corresponding to signal 3
PORTB&=~(1<<PB1);// o/p drive off for ON the relay
}
else if(adc_result[2]<713)//checking for vge <230V
{
do
{
PORTD|=(1<<PD3);//glow the led corresponding to UV indication
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[0]=ADCW;
}while(adc_result[0]<713);
PORTD&=~(1<<PD3);//off the led corresponding to UV indication
}
else
{
if(ch<3)
{
ch++;
ADMUX=ch;
}
}
break;
}
// GLP
case 3:
{
adc_result[3]=ADCW;
ADMUX=0x04;//select adc 4
//Start next conversion
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[4]=ADCW;
if((adc_result[3]-adc_result[4])>31)
{
PORTD|=(1<<PD3);//ON the led corresponding to GLP indication
do
{
ADMUX=0x03;//select adc 3
//Start next conversion
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[3]=ADCW;
ADMUX=0x04;//select adc 4
//Start next conversion
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
adc_result[4]=ADCW;
if((adc_result[3]-adc_result[4])>38)
{
PORTB|=(1<<PB1);// o/p drive
}
}while((adc_result[3]-adc_result[4])>31);
PORTD&=~(1<<PD3);//OFF the led corresponding to GLP indication
PORTB&=~(1<<PB1);// off the o/p drive
}
}
}
int main(void)
{
port_init();
//discarding the first adc result
ADCSRA |= (1<<ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1<<ADIF)));
ADMUX=ch;
// Loop Forever
while(1)
{
init_adc();
}
}
|
|
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 10:28 AM |
|


Joined: Jul 18, 2005
Posts: 62299
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Oh how I love cross-posts! OP also sent this to me in a PM. This was my reply there:
I built your code and got:
Code:
../test.c:53: warning: 'ANA_COMP' appears to be a misspelled signal handler
../test.c: In function '__vector_14':
../test.c:291: warning: 'main' is normally a non-static function
../test.c:308: error: expected declaration or statement at end of input
The first will depend on which AVR you are building for but on the one I tried (mega16) the name for that ISR vector is ANA_COMP_vect so I guess you missed the "_vect" on the end?
The warning about main() being non-static is almost certainly because you have unbalanced parentheses above so the compiler thinks main() is being defined within the function above. This would also explain the final error.
In part you could do yourself a huge favour by learning to indent your code properly. Then it will become immediately obvious when the number of { does not match the number of } for a particular function as the indentation either won't get back to the left margin or it will with an additional }.
There is a utility in WinAVR called indent.exe that you can use to reformat your code. Just use "indent file.c" and it will update file.c to have correct indentation.
When I run it on your file I even get:
Code:
E:\avr>indent test.c
indent: test.c:309: Error:Unexpected end of file
which once again shows that the use of {} is wrong. What it wrote in the process (I used indent -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 test.c in fact) is:
Code:
#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <util/delay.h>
//system clock @1MHz
#define F_CPU 1000000
//Global variable
int adc_result[3] = { 0, 0, 0 }; //for storing the adc out put
uint8_t ch = 0;
/* PORT INIT */
void port_init(void)
{
//set portB.1 as output drive for relay
DDRB |= (1 << PB1);
PORTB &= ~(1 << PB1);
//set portC0-4 as input and enable the pull up resistor
DDRC &= ~((1 << PC0) | (1 << PC1) | (1 << PC2) | (1 << PC3) | (1 << PC4)); // ADC i/p R,B,Y & Gnd, neutral
PORTC |=
((1 << PC0) | (1 << PC1) | (1 << PC2) | (1 << PC3) | (1 << PC4));
//set up port D 0-3 as output
DDRD &= ~((1 << PD0) | (1 << PD1) | (1 << PD2) | (1 << PD3)); //o/p led for R,B,Y and GLP
}
void init_adc(void)
{
// Set ADC prescaler to 8 - 125KHz sample rate @ 1MHz
ADCSRA |= ((1 << ADPS1) | (1 << ADPS0));
// Enable ADC Interrupt
ADCSRA |= (1 << ADIE);
// Enable ADC
ADCSRA |= (1 << ADEN);
// Enable Global Interrupts
sei();
ADCSRA |= (1 << ADSC);
}
/* Interrupt service routine for Analog comparator*/
ISR(ANA_COMP)
{
}
/* Interrupt service routines */
ISR(ADC_vect)
{
//delay for discarding first conversion result
//_delay_ms(10);
//Read the adc result
switch (ch) {
case 0:
{
adc_result[0] = ADCW;
if (adc_result[0] > 823) //checking for vge >265V
{
do {
PORTD |= (1 << PD0); //glow the led corresponding to signal 1
_delay_ms(3);
//Start next conversion with same channel
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1 << ADIF))) ;
adc_result[0] = ADCW;
if (adc_result[0] > 837) //checking for vge >270V
{
do {
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!
(ADCSRA &
(1 << ADIF))) ;
adc_result[0] = ADCW;
PORTB |= (1 << PB1); // o/p drive ON if the state at adc0 exist for a particular time
}
while (adc_result[0] < 823); //do until the vge reduced to 265V
}
}
while (adc_result[0] > 823);
PORTD &= ~(1 << PD0); //off the led corresponding to signal 1
PORTB &= ~(1 << PB1); // o/p drive off for ON the relay
}
else if (adc_result[0] < 713) //checking for vge <230V
{
do {
PORTD |= (1 << PD3); //glow the led corresponding to UV indication
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1 << ADIF))) ;
adc_result[0] = ADCW;
}
while (adc_result[0] < 713); //do until vge >230V
PORTD &= ~(1 << PD3); //off the led corresponding to UV indication
} else {
if (ch < 3) {
ch++; //change adc channel
ADMUX = ch;
}
}
break;
}
case 1:
{
adc_result[1] = ADCW;
if (adc_result[1] > 823) //checking for vge >265V
{
do {
PORTD |= (1 << PD1); //glow the led corresponding to signal 2
//Start next conversion with same channel
_delay_ms(3);
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1 << ADIF))) ;
adc_result[0] = ADCW;
if (adc_result[0] > 837) //checking for vge >270V
{
do {
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!
(ADCSRA &
(1 << ADIF))) ;
adc_result[0] = ADCW;
PORTB |= (1 << PB1); // o/p drive if the state at adc1 exist for a particular time
}
while (adc_result[1] > 862);
}
}
while (adc_result[1] > 823);
PORTD |= (1 << PD1); //off the led corresponding to signal 2
PORTB &= ~(1 << PB1); // o/p drive off for ON the relay
} else if (adc_result[1] < 713) //checking for vge <230V
{
do {
PORTD |= (1 << PD3); //glow the led corresponding to UV indication
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1 << ADIF))) ;
adc_result[0] = ADCW;
}
while (adc_result[0] < 713); //do until vge >230V
PORTD &= ~(1 << PD3); //off the led corresponding to UV indication
} else {
if (ch < 3) {
ch++;
ADMUX = ch;
}
}
break;
}
case 2:
{
adc_result[2] = ADCW;
//Start next conversion
ADCSRA |= (1 << ADSC);
if (adc_result[2] > 862) //checking for vge >265V
{
do {
PORTD |= (1 << PD2); //glow the led corresponding to signal 3
//Start next conversion with same channel
_delay_ms(3);
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1 << ADIF))) ;
adc_result[0] = ADCW;
if (adc_result[2] > 837) //checking for vge >270V
{
do {
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!
(ADCSRA &
(1 << ADIF))) ;
adc_result[0] = ADCW;
PORTB |= (1 << PB1); // o/p drive if the state at adc2 exist for a particular time
}
while (adc_result[2] < 862);
}
}
while (adc_result[2] < 862);
PORTD |= (1 << PD2); //glow the led corresponding to signal 3
PORTB &= ~(1 << PB1); // o/p drive off for ON the relay
} else if (adc_result[2] < 713) //checking for vge <230V
{
do {
PORTD |= (1 << PD3); //glow the led corresponding to UV indication
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1 << ADIF))) ;
adc_result[0] = ADCW;
}
while (adc_result[0] < 713);
PORTD &= ~(1 << PD3); //off the led corresponding to UV indication
} else {
if (ch < 3) {
ch++;
ADMUX = ch;
}
}
break;
}
// GLP
case 3:
{
adc_result[3] = ADCW;
ADMUX = 0x04; //select adc 4
//Start next conversion
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1 << ADIF))) ;
adc_result[4] = ADCW;
if ((adc_result[3] - adc_result[4]) > 31) {
PORTD |= (1 << PD3); //ON the led corresponding to GLP indication
do {
ADMUX = 0x03; //select adc 3
//Start next conversion
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1 << ADIF))) ;
adc_result[3] = ADCW;
ADMUX = 0x04; //select adc 4
//Start next conversion
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1 << ADIF))) ;
adc_result[4] = ADCW;
if ((adc_result[3] - adc_result[4]) >
38) {
PORTB |= (1 << PB1); // o/p drive
}
}
while ((adc_result[3] - adc_result[4]) > 31);
PORTD &= ~(1 << PD3); //OFF the led corresponding to GLP indication
PORTB &= ~(1 << PB1); // off the o/p drive
}
}
}
int main(void) {
port_init();
//discarding the first adc result
ADCSRA |= (1 << ADSC);
//wait for coversion to be completed
while (!(ADCSRA & (1 << ADIF))) ;
ADMUX = ch;
// Loop Forever
while (1) {
init_adc();
}
}
As you can see - indentation has not returned to the right margin by the end.
Can I just say that this program shows very poor design. For one thing you should not be doing everything in an ISR() but for another you should never write code so complex that you run the risk of losing where the indentation level is in the first place! If a function is that complex then break it into several smaller functions. For example you have a large switch() in there - make each case: a separately called function. |
_________________
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 12:59 PM |
|


Joined: Mar 27, 2002
Posts: 18560
Location: Lund, Sweden
|
|
| OT:
Quote:
This was my reply there
How about as many of us a possible try to enforce a principle not to answer any questions in PMs if it could be discussed in open in a forum.
I have a standard answer that I just paste into a reply PM, which essentially says "In all friendliness: take it to the forums". |
|
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 01:48 PM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
clawson
i did as you told. but it again shows 2 error
Code:
#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define F_CPU 1000000 //system clock @1MHz
//Global variable
int adc_result[5]={0,0,0,0,0};//for storing the adc out put
uint8_t ch=0;
uint8_t y=0;
uint8_t i=0;
int k=0;
/* PORT INIT */
void port_init (void)
{
DDRB |=(1<<PB1);//set portB.1 as output drive for relay
PORTB&=~(1<<PB1);//initially set 0 as o/p drive
DDRB |=(1<<PB0)//error occur
//set portC0-4 as i/p with pull up resistor
DDRC &=~((1<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC3)|(1<<PC4));// ADC i/p R,B,Y & Gnd, neutral
PORTC |=((1<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC3)|(1<<PC4));
//set up port D 0-4 as output
DDRD &=~((1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD3)|(1<<PD4));//o/p led for R,B,Y and GLP
}
void init_adc(void)
{
ADCSRA |= ((1 << ADPS1) | (1 << ADPS0));// Set ADC prescaler to 8 - 125KHz sample rate @ 1MHz
ADCSRA |= (1 << ADEN); // Enable ADC
ADCSRA |= (1<<ADSC);//start conversion
}
void init_glp(void)
{
i=ch;
ADMUX=ch;
init_adc();
adc_result[i]=ADCW;
}
int main(void)
{
i=ch;
port_init();
ADMUX=ch;
init_adc();
ADCSRA |= (1<<ADSC);//discarding the first adc result
// Loop Forever
while(1)
{
ch=0;
init_adc();
if(ch<3)
{
for(ch=0;ch<3;ch++)
{
ADMUX=ch;
init_adc();
adc_result[i]=ADCW;
if (adc_result[i]>795)//checking for 265V
{
PORTD=y;
_delay_ms(1);
init_adc();
adc_result[i]=ADCW;
if(adc_result[i]>810)//checking for 270V
{
do
{
PORTB|=(1<<PB1); // o/p drive ON
init_adc();
_delay_ms(1);
adc_result[i]=ADCW;
}while(adc_result[i]>795);
PORTD=0x00;//off the indicator led
PORTB&=~(1<<PB1);// o/p drive off
}
}
else(adc_result[i]<690)//checking for 230V
{
do
{
PORTD|=(1<<PD3);// on the led corresponding to UV indication
init_adc();
adc_result[i]=ADCW;
}while(adc_result[i]<690);//checking for 230V
}
y++;
}
y=0;
}
else if((2<ch)&&(ch<5))
{
ch=3;
init_glp();
ch++;
init_glp();
k=(adc_result[4]-adc_result[3]);
if(k>30)//checking for 230V
{
PORTD|=(1<<PD4);//ON the led corresponding to GLP indication
_delay_ms(1);
ch=3;
init_glp();
ch++;
init_glp();
k=(adc_result[4]-adc_result[3]);
if(k>45)//checking for 15V difference
{
do
{
PORTB|=(1<<PB1); // o/p drive ON
ch=3;
init_glp();
ch++;
init_glp();
k=(adc_result[4]-adc_result[3]);
}while(k>30);//checking for 15V difference
PORTB&=~(1<<PB1);// o/p drive off
PORTD&=~(1<<PD4);//OFF the led corresponding to GLP indication
}
}
}
else
{
PORTB|=(1<<PB0);
}
}
}
|
|
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 02:25 PM |
|


Joined: Mar 27, 2002
Posts: 18560
Location: Lund, Sweden
|
|
|
Quote:
i did as you told. but it again shows 2 error
WHAT errors?!
Please copy the error messages verbatim from your build output window, and paste them here. |
|
|
| |
|
|
|
|
|
Posted: Jun 20, 2012 - 03:05 PM |
|

Joined: Jun 04, 2012
Posts: 295
Location: Mumbai,India
|
|
rm -rf technic_protector.o technic_protector.elf dep/* technic_protector.hex technic_protector.eep technic_protector.lss technic_protector.map
rm: cannot lstat `dep/*': Invalid argument
make: [clean] Error 1 (ignored)
Build succeeded with 0 Warnings...
avr-gcc -mmcu=atmega168 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT technic_protector.o -MF dep/technic_protector.o.d -c ../technic_protector.c
In file included from ../technic_protector.c:14:0:
c:\program files\atmel\avr tools\avr toolchain\bin\../lib/gcc/avr/4.5.1/../../../../avr/include/util/delay.h:89:3: warning: #warning "F_CPU not defined for <util/delay.h>"
../technic_protector.c:16:0: warning: "F_CPU" redefined
c:\program files\atmel\avr tools\avr toolchain\bin\../lib/gcc/avr/4.5.1/../../../../avr/include/util/delay.h:90:0: note: this is the location of the previous definition
../technic_protector.c: In function 'port_init':
../technic_protector.c:33:1: error: called object '1' is not a function
../technic_protector.c: In function 'main':
../technic_protector.c:96:11: warning: statement with no effect
../technic_protector.c:97:7: error: expected ';' before '{' token
make: *** [technic_protector.o] Error 1
Build failed with 2 errors and 3 warnings... |
|
|
| |
|
|
|
|
|