Hello together,
I have a question about const arrays.
I used a lot of diferent compilers and the behaivior of the Arduino Compiler seems to be diferent:
Usually when I write:
const array_with_content = {0, 1, 2, 3, 4};
The Compiler writes it to the Flash only and does not load it to the RAM. In a Testproject it does.
Is this a issue due to the compiler? Or does it depent to the AVR architecture?
Or did I do a stupid mistake?
Here ist my Example Project: (Run on Arduino UNO)
It simply Puts a PWM Signal with 200Hz to the Output an the Arrays store Walue an length.
When I Compile it, Arduino says: "Wenig Speicher verfügbar, es können Stabilitätsprobleme auftreten." which means: less RAM left, there may be lack of stability
HINT: The arrays had to be shortend due to the 9000 Characters of the forum. I attached the ino file.
#define sizeof_pwm_array 650
void (*isrCallback)();
const uint16_t pwm_out_array[sizeof_pwm_array] { 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF5, 0xF6, 0xF7, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, ...};
const uint8_t pwm_out_rep[sizeof_pwm_array] { 0xB5, 0x14, 0x10, 0x06, 0x04, 0x06, 0x04, 0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x06, 0x04, 0x06,...;}
void setup(){
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
TCCR1A = _BV(COM1A1) | _BV(COM1B1) ; // phase and frequency correct mode. NON-inverted mode
//phase/frequency correct mode. SELECT THIS FOR INVERTED OUTPUTS.
TCCR1B = _BV(WGM13) | _BV(CS11);
// Select mode 8 and select divide by 8 on main clock.
ICR1 = 5000;
}
void loop() {
static uint8_t nr=0;
delay(5);
change_pwm();
}
void change_pwm()
{
static uint16_t pwm_value; // 0...5000
static uint16_t index=0xFFF;
static uint16_t sub_index;
if(index >= sizeof_pwm_array)
{
index = 0;
pwm_value = pwm_out_array[0] * 12,5;
sub_index = pwm_out_rep[0];
}
sub_index--;
OCR1B = pwm_value;
OCR1A = pwm_value;
if(sub_index == 0)
{
pwm_value = pwm_out_array[index] * 12,5;
sub_index = pwm_out_rep[index];
index++;
}
}
PWM_Folge.ino (9.89 KB)