TINY 10 internal interrup , help

Go To Last Post
41 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HI ,

I hope someone can help me , i have been trying out AVR6.1 with ATtiny10 . I am trying to create a interupt route to be triggered on timer0 , comparing the value in the one register to what the counter register has . if equal interrupt and go to ISR routine.

I have been going over the very simple code to test this but in AVR6.1 the compiler tells me operhand out of range.

I double checked if the code is ok and the right chip is selected.

Could someone have alook and perhaps point out my mistake , i am sure its something over looked but i am not sure what.

/*
* tiny10_wd001.c
*/
#define F_CPU 1000000UL

#include
#include

int main(void)
{
char timer1=0x000,timer2=0x000,timer3=0x000,timer4=0x000;
char timer1b=0x000,timer2b=0x000,timer3b=0x000,timer4b=0x000;

CLKMSR=0x00;//8mhz clock setup

//DDRB = 0x0f; //direction of pin IO, 1= output , 0= input

cli();
TIFR0 |= 0x01; // clear interrupt flag

OCR0AH = 0x00;
OCR0AL = 0x70; // number to count up to (0x70 = 112)

//TCCR0A &= ~(0 << WGM00); // Configure timer 0 for CTC mode
//TCCR0A &= ~(1 << WGM01); // Configure timer 0 for CTC mode
TCCR0A = 0x00; // Configure timer 0 for CTC mode

//TCCR0B |= (3 << WGM02); // Configure timer 0 for CTC mode
//TCCR0B &= ~( 4<< WGM03); // Configure timer 0 for CTC mode

//TCCR0B |= (0<<CS00); // clock source CLK/1024, start timer
//TCCR0B |= (1<<CS02); // clock source CLK/1024, start timer
TCCR0B = 0x0d; // clock source CLK/1024, start timer, dec 12, b00001100

TIMSK0 = 0x01; // TC0 compare match A interrupt enable
sei(); // global interrupt enable

while(1)
{

//PORTB |= (1<<PORTB2);

timer3b=0x00;

for(timer3=0;timer3<10;timer3++)
{
for(timer1=0;timer1<100;timer1++)
{

for(timer2=0;timer2<32;timer2++)
{
timer3b++;
}
}
}

//PORTB &= ~(1<<PORTB2);

timer4b=0x00;

for(timer4=0;timer4<10;timer4++)
{
for(timer1=0;timer1<100;timer1++)
{

for(timer2=0;timer2<32;timer2++)
{
timer4b++;
}
}
}

}

return 0;
}

ISR(TIM0_COMPA_vect)
{

PORTB ^= (1<<PORTB2);

}

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tidy up your code. e.g. remove extraneous comments, use BIT_NAMEs, indent consistently.

Then edit your post to contain the tidied code. Select with mouse. Press [CODE] button.

Hint. Any pointless loops will be optimised away. Declare a variable as volatile if you want each line executed.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


/*
* tiny10_wd001.c
*/

#include <avr/io.h>
#include <avr/interrupt.h>

int main(void)
{
CLKMSR=0x00;//8mhz clock setup

DDRB = 0x0f; //direction of pin IO, 1= output , 0= input

cli();
TIFR0 |= 0x01; // clear interrupt flag

OCR0AH = 0x00;
OCR0AL = 0x70; // number to count up to (0x70 = 112)
TCCR0A = 0x00; // Configure timer 0 for CTC mode,WGM01=0 ,WGM00=0

TCCR0B = 0x0d; // clock source CLK/1024, start timer,WGM03=0,WGM02=1,CS02=1, dec 12, b00001100

TIMSK0 = 0x01; // OCIE0A=1,TC0 compare match A interrupt enable
sei(); // global interrupt enable

while(1)
{
;
}

return 0;
}

ISR(TIM0_COMPA_vect)
{

PORTB ^= (1<<PORTB2);

}

$ Added code tag at end of code - JS $

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is what I meant my tidy code with CODE tahs.


/*
* tiny10_wd001.c
*/

#include <avr/io.h>
#include <avr/interrupt.h>

int main(void)
{
CLKMSR = 0x00; //8mhz clock setup

DDRB = 0x0f; //direction of pin IO, 1= output , 0= input

cli();
TIFR0 = (1<<OCF0A); // clear interrupt flag with =

OCR0AH = 0x00;
OCR0AL = 0x70; // number to count up to (0x70 = 112)
TCCR0A = 0x00; // not using OC0x pins
TCCR0B = (1<<WGM02)|(5<<CS00); // CTC, div1024

TIMSK0 |= (1<<OCIE0A) //compare match A interrupt enable
sei(); // global interrupt enable

while (1) {
;
}

return 0;
}

ISR(TIM0_COMPA_vect)
{

PORTB ^= (1<<PORTB2);

}

Now go and look up the values and descriptions of those BIT_NAMEs. And spot where you went wrong.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David,

Thanks for this, I noticed three problems in the code . My interrupt flag was incorrectly cleared, the TCCR0B register was setup to CTC and DIV 256, and the TIMSK0 was incorrectly enabled .

Having gone through the registers description in the DATA sheet. I am still getting the following.

"operand out of range: 0x3f"
I have been through the DS for the most of the day, any other area you can point me into to look at?

regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you will find that the bitposition of OCIE0A is 1 and hence bitmask value is (1<<1) i.e. 2

Which line does your error refer to?

I have not built the code that I posted. I simply formatted then hand-edited.

Which IDE or GCC version are you using. AFIK, early GCC could not compile tiny10 properly.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David,

I am using ATMEL AVR studio 6.1,

Atmel Toolchain\AVR8 GCC\Native\3.4.1051\avr8-gnu-toolchain\bin\avr-gcc.exe

When it tries to compile the code , it generate a random *.S file , which i believe to be ASM version. but trying to locate it in the temp area is useless . As soon as its done compiling the file get deleted , by the studio.

As you see it tells me the line and coulomb.

C:\DOCUME~1\COETZE~1\LOCALS~1\Temp\ccDRq9hn.s(26,1): operand out of range: 0x3f

If i leave everything the same with the changes we discussed and only remove the actual ISR function , it compiles without a problem.

it seems not to be unable to link up with the ISR routine.

Regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I built the project in AS6.2

I had a missing semi-colon on the TIMSK0 line.

It simulated just fine. PORTB.0 toggles every 115ms if the chip is running at the default 1MHz.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David,

Thanks for the assistance, the code as you say is simulating correct. Even though i am getting the error.

So i loaded the code on the device and it is running although the compiler is telling me the error is still there.

I am wondering what the error is about, I have contacted a friend at ATMEL to look at the code to and perhaps give me some feedback what that is.

Thanks for all the assistance so late at night appreciate it.
regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
When it tries to compile the code , it generate a random *.S file , which i believe to be ASM version. but trying to locate it in the temp area is useless . As soon as its done compiling the file get deleted , by the studio.
Then you have not discovered -save-temps yet?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would not f*rt about with --save-temps.
Just add the semi-colon to the TIMSK0 line. Build a and run/simulate.

If you get an Error, say so. I have posted neat code for you. Simply say where it goes wrong for you.

If someone goes to the effort of tidying and building your project, it is only reasonable to paste your error line(s).

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David ,

There is no need to get angry, in order for me to post the lines where the error is i first need to understand what causes the error.

Your assistance is and was brilliant. I am not saying you did anything wrong, i am merely stating there is something wrong and i can't point to the problem clean code or not.

I believe it is in the build process which is above our control well at least mine.

As i said i can't stipulate where the code is as the only place where i could get any clue to the error is in the S file which is a temp file. from the system.

Hence my reason for contacting ATMEL direct, forums like these assist a great many people all level from beginner to pro.

We need to accept that not everyone is equally clued up as most and that some code may look dirty because it was not intended as release code but experimental.

Sorry the code was so untidy but it was a simple code which i did not expected to create such a problem.

Regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok so what happened when you used -save-temps. The .s file the C compiler generated would now be in the build directory. What did the line that gave "operand out of range" actually say? It seems very unusual for the C compiler to generate code where the values in an opcode might be out of range.

Can you also post a copy of EXACTLY the source code you are using when you see this "operand out of range" error? This thread is very confused and it's not clear what code you are using when you see this (if it has even been posted here).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David,

The compiler does not leave any S file behind , not even in the build directory. Which makes this a very hard problem for me. When double clicking on the on the error message you would expect the compiler to take you to the line where the problem would be but it does not.

The decription is :
operhand out of range : 0x3f

File: ccgU2Hle.s

Line: 271 & 463

coloumb: 1

The compiler out put window is as follows:

