|
|
View previous topic :: View next topic |
Author |
Message |
mojsa2000
Joined: 18 May 2010 Posts: 78
|
worst case in .lst file |
Posted: Sat Nov 27, 2010 6:15 am |
|
|
Hi
I compiled the program and then look at the .lst file.in the .lst file,there is a message:
Stack: 8 worst case (5 in main + 3 for interrupts)
how can I recognize and improve them?
for example this is the main that has 5 worst case:
Code: |
void main()
{
SET_TRIS_A( 0xFF );
enable_interrupts(INT_AD);
enable_interrupts(INT_EXT);
enable_interrupts(INT_RTCC);
setup_adc_ports(AN0_AN1_VSS_VREF);
setup_adc(ADC_CLOCK_DIV_8);
enable_interrupts(INT_RDA);
setup_timer_2(T2_DIV_BY_1,255,4);//per 1ms
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
setup_comparator(NC_NC_NC_NC);
ext_int_edge( H_TO_L );
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
setup_timer_0(RTCC_EXT_H_TO_L|RTCC_DIV_32);
set_timer0(0);
set_timer2(0);
ds1307_init();
delay_ms(100);
lcd_init();
while(1)
{
calculating();
if(half_min_flag)
{
ds1307_get_date(day,month,year,dow);
ds1307_get_time(hour,min,sec);
//**********************
if (ten_min_write_to_eeprom)
{
v_memory_pointer_func(hour,min,day);
i_memory_pointer_func(hour,min,day);
eeprom_write(i_out,i_memory_pointer);
eeprom_write(v_out,v_memory_pointer);
ten_min_write_to_eeprom=0;
//********************************
if(hour_write_to_eeprom)
{
hourly_Energy=total_energy/3600;
daily_Energy+=hourly_Energy;
hourly_pos_VI_memory_pointer_func(hour,day);
hourly_neg_VI_memory_pointer_func(hour,day);
if(hourly_Energy>=0)
{
eeprom_write(hourly_Energy,hourly_pos_VI_memory_pointer);
eeprom_write(0,hourly_neg_VI_memory_pointer);
}
if(hourly_Energy<0)
{
eeprom_write(hourly_Energy,hourly_neg_VI_memory_pointer);
eeprom_write(0,hourly_pos_VI_memory_pointer);
}
hour_write_to_eeprom=0;
}
//******************************************************************
if(day_write_to_eeprom)
{
if(daily_Energy>=0)
{
daily_pos_VI_memory_pointer_func(day);
eeprom_write(daily_Energy,hourly_pos_VI_memory_pointer);
eeprom_write(0,hourly_neg_VI_memory_pointer);
}
if(daily_Energy<0)
{
daily_neg_VI_memory_pointer_func(day);
eeprom_write(daily_Energy,hourly_neg_VI_memory_pointer);
eeprom_write(0,hourly_pos_VI_memory_pointer);
}
day_write_to_eeprom=0;
daily_Energy=0;
}
}
half_min_flag=0;
}
calculating();
if(one_min_flag)//display the values On LCD in per minute
{
lcd_clear();
lcd_gotoxy(1,1);
printf(lcd_putc,"Date: 20%u/%u/%u",year,month,day);
lcd_gotoxy(1,2);
printf(lcd_putc,"Time: %02u:%02u",hour,min);
delay_ms(4000);
read_hourly_vi(hour,day);
lcd_clear();
lcd_gotoxy(1,1);
printf(lcd_putc,"+E(Hour): %.2f",hourly_positive_power);
lcd_gotoxy(1,2);
printf(lcd_putc,"-E(Hour): %.2f",hourly_negative_power);*/
delay_ms(4000);
read_daily_vi(day);
lcd_clear();
lcd_gotoxy(1,1);
printf(lcd_putc,"+P(Day): %.2f",daily_positive_power);
lcd_gotoxy(1,2);
printf(lcd_putc,"-P(Day): %.2f",daily_negative_power);
delay_ms(4000);
one_min_flag=0;
}
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Sat Nov 27, 2010 7:46 am |
|
|
Why do you need to change this?.
Whether it matters, depends on your chip, which you are not telling us....
If your chip has more than 8 stack levels, then reducing the count, is not an 'improvement', almost certainly resulting in more ROM being used.....
Three in interrupts, is _high_. Implying that you are calling subroutines inside interrupts, and almost certainly taking longer in the interrupts than you should. Anything above '2' in interrupts (and this only when using multiple hardware priority levels), is a possible sign of badly written interrupt code.
I'd be much more worried about this, than five in main...
In the main, I'd be most suspicious that 'calculating' is itself calling some further subroutines.
Code calling routines, inside other routines, is the 'user' of stack levels.
Best Wishes |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Sat Nov 27, 2010 8:10 am |
|
|
Dear Ttelmah
Hi
Thanks for your introduction. I strongly need your opinion about my project.
In my project, I want to read/write date and time from/to ds1307 via commands that come from the pc (RX/TX). I've made a program by C# that sends the read/write commands. Therefore when the pc sends a command, the micro should receive it and should recognize the request, then, finally, should receive data (date and time) completely. For this action, I used a kbhit() in #rda isr. if I use this routine in main(), the data maybe change when is received.
Whats your idea about this? Is there other ways? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|