Author Topic: Atmel Studio compiler errors  (Read 13778 times)

0 Members and 1 Guest are viewing this topic.

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: Atmel Studio compiler errors
« Reply #25 on: August 31, 2014, 10:01:58 pm »
And some c++ compilers don't like not to have an empty line at the end of the file.

Edit: Which make perfect sense to be required.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Atmel Studio compiler errors
« Reply #26 on: August 31, 2014, 10:38:39 pm »
Quote
So basically i need to do a clean build each time to make sure ?
Probably not.

Look.  avr-gcc and Atmel Studio have bugs; they're huge programs.
But the chances that they have catastrophic bugs that cause a program to not compile one time, and compile the next, or similar are VERY slim.  It's MUCH more likely that it's YOU.

Quote
The code previously worked, I commented some of it out and then removed the comments and now I get errors relating to code in the watchdog header file which is out of my control, I think that's unusual is it not ?
No, unfortunately.  If you leave some stray characters behind during the removal, it's quite possible that those will cause error messages "in" the system include files.  For a good time, try running the following through any desktop compiler:
Code: [Select]
char *bar(int, int)     // Function prototype
#include <stdio.h>   // get standard IO code.
C seems to be really, horribly, awful when it come to figuring out the source of parsing errors.  That's probably a result of it having its syntax designed back in the dark ages before language designers understood the importance of ... pickyness.  And in between "clever" programmers and purist compiler designers, it somehow seems necessary to output 100+ lines of errors about stable system include files, rather than saying "Did you really mean to use a #include in the middle of a C statement?"