------ Build started: Project: tiny10_wd001, Configuration: Debug AVR ------
Build started.
Project "tiny10_wd001.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files\Atmel\Atmel Studio 6.1\Vs\Compiler.targets" from project "C:\Documents and Settings\coetzeec2380\My Documents\fw\AVR\tiny10_wd001\tiny10_wd001\tiny10_wd001.cproj" (target "Build" depends on it):
Task "RunCompilerTask"
C:\Program Files\Atmel\Atmel Studio 6.1\shellUtils\make.exe all
Building file: .././tiny10_wd001.c
Invoking: AVR/GNU C Compiler : 3.4.4
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1051\avr8-gnu-toolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -DDEBUG -O0 -g2 -Wall -mmcu=attiny10 -c -std=gnu99 -MD -MP -MF "tiny10_wd001.d" -MT"tiny10_wd001.d" -MT"tiny10_wd001.o" -o "tiny10_wd001.o" ".././tiny10_wd001.c"
C:\DOCUME~1\COETZE~1\LOCALS~1\Temp\ccgU2Hle.s: Assembler messages:
C:\DOCUME~1\COETZE~1\LOCALS~1\Temp\ccgU2Hle.s(271,1): operand out of range: 0x3f
C:\DOCUME~1\COETZE~1\LOCALS~1\Temp\ccgU2Hle.s(463,1): operand out of range: 0x3f
Finished building: .././tiny10_wd001.c
Building target: tiny10_wd001.elf
Invoking: AVR/GNU Linker : 3.4.4
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1051\avr8-gnu-toolchain\bin\avr-gcc.exe" -o tiny10_wd001.elf tiny10_wd001.o -Wl,-Map="tiny10_wd001.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -mmcu=attiny10
Finished building target: tiny10_wd001.elf
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1051\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature "tiny10_wd001.elf" "tiny10_wd001.hex"
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1051\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "tiny10_wd001.elf" "tiny10_wd001.eep" || exit 0
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1051\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "tiny10_wd001.elf" > "tiny10_wd001.lss"
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1051\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature "tiny10_wd001.elf" "tiny10_wd001.srec"
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1051\avr8-gnu-toolchain\bin\avr-size.exe" "tiny10_wd001.elf"
text data bss dec hex filename
834 0 4 838 346 tiny10_wd001.elf
Done executing task "RunCompilerTask".
Task "RunOutputFileVerifyTask"
Program Memory Usage : 834 bytes 81.4 % Full
Data Memory Usage : 4 bytes 12.5 % Full
Done executing task "RunOutputFileVerifyTask".
Done building target "CoreBuild" in project "tiny10_wd001.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "Build" in file "C:\Program Files\Atmel\Atmel Studio 6.1\Vs\Avr.common.targets" from project "C:\Documents and Settings\coetzeec2380\My Documents\fw\AVR\tiny10_wd001\tiny10_wd001\tiny10_wd001.cproj" (entry point):
Done building target "Build" in project "tiny10_wd001.cproj".
Done building project "tiny10_wd001.cproj".

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========


/*
* tiny10_wd001.c
*
* Created: 4/4/2014 8:14:32 PM

*/

#include <avr/io.h>
#include <avr/interrupt.h>

#define RLY PORTB2

void delay_ms(unsigned int v1);

static char intval=0x00;
char sec_cnt=0x00;
char min_cnt=0x00;
char hour_cnt=0x00;

int main(void)
{

char port_temp=0x00;

CLKMSR=0x00; //clock setup

cli();
TIFR0 = (1<<OCF0A)|(1<<TOV0); // clear interrupt flag with =

TCCR0A = 0x00; // not using OCOx pins

TCCR0B = (1<<WGM02)|(1<<CS02)|(1<<CS00); // CTC, div1024

OCR0AH = 0x00;
OCR0AL = 0x61; // number to count up to (0x61 = 97) +-100ms @ 1Mhz

TIMSK0 |= (1<<OCIE0A); //compare match A interrupt enable
sei(); // global interrupt enable

DDRB = 0x04; //direction of pin IO, 1= output , 0= input, b0100

while(1)
{

port_temp=PINB; //reading all pins into the temp register
port_temp=port_temp & 0x03; // masking out the PIN_B0 and PIN_B1

if(0x01==port_temp)
{
PORTB &= ~(1<<PORTB2); //deactivate relay NC
if (sec_cnt==10) //see if timer reached 10sec
{

cli(); // disable global interrupts

sec_cnt=0x00;
min_cnt=0x00;
hour_cnt=0x00;

PORTB |= (1<<PORTB2); //activate relay NC
delay_ms(5000);
PORTB &= ~(1<<PORTB2); //deactivate relay NC

TIFR0 = (1<<OCF0A)|(1<<TOV0); // clear interrupt flags
sei(); // enable global interrupts
}
}

}

return 0;
}

