Porting C-Code from PIC to AVR

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

Hi,

i tried to port a C-Source for PIC (Hi-Tech PICC Compiler) to my AVR. After some changes in device specific sections i got the code running, but at some points my AVR hangs up or resets himself. I think this is because of too heavy RAM usage? (or not?).

The code was written for a PIC16F876 with 368 Byte RAM. My ATMega8 has 1kByte RAM so can it be a RAM problem?

Has someone experience in porting C-Code from PIC Hi-Tech PICC Compiler to AVR GCC?

Hava a look at my web page -> http://www.tobiscorner.at.tf

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

Hello,
I do not see any problem in Mem, unless you have added extra variables in the new port. On compile please check the .data and .bss size. If that exceeds or close to the limit then you are in trouble. You should be able to asses the max stack your code is going to use. This stack size and the sum total of .bss and .data is the amount of mem you will need.

Next point is - are you using any interruopts? If yes, please check that the vector names are given properly. This I am assuming since you mentioned the processor resets. If the vector address is not set properly in GCC, when an interrupt occurs, by default the vector points to RESET.

Hope this helps.

Parthasaradhi Nayani

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

Hello,

.data + .bss is about 100. So this isn't the problem.

Yes i'm using interrupts. Is this correct SIGNAL(SIG_UART_DATA) { ...}?

Hava a look at my web page -> http://www.tobiscorner.at.tf

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

I've now read a little of the PICC Documentation and figured out one more problem: Some variables (and the huge structures) are definded as "const" and with PICC theese variables are stored in program memory.

How do i put variables and access them in program space?

typedef struct tagName {
unsigned char x;
unsigned char y;
} Name;

This is a simple structure. Do i get is this way into program mem?

const Name *pName PROGMEM;
This should create an Pointer to this structure in Program space.

Is this correct?

Hava a look at my web page -> http://www.tobiscorner.at.tf

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

Basically correct, but you gotta fetch them from ROM manually.

This is described in the avr-libc documentation, and there are

numerous threads here about it.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.