(This is one of the reasons that there used to be "teaching compilers" like WATFor and PL/C.  They would do a much better job of indicating, and continuing, in the face of common sytax errors than their "professional" equivalents.   I don't know if there's a "teaching" C compiler.  I guess some of that lack is being taken up by the IDE.  Keil puts a big read X next to that prototype, but Atmel Studio isn't as helpful...)
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Atmel Studio compiler errors
« Reply #27 on: September 01, 2014, 05:06:44 am »
For a good time, try running the following through any desktop compiler:
Code: [Select]
$ clang -c a.c
a.c:1:20: error: expected ';' after top level declarator
char *bar(int, int)
                   ^
                   ;
1 error generated.
$
GCC has improved its diagnostics a lot in recent versions (largely a response to Clang), but they've got some ways to go yet.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Atmel Studio compiler errors
« Reply #28 on: September 01, 2014, 07:03:11 am »
Code is:

Code: [Select]
#define F_CPU 8000000UL

#include <avr/io.h>
#include "simon_atmega328_avr_c.h"
#include "tacho.h"
#include <avr/wdt.h>
#include <avr/interrupt.h>

#define speed0 950 //PCM value for a stopped motor
#define speed1 50 //timing value for speed1
#define speed2 33 //timing value for speed2
#define PCM_VALUE OCR1A // OCR1A holds the PWM duty value for the PCM output

#define PCM PB1
#define S1_o PB2
#define S2_o PD4
#define Fault_o PB5

#define S1_i PB6
#define S2_i PB7
#define Fault_i PB4
#define scavenge PD1


#define bounce 100 //time in ms to wait for switch de-bounce

int main(void)
{
uint16_t pwm1 = 1500; //starting PCM value for speed1
uint16_t pwm2 = 1800; //starting PCM value for speed2

sei(); //globally enable interrupts
bit_s(DDRB, PB0); //set output for startup test signal
bit_s (PORTB, PB0); //turn on test pin
_delay_ms(1000); //wait 1000ms to get a pulse that is easy to detect
bit_c(PORTB, PB0); //turn test pin off

wdt_enable(WDTO_2S); //enable watchdog timer with a 2S timeout

bit_s(DDRB, PCM); //PCM output
bit_s(DDRB, S1_o); //speed1 output
bit_s(DDRD, S2_o); //speed2 output
bit_s(DDRB, Fault_o); //fault output
bit_s(DDRD, scavenge); //scavenge output

bit_s(PORTB, S1_i); //enable pull-up for S1_i
bit_s(PORTB, S2_i); //enable pull-up for S2_i

bit_s(PORTB, Fault_i); //enable pull-up for fault in

bit_s(EICRA, ISC01); //set interrupt0 to fire on a falling edge
bit_c(EICRA, ISC00);

counter0_CTC(50);

bit_s(EIMSK, INT0); //enable external interrupt 0

pwm16_fast_setup();

PCM_VALUE = speed0;

wdt_reset ( );

while(1)
    {
        wdt_reset ( );

time_calc();

        //if both speed inputs are high set PWM at 1000 (1.5mS pulse) reversed logic with mcu pull-up's
        if ( (bit_get (PINB, S2_i)) && (bit_get (PINB, S1_i)) )
        {
        delay_ms(bounce); //wait for switch bounce
        if ( (bit_get (PINB, S2_i)) && (bit_get (PINB, S1_i)) ) //recheck state
        {
        PCM_VALUE = speed0 ;
        bit_c (PORTB, S1_o) ;
        bit_c (PORTD, S2_o) ;
bit_c (PORTD, scavenge); // Turn off scavenge fan
        }
        }

        //Set speed 1
//if speed 1 low AND speed 2 high set speed1 pulse reversed logic with mcu pull-up's
if ( (bit_get (PINB, S2_i)) && (!bit_get (PINB, S1_i)) )
{
_delay_ms(bounce); //wait for switch bounce
if ( (bit_get (PINB, S2_i)) && (!bit_get (PINB, S1_i)) ) //recheck state
{
bit_s (PORTB, S1_o) ;
bit_c (PORTD, S2_o) ;

if (time > speed1)
pwm1++;

if (time < speed1)
pwm1--;

PCM_VALUE = pwm1;
bit_s (PORTD, scavenge); //Turn on Scavenge fan
}
}

//Set speed 2
//if speed 2 low AND speed 1 high set speed2 pulse reversed logic with mcu input pull-up's
if ( (!bit_get (PINB, S2_i)) && (bit_get (PINB, S1_i)) )
{
_delay_ms(bounce); //wait for switch bounce
if ( (!bit_get (PINB, S2_i)) && (bit_get (PINB, S1_i)) ) //recheck state
{
bit_c (PORTB, S1_o) ;
bit_s (PORTD, S2_o) ;

if (time > speed2)
pwm2++;

if (time < speed2)
pwm2--;

PCM_VALUE = pwm2;
bit_s (PORTD, scavenge); //Turn on Scavenge fan
}
}
        //fault signal
        //if the fault input is 1 then turn on fault output else turn it off
if (bit_get (PINB, Fault_i))
bit_s(PORTB, Fault_o);
else
bit_c(PORTB, Fault_o);
       
    }
}
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Atmel Studio compiler errors
« Reply #29 on: September 01, 2014, 07:08:04 am »
I'm really curious to know why pwm1 and pwm2 are giving me warnings about the variables not changing, last time i checked pwm1++ or pwm1-- is a change.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Atmel Studio compiler errors
« Reply #30 on: September 01, 2014, 08:20:52 am »
Where is "time" defined ?
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Atmel Studio compiler errors
« Reply #31 on: September 01, 2014, 08:48:54 am »
tacho.h

Code: [Select]

volatile uint16_t tacho1, tacho2, time, count; //reading pulled off counter1

ISR(INT0_vect)
{
tacho1 = tacho2;
tacho2 = count;
}

ISR(TIMER0_COMPA_vect)
{
count++;
}

void counter0_CTC (uint8_t TOP)
{
//setup counter for CTC mode
bit_c(TCCR0B, WGM02);
bit_s(TCCR0A, WGM01);
bit_c(TCCR0A, WGM00);

//set div8 prescaler (counts in uS on a 8MHz clock)
bit_c(TCCR0B, CS02);
bit_s(TCCR0B, CS01);
bit_c(TCCR0B, CS00);

OCR0A = TOP; //set the compare match value to the one specified in the function argument.

bit_s(TIMSK0, OCIE0A); //enable channel A compare/match interrupt flag.
}

void time_calc (void)
{
bit_c(EIMSK, INT0); //disable external interrupt 0 to stop false readings

if (tacho1 > tacho2)
tacho2 = tacho2 + 0xFFFF;

time = tacho2 - tacho1;

bit_s(EIMSK, INT0); //re-enable external interrupt 0
}
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Atmel Studio compiler errors
« Reply #32 on: September 01, 2014, 09:25:00 am »
Can you copy and paste the actual output from the compiler?  I'm seeing:
Code: [Select]
avr-gcc -Os -mmcu=atmega328p avrbar.c -Wall
In file included from avrbar.c:5:0:
tacho.h:5:1: warning: return type defaults to 'int' [-Wreturn-type]
 ISR(INT0_vect)
 ^
tacho.h:11:1: warning: return type defaults to 'int' [-Wreturn-type]
 ISR(TIMER0_COMPA_vect)
 ^
tacho.h:11:1: error: redefinition of 'ISR'
tacho.h:5:1: note: previous definition of 'ISR' was here
 ISR(INT0_vect)
 ^
tacho.h: In function 'ISR':
tacho.h:14:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
caused by not including interrupt.h before you try to use ISR.

But apparently you're seeing additional/different errors and warnings?
 

Offline firewalker

  • Super Contributor
  • ***
  • Posts: 2450
  • Country: gr
Re: Atmel Studio compiler errors
« Reply #33 on: September 01, 2014, 09:31:38 am »
Enter

#include <avr/interrupt.h>

to tacho.h

Edit: Should refresh before posting.  ;D ;D ;D

Alexander.
« Last Edit: September 01, 2014, 09:39:54 am by firewalker »
Become a realist, stay a dreamer.

 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Atmel Studio compiler errors
« Reply #34 on: September 01, 2014, 09:32:53 am »
@westfw

I've run so many versions that I've lost track, according to avr freaks I should have included the interrupts header file in my tacho header file. At the moment it builds ok.

I may also be having problems because I've not been doing clean builds and as I've had copies of the project it might be that different versions of a file have been accidentally used.

 

Offline mamalala

  • Supporter
  • ****
  • Posts: 777
  • Country: de
Re: Atmel Studio compiler errors
« Reply #35 on: September 01, 2014, 12:09:21 pm »
tacho.h

Code: [Select]

volatile uint16_t tacho1, tacho2, time, count; //reading pulled off counter1

ISR(INT0_vect)
{
tacho1 = tacho2;
tacho2 = count;
}

ISR(TIMER0_COMPA_vect)
{
count++;
}

void counter0_CTC (uint8_t TOP)
{
//setup counter for CTC mode
bit_c(TCCR0B, WGM02);
bit_s(TCCR0A, WGM01);
bit_c(TCCR0A, WGM00);

//set div8 prescaler (counts in uS on a 8MHz clock)
bit_c(TCCR0B, CS02);
bit_s(TCCR0B, CS01);
bit_c(TCCR0B, CS00);

OCR0A = TOP; //set the compare match value to the one specified in the function argument.

bit_s(TIMSK0, OCIE0A); //enable channel A compare/match interrupt flag.
}

void time_calc (void)
{
bit_c(EIMSK, INT0); //disable external interrupt 0 to stop false readings

if (tacho1 > tacho2)
tacho2 = tacho2 + 0xFFFF;

time = tacho2 - tacho1;

bit_s(EIMSK, INT0); //re-enable external interrupt 0
}

If that really is a .h file, then you are doing it wrong. Regular code should not be in there, and neither should variable declarations.

Greetings,

Chris

Edit: Oh, and stuff like "tacho2 = tacho2 + 0xFFFF;" can also be written as "tacho2--;", because that is what it will effectively do in this case.
« Last Edit: September 01, 2014, 12:12:28 pm by mamalala »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Atmel Studio compiler errors
« Reply #36 on: September 03, 2014, 07:00:40 am »
It would seem that I made a mess of splitting my code into different files, I don't know where I got the idea from but yes apparently header files is not the place.

I've now split my files into C files and added them to the project and it all works.
« Last Edit: September 03, 2014, 09:13:44 am by Simon »
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Atmel Studio compiler errors
« Reply #37 on: September 03, 2014, 09:01:14 am »
Using various h and c files is not a bad thing if done correctly.  You can reuse those modules on other projects.

It took me a while to get the hang of variable declarations, definitions, the use of the extern keyword, etc.

Get that wrong and it all becomes a steaming pile with endless warnings, errors and unexpected results.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17815
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: Atmel Studio compiler errors
« Reply #38 on: September 03, 2014, 09:14:21 am »
Yes I think I have the hang of it now....
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf