-Hi everybody. I have a memory related question when compiling. In my example, when I do method 1, the compiler says 1084 bytes are exhausted (in the picture) And when I do method 2, it only runs out of 880 bytes. Why is there such a big difference? can anyone help me? Thanks!
-- Here is error in code
error_memory|690x285
-- Full_code:
#include <avr/io.h>
volatile uint8_t timeCount = 0;
volatile uint8_t delay_ = 0;
float last_m;
int current_step=0;
void delay_s(uint8_t count)
{
delay_=count;
while(delay_)
{
}
}
void step_(int angle,uint8_t m)
{
uint8_t stepp = (abs)(current_step-angle);
int real_angle;
real_angle =( angle-current_step>0)?1:(-1);
while(stepp)
{
if(real_angle<0)
{
choose_(stepp % 4);
delay_s(m);
}
else {
choose_((abs(angle) - stepp)%4);
delay_s(m);
}
stepp--;
}
current_step = angle;
}
void choose_(uint8_t a)
{
switch(a)
{
case 0:PORTB=0x09;
break;
case 1: PORTB=0x0A;
break;
case 2:
PORTB=0x06;
break;
case 3:
PORTB=0x05;
break;
}
}
void setup_adc()
{
ADMUX|=(1<<REFS0)|(1<<MUX1)|(1<<ADLAR); // bit 6 -1- Vref = vcc , 0 - Vref = internal = 1.1 , ADC2
ADCSRA|=(1<<ADEN)|(1 << ADPS1) | (1 << ADPS0);// aden = enable, prescale
ADCSRA |= (1 << ADSC);
}
uint8_t adc_read (void)
{
uint8_t adc_result;
adc_result = ADCH; // 0 -255
//adc_result = ADC; // For 10-bit resolution
ADCSRA |= (1 << ADSC);
return adc_result;
}
int main (void)
{
DDRB = 0x0f; //Set PB2 as output, ignore the rest
TCCR0B |= _BV(CS01) ; // clock frequency / 8
OCR0B = 0x00; // Output compare
TCNT0 = 0; // Set counter 0 to zero
TIMSK0 = _BV(TOIE0); // Enable overflow interrupt
PORTB=0x01;
setup_adc();
sei(); //Enable global interrupts
while(1)
{
uint8_t m = adc_read();
/// **** method 1 with 1088 bytes
float real_ = -90 + (float)(m*0.71);
/// ****** method 2 with 880 bytes
/*
float real_ = (float) (m*0.71);
real_ = real_ -90;
*/
}
}
ISR(TIM0_OVF_vect)
{
timeCount++;
if(timeCount %10==0)
{
if(delay_ )delay_ --;
}
}