+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Advanced Member level 4
    Points: 12,456, Level: 26
    Achievements:
    Created Blog entry 7 years registered
    thannara123's Avatar
    Join Date
    Jan 2010
    Location
    Nedumkandam, India, India
    Posts
    1,428
    Helped
    118 / 118
    Points
    12,456
    Level
    26
    Blog Entries
    2

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

    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 
    #include 
    #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<
    
    The error will goes when i will give a random value to the variable temp just before the return in the test function.
    Last edited by thannara123; 7th July 2018 at 16:56.
    I Respect You

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 79,232, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,979
    Helped
    4332 / 4332
    Points
    79,232
    Level
    68

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

    Half a program tells us nothing.....

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  3. #3
    Advanced Member level 4
    Points: 12,456, Level: 26
    Achievements:
    Created Blog entry 7 years registered
    thannara123's Avatar
    Join Date
    Jan 2010
    Location
    Nedumkandam, India, India
    Posts
    1,428
    Helped
    118 / 118
    Points
    12,456
    Level
    26
    Blog Entries
    2

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

    i posted the program but it shows a part only ?


    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 andre_teprom; 7th July 2018 at 19:55. Reason: added syntax tags
    I Respect You



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 256,166, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    44,687
    Helped
    13593 / 13593
    Points
    256,166
    Level
    100

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

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



  5. #5
    Advanced Member level 4
    Points: 12,456, Level: 26
    Achievements:
    Created Blog entry 7 years registered
    thannara123's Avatar
    Join Date
    Jan 2010
    Location
    Nedumkandam, India, India
    Posts
    1,428
    Helped
    118 / 118
    Points
    12,456
    Level
    26
    Blog Entries
    2

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

    Quote Originally Posted by FvM View Post
    Where's error line recog.c:2109? I guess not in the posted code.
    Click image for larger version. 

Name:	Capture.JPG 
Views:	4 
Size:	80.1 KB 
ID:	147758
    sir above posted the full code .
    I Respect You



    •   AltAdvertisement

        
       

  6. #6
    Super Moderator
    Points: 79,232, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,979
    Helped
    4332 / 4332
    Points
    79,232
    Level
    68

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

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  7. #7
    Advanced Member level 4
    Points: 12,456, Level: 26
    Achievements:
    Created Blog entry 7 years registered
    thannara123's Avatar
    Join Date
    Jan 2010
    Location
    Nedumkandam, India, India
    Posts
    1,428
    Helped
    118 / 118
    Points
    12,456
    Level
    26
    Blog Entries
    2

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

    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 by thannara123; 8th July 2018 at 09:49.
    I Respect You



  8. #8
    Super Moderator
    Points: 79,232, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,979
    Helped
    4332 / 4332
    Points
    79,232
    Level
    68

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

    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[i] = 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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



--[[ ]]--