//========================================================= Interrupt routines

ISR(TIM0_COMPA_vect)
{

cli();
TIFR0 = (1<<OCF0A)|(1<<TOV0); // clear interrupt flags

if(intval==10) // 1second loop
{

intval=0x000;
sec_cnt++;
}

if(sec_cnt==59)
{
sec_cnt=0x00;
min_cnt++;
}

if(min_cnt==59)
{
min_cnt=0x00;
hour_cnt++;
}

if(hour_cnt==24)
{
sec_cnt=0x00;
min_cnt=0x00;
hour_cnt=0x00;

}

intval++;
sei();

}

//======================================================= delay for milli seconds
void delay_ms(unsigned int v1)
{
unsigned int dtimer1,dtimer2;

for(dtimer2=0;dtimer2<v1;dtimer2++) //user v1
{

for(dtimer1=0;dtimer1<35;dtimer1++) //1ms @ 1MHZ
{
;
}
}

}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried to attached the screen capture of the error, could not get it right.
i tried cleaning up the code, but i see the spaces and tab space for the comments are now un-alligned
regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just copied the code you posted, pasted it into AS6.2 (release version) in a file called test.c and built it:

------ Rebuild All started: Project: test, Configuration: Debug AVR ------
Build started.
Project "test.cproj" (Clean target(s)):
Target "Clean" in file "C:\Program Files\Atmel\Atmel Studio 6.2\Vs\Compiler.targets" from project "C:\Documents and Settings\asl\My Documents\Atmel Studio\6.2\test\test\test.cproj" (entry point):
Task "RunCompilerTask"
Shell Utils Path C:\Program Files\Atmel\Atmel Studio 6.2\shellUtils
C:\Program Files\Atmel\Atmel Studio 6.2\shellUtils\make.exe clean
rm -rf test.o
rm -rf test.d
rm -rf "test.elf" "test.a" "test.hex" "test.lss" "test.eep" "test.map" "test.srec" "test.usersignatures"
Done executing task "RunCompilerTask".
Done building target "Clean" in project "test.cproj".
Done building project "test.cproj".

Build succeeded.
------ Rebuild All started: Project: test, Configuration: Debug AVR ------
Build started.
Project "test.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files\Atmel\Atmel Studio 6.2\Vs\Compiler.targets" from project "C:\Documents and Settings\asl\My Documents\Atmel Studio\6.2\test\test\test.cproj" (target "Build" depends on it):
Task "RunCompilerTask"
Shell Utils Path C:\Program Files\Atmel\Atmel Studio 6.2\shellUtils
C:\Program Files\Atmel\Atmel Studio 6.2\shellUtils\make.exe all
Building file: .././test.c
Invoking: AVR/GNU C Compiler : 4.8.1
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-gcc.exe" -x c -funsigned-char -funsigned-bitfields -DDEBUG -DF_CPU=8000000UL -O3 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -g2 -Wall -mmcu=attiny10 -c -std=gnu99 -save-temps -MD -MP -MF "test.d" -MT"test.d" -MT"test.o" -o "test.o" ".././test.c"
Finished building: .././test.c
Building target: test.elf
Invoking: AVR/GNU Linker : 4.8.1
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-gcc.exe" -o test.elf test.o -Wl,-Map="test.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mrelax -mmcu=attiny10 -Wl,-section-start=.table_sec=0x1234
Finished building target: test.elf
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "test.elf" "test.hex"
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "test.elf" "test.eep" || exit 0
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "test.elf" > "test.lss"
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "test.elf" "test.srec"
"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-size.exe" "test.elf"
text data bss dec hex filename
226 0 4 230 e6 test.elf
Done executing task "RunCompilerTask".
Task "RunOutputFileVerifyTask"
Program Memory Usage : 226 bytes 22.1 % Full
Data Memory Usage : 4 bytes 12.5 % Full
Done executing task "RunOutputFileVerifyTask".
Done building target "CoreBuild" in project "test.cproj".
Target "PostBuildEvent" in file "C:\Program Files\Atmel\Atmel Studio 6.2\Vs\Avr.common.targets" from project "C:\Documents and Settings\asl\My Documents\Atmel Studio\6.2\test\test\test.cproj" (target "Build" depends on it):
Task "Exec"
Command:
avr-source test.s
file 1 = .././test.c
file 2 = c:\\program files\\atmel\\atmel toolchain\\avr8 gcc\\native\\3.4.1056\\avr8-gnu-toolchain\\avr\\include\\stdint.h
Done executing task "Exec".
Done building target "PostBuildEvent" in project "test.cproj".
Target "Build" in file "C:\Program Files\Atmel\Atmel Studio 6.2\Vs\Avr.common.targets" from project "C:\Documents and Settings\asl\My Documents\Atmel Studio\6.2\test\test\test.cproj" (entry point):
Done building target "Build" in project "test.cproj".
Done building project "test.cproj".

Build succeeded.
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Projects Build Summary
----------------------
Time | Status | Errors |Warngs/info| Project [Config|platform]
-------------|-----------|-----------|-----------|---------------------------------------------------------------------------------------------------
00:00:03.50 | Succeeded |0 |0 | test\test.cproj [Debug|AVR]

Total Time Elapsed 00:00:05.23

No errors whatsoever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BTW I notice that despite me now suggesting it twice your build did NOT use -save-temps. I really suggest you do this if you want to see what's on lines 271 and 463 where the error occurred.

(very high line numbers for such a short piece of code!?!?).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

... in order for me to post the lines where the error is i first need to understand what causes the error.


??? Doesn't the syntax error notification give the file name and line number (and column)?

It took several posts before you actually passed on the information.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the purpose of the cli/sei in the ISR, are you trying to "nest" interrupts? Not usually a good thing for beginners to do. or do you not understand the mpu disables/re-enables interrupts for you before/after calling the ISR?

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clawson, Sorry i did notice that the -save-temps is a parameter i need to adjust. thanks will do so

Theusch, it does not point out where in the C files the problem is only the S files. Which was deleted by the compiler, as Clawson pointed out to me that i did not use the above mentioned parameter to save the files .

Theusch

It took several posts before you actually passed on the information.

I did post ""operand out of range: 0x3f" and mention of the problem with the S file. I did not think that the output window data would be needed.

Regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry that should have been quote tags

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Theusch, it does not point out where in the C files the problem is only the S files.

Well, I don't know whether something has to do with the -O0 or whatever the cause. I took your posted source, removed the semicolon at the end of the TIMSK0 line, and pasted the source into a "generic" 6.1 project. A fragment of my build results:
Quote:
Invoking: AVR/GNU C Compiler : 3.4.2
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.1002\avr8-gnu-toolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -DDEBUG -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -g2 -Wall -mmcu=attiny10 -c -std=gnu99 -MD -MP -MF "GccApplication1.d" -MT"GccApplication1.d" -MT"GccApplication1.o" -o "GccApplication1.o" ".././GccApplication1.c"
.././GccApplication1.c: In function 'main':
C:\Users\ltheusch\Documents\Atmel Studio\6.1\GccApplication1\GccApplication1\GccApplication1.c(45,9): expected ';' before '__asm__'
make: *** [GccApplication1.o] Error 1
Done executing task "RunCompilerTask" -- FAILED.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clawson, thanks for the -save-temps.

The output window is as follows:

C:\Documents and Settings\coetzeec2380\My Documents\fw\AVR\tiny10_wd001\tiny10_wd001\Debug\tiny10_wd001.s(271,1): operand out of range: 0x3f
C:\Documents and Settings\coetzeec2380\My Documents\fw\AVR\tiny10_wd001\tiny10_wd001\Debug\tiny10_wd001.s(463,1): operand out of range: 0x3f

The S file /ASM file is a very big file and at line 271 coulomb 1 which is at position "lds r16,63" the following segment is the area in question.


.LCFI5:
.cfi_def_cfa_offset 4
.cfi_offset 16, -3
lds r16,63
push r16
ldi __zero_reg__,0
push r20

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

"C:\Program Files\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1051\avr8-gnu-toolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -DDEBUG -O0 -g2 -Wall -mmcu=attiny10 -c -std=gnu99 -MD -MP -MF "tiny10_wd001.d" -MT"tiny10_wd001.d" -MT"tiny10_wd001.o" -o "tiny10_wd001.o" ".././tiny10_wd001.c"

