Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AVR Gcc error Attiny13 - float value return to Uint16 - Error

Status
Not open for further replies.

thannara123

Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,576
Helped
122
Reputation
244
Reaction score
114
Trophy points
1,353
Location
India
Activity points
10,346
I am making a simple project with Attiny13
Trying to read ADC value while making program am getting Error as follows

Error 1 in extract_insn, at recog.c:2109
Error 2 unrecognizable insn:


It shows whenever i return the Unint16 value from a float value Pleas see the program .
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 9600000




void adc_init()
{
	ADMUX=0x00; // VCC used as voltage referance
	ADMUX |= (1 << MUX0); //// Set the ADC input to PB2/ADC1
	ADCSRA |= (1 << ADPS1) | (1 << ADPS0) | (1 << ADEN);//Set the prescaler to clock/128 & enable ADC
}	


unsigned int read_adc()
{   unsigned int LSB_data=0,MSB_data =0, adc_value=0;
	ADMUX |= (1 << MUX0);	
	ADCSRA|=(1<<ADSC); // start conversion
	while(ADCSRA & (1<<ADSC));
	LSB_data = ADCL ;
	MSB_data = ADCH ;
	adc_value = ((unsigned int)MSB_data<<8);
	adc_value = adc_value |((unsigned int)LSB_data);
	return (adc_value);
}


int test()
 {
 int i,adc_value[100]={0}; uint16_t temp =0;
 
 adc_init();
 
 for(i=0; i<100;i++)              // samples taking from 41 times 9.4milli second taken about on complte half cycle
 {
	 adc_value[i] = read_adc();  // reading voltage
 }
 
 temp = adc_value[0];
 
 for(i=0; i<100; i++)
 {
	 if(temp<adc_value[i])
	temp=  adc_value[i];
 }
// temp =100;
 
return (temp);//*(0.639)); //o making Peak to RMS
 }




int main(void)
{  
	 uint16_t adc_value1=0;
	
	adc_value1 = test();
    
	while(1)
    { 
		
        //TODO:: Please write your application code 
    }
   }

<avr io.h=""><avr interrupt.h=""><adsc); start="" conversion
<adsc));
<adc_value[i])

The error will goes when i will give a random value to the variable temp just before the return in the test function.</adc_value)
</adsc));
</adsc);></avr></avr>
 
Last edited:

i posted the program but it shows a part only ?:oops:



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <avr io.h="">
#include <avr interrupt.h="">
#define F_CPU 9600000
 
void adc_init()
{
    ADMUX=0x00; // VCC used as voltage referance
    ADMUX |= (1 << MUX0); //// Set the ADC input to PB2/ADC1
    ADCSRA |= (1 << ADPS1) | (1 << ADPS0) | (1 << ADEN);//Set the prescaler to clock/128 & enable ADC
}    
 
unsigned int read_adc()
{   unsigned int LSB_data=0,MSB_data =0, adc_value=0;
    ADMUX |= (1 << MUX0);    
    ADCSRA|=(1<<adsc); start="" conversion
      while(ADCSRA & (1<<adsc));
    LSB_data = ADCL ;
    MSB_data = ADCH ;
    adc_value = ((unsigned int)MSB_data<<8);
    adc_value = adc_value |((unsigned int)LSB_data);
    return (adc_value);
}
 
int test()
 {
 int i,adc_value[100]={0}; uint16_t temp =0;
 
 adc_init();
 
 for(i=0; i<100;i++)              // samples taking from 41 times 9.4milli second taken about on complte half cycle
 {
     adc_value[i] = read_adc();  // reading voltage
 }
 
 temp = adc_value[0];
 
 for(i=0; i<100; i++)
 {
     if(temp<adc_value[i])
    temp=  adc_value[i];
 }
// temp =100;
 
return (temp);//*(0.639)); //o making Peak to RMS
 }
 
 
int main(void)
{  
     uint16_t adc_value1=0;
    
    adc_value1 = test();
    
    while(1)
    { 
        
        //TODO:: Please write your application code 
    }
   }



It doesnt appear in CODE blocks
Code:
< /adc_value[i])
< /adsc));
< /adsc);>< /avr>< /avr>
 
Last edited by a moderator:

Where's error line recog.c:2109? I guess not in the posted code.
 

Where's error line recog.c:2109? I guess not in the posted code.

Capture.JPG
sir above posted the full code .
 

We still can't see the full code and the image in post #5 is not part of the code previously shown.

I'm not sure what IDE you are using but to subtract 307 from an ADC result could produce a negative result and then multiplying it by a fraction may lose it altogether. Bear in mind you seem to be casting the result as an unsigned integer. I suspect you have mixed up the data types somewhere but without the full code it's difficult to see where.

Brian.
 

Post #3 has the full code
Sir, i am not completed the full code in main function .
The error came out while i complete these functions which is shown in psot #3.
me also think that " you said the data type problem ".But the same program i used and worked out in Atmega8
I am using atmel Studio (AVR gcc)

I put the whole code i Have written no Hidden program
Even if changed the code as shown below
Code:
return  temp;//( uint16_t)(temp-307)*.660;
But the same error persist .

is there any effect computer virus on compiler ?
 
Last edited:

Atmel studio doesn't work in Linux so I can't check it myself but you still have some suspicious type conversions.

For example: "read_adc()" returns an unsigned integer value but you then use "adc_value = read_adc();" where the adc_value[] array holds signed integer values. The compiler probably does promotion/demotion automatically but you could lose accuracy.

Another example: "test()" returns a signed integer result but you then use "adc_value1 = test();" where adc_value1 is an unsigned integer.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top