Do you get the same results with -Os?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
There is no need to get angry, in order for me to post the lines where the error is i first need to understand what causes the error.

I was not angry. I was just observing that I spent 10 minutes of my life
tidying, building and simulating your code.
It takes 2 minutes of your life to tidy your own code. Most importantly, it
requires zero brain-ache.

I quite understand that you may be less familiar with the building and simulating.
You may even be unsure how to copy and paste Build Warnings/Errors.

Cliff and I will always differ:
I promote high-level code written neatly.
Cliff likes to dive into the generated ASM.

Incidentally, the tidy code that I posted obeyed all the conventions.

The code that you last posted breaks most of the rules in the book.

However, I pasted it into AS6.2 and the Simulator is still running!
It takes a LONG time to simulate 10 seconds! i.e. 10 million instructions.

Ah-ha. It has just got to the Breakpoint. It says 10,035,265.00 µs

As I said earlier, Cliff and I take different approaches.
I could point out the 'anomalies' in the HLL.
I have no intention of even looking at the ASM.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Theusch, I do not want to enable the optimization as it would remove the nested for loop.
i will give it go and get back

regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Theusch, your suggestion to activate the size optimization does solve the whole problem for the error.

Appreciate it , i would like to solve the problem without it though.

It does help for a point of reference.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David,

Thanks for clearing things up,

Quote:

It takes 2 minutes of your life to tidy your own code. Most importantly, it
requires zero brain-ache.

If you have the time and are willing to show me my faults in the code which you say break the rules i would like to learn where i went wrong. i would like to take it off the forum.

I honestly don't know whats wrong with the tidiness of the code.

Regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

i would like to solve the problem without it though.

??? The Tiny10 only has 500 words of flash space to start with, so you are limited to 500 instructions--period. (You said the .s file is big--is your problem that the app is too big for the target?) -O0 might generate a program 2x or more of any decent optimixation level. Also, Tiny10 code generation with your chosen toolchain used to be shaky at best. It is probably solid now--but I'd give no guarantees at -O0.

Let me construct an analogy: I want you to get from point A to point B as fast as possible. But you cannot run; only walk. Now I'll call you onto the carpet and read you the riot act because you are so slow in getting the task done.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

i would like to solve the problem without it though.

??? The Tiny10 only has 500 words of flash space to start with, so you are limited to 500 instructions--period. (You said the .s file is big--is your problem that the app is too big for the target?) -O0 might generate a program 2x or more of any decent optimixzation level. Also, Tiny10 code generation with your chosen toolchain used to be shaky at best. It is probably solid now--but I'd give no guarantees at -O0.

Let me construct an analogy: I want you to get from point A to point B as fast as possible. But you cannot run; only walk. Now I'll call you onto the carpet and read you the riot act because you are so slow in getting the task done.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd say it's a compiler bug, that doesn't really matter since the optimizer will fix it.

lds r16,63 

isn't possible on the reduced cores, maybe it should be

in r16,63 

that is save SREG to r16.

Quote:
The IN and OUT instructions can access all 64 locations of I/O memory. Direct addressing using the LDS and STS instructions reaches the 128 locations between 0x0040 and 0x00BF.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
If you have the time and are willing to show me my faults in the code which you say break the rules i would like to learn where i went wrong. i would like to take it off the forum.

I honestly don't know whats wrong with the tidiness of the code.

Your tidiness is 100% perfect. Note that you can automate the indentation in Arduino IDE with or in AS6. Personally, I use indent.exe as a separate job.

Your 'break the rules' are:
1. sei() inside an ISR()
2. not making ISR() shared variables volatile.
3. making pointless loops istead of
4. you don't need to clear OCF0A in the ISR()
5. TOV0 is irrelevant without a TOI0E
6. Your ISR() could have nested if. It is logical
7. Your main() disables IRQs after 10 sec. then does 5 sec delay.
8. if(0x01==port_temp) is a very unwise test of a port. If you want to read PINB.0 mask the specific bit that you want to test.

I would fix all these HLL points before ever worrying about code generation. I would be very surprised if there is a compiler error.

The Tiny10 is a lousy AVR to develop on. There is no debugWIRE. Choose a Tiny4313 or Tiny1634. Once you are fully debugged on the 'big' Tiny, perform a lobotomy, re-compile for the Tiny10. Test for Tiny10.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David,

Thanks for the pointers, very much appreciate it.

PS also to everyone else , Thanks for the inputs i picked up a great deal.

Regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
I would be very surprised if there is a compiler error.
Well, according to the OP the compiler produced this
lds r16,63 

which results in an impossible/undefined op-code for the given architecture. That is a compiler error.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, as I said earlier, I would fix the logic first. There is nothing much that will not compile/run on a big Tiny. e.g. use Timer1

As a separate issue, it is worth seeing how the OP got a "lds r16,63". And it would be worth seeing how the Simulator handles it. And I could dig out a real Tiny10 to run it on.

My build of the OP's source code has no LDS. And has no build errors either.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Well, as I said earlier, I would fix the logic first.
Me too.
Quote:
As a separate issue, it is worth seeing how the OP got a "lds r16,63"

I get that if I compile your code with -O0. But it's kind of funny that it only generates a warning (another compiler bug).

If I try to assemble that line of code with avrasm2 I get

Quote:
error: Operand out of range

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
As a separate issue, it is worth seeing how the OP got a "lds r16,63".
Which was the EXACT reason for me suggesting -save-temps. There's only two ways to get an invalid opcode into the s file. Either OP used asm() or the compiler generated something invalid. I suspected the latter. Only by looking at the same file (and especially with avr-source) can you see where the opcode came from.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, The error only comes with -O0. I think you must be crazy to use -O0, but hey-ho, if that is what the punter wants!
I ticked the "--save-temps box in the Misc tab of the Compiler configuration.

It appears that "LDS R16,0xBF" is generated instead of "IN R16,0x3F" i.e. "IN R16,SREG"

According to the Simulator, there is no "memory" @ 0xBF. However, I don't see it as an illegal instruction. Surely "LDS R16,0x3F" would perform the same job as "IN R16,0x3F" but slower.

Yes, it is definitely a Compiler error. But who is going to use -O0 ?

David.

Edit.

	volatile uint8_t val = *(uint8_t *)0x3F;

-O0 produces a perfectly valid:


0000002D LDI R20,0x3F Load immediate
0000002E LDI R21,0x00 Load immediate
0000002F MOV R30,R20 Copy register
00000030 MOV R31,R21 Copy register
00000031 LDD R20,Z+0 Load indirect with displacement

-O1 produces a more efficient:


00000023 IN R20,0x3F In from I/O location

The ISR() preamble was probably written in gobbledygook. Otherwise it would have needed to push 3 registers before reading and pushing the value of SREG.

OTOH, wasn't -O0 deliberately created to be complete crap in the first place?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did a test on real hardware, SREG contained 0x02 but lds from address 63 returned zero.

        in      r24, SREG       ; Save SREG
lds r18, 63 ; Warning: operand out of range: 0x3f

rcall suart_put_hex ; Print SREG

ldi r24, ' '
rcall suart_putc

mov r24, r18
rcall suart_put_hex ; Print result of "lds r18, 63"

Result:

02 00

=====================================================================

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well my LDS and STS were generated in the ISR() preamble and postamble. And they actually addressed 0x00BF rather than 0x3F.

I would have expected LDS to have worked the same as IN but with an extra cycle. Perhaps this is a feature of the brain-death Tiny10 core and the SFR mapping.

According to the Simulator, SRAM goes from 0x0040 - 0x005F.

I guess that LDS would work in this range. I am too idle to read up the docs.

   volatile uint8_t val = *(uint8_t *)0x5F;

generates LDS R20,0x5F with -O1

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

OTOH, wasn't -O0 deliberately created to be complete crap in the first place?

Well yes and no. -O0 is actually the default so if you don't specify -O you get it anyway. All it means is "don't optimise" but it's not really expected that anyone would use it in reality. It's there so the compiler authors can access the code generation before optimisation phases have been applied. I guess it'd be a dangerous change to make now but GCC could really do with having at least -O1 as the default so you'd have to go out of your way to stumble upon -O0.

(then someone like Atmel goes and makes the mistake in early AS5/AS6 of making the "Debug" build use -O0! Thankfully they corrected that later after I pointed it out to them but there's a lot of people using old AS5/6 versions and who probably don't even know the difference between "Debug" and "Release" and just build using all the default settings (and that means "Debug")).