 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Ttelmah Guest
|
|
Posted: Fri Jan 12, 2007 11:18 am |
|
|
| Christophe wrote: | I don't know if the TS still is following this actually? But the TS is not the same as me. I have a completely different main program.
I do have _alot_ of global variables; is that a problem when using bootloaders? |
Sorry, misunderstood, was following the 'one thread', and thought it was the same person with problems.
It does sound as if the problem is not the bootloader at all, but rather something 'walking' over the RAM. Once the code is running, the only differences with the bootloader are:
1) A fractional extra time delay entering the interrupt. Try adding delay_cycles(3) at the start of every interrupt handler. Does it still work without the bootloader?.
2) The loss of ROM. How near to full is your program, with the bootloader present?. There have been a couple of threads in the past, where (without a bootloader), having a program that is near to running out of RAM, can lead to problems appearing, when ROM becomes short. The problem is that though the two memory areas are distinct, being short of one, can put an extra load on the other...
Global variables as such, are not a problem, but low memory as a whole, may well be. Are you sure that both programs do fit in their available space?. Are you testing with an ICD?. If so, remember the loss of resources at the top of memory, and the RAM, that this involves. Is it possible that what is actually happening, is that with the bootloader present, you are running out of resources for the ICD?...
You flag for an ICE, which should not have this problem, but some ICE systems have their own limitations. Have you tried in a real chip, without ICD/ICE?.
Best Wishes |
|
 |
Guest
|
|
Posted: Fri Jan 12, 2007 3:13 pm |
|
|
| Quote: |
And what do I learn with that? _right_
|
There is no need to be rude |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Mon Jan 15, 2007 2:11 am |
|
|
1> I've tried inserting the delay_cycles (3); it works without bootloader.
2> The program is 86%. The bootloader is 5%. So I guess my program is very near to full. I don't use the ICD.
| Quote: | | Are you sure that both programs do fit in their available space? |
How can I test that?
Have you got any more suggestions?
Why do interrupts suddenly stop getting executed. How can I be sure they are fired?
edit: I made the main program 77% ROM. Still same problem.
edit2: I managed to succesfully load the main program via codeloader. Interrupts are working!? Codeloader is at the end of memory; mine is at the begin. |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Mon Jan 15, 2007 10:28 am |
|
|
| Is it btw hard to place the CCS bootloader at the end of memory? |
|
 |
Ttelmah Guest
|
|
Posted: Mon Jan 15, 2007 3:45 pm |
|
|
Just a thought Christophe.
Where are you declaring your interrupt handlers, in your 'application' code?.
I always use the 'standard' of declaring the interrupt handlers first. Now CCS, tends to generate code in (approximately) the order it is declared. I am wondering, if the interrupt handler routines (not the global handler provided by CCS, but the individual functions), are ending up above perhaps 0x8000, and the long jump from the global handler is the problem, rather than the bootloader. Possibly, without the bootloader present, the routines are just that little bitlower in the memory, and avoiding problems...
Best Wishes |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Tue Jan 16, 2007 2:05 am |
|
|
Well that would be:
1. global vars
2. functions
3. Interrupt handler functions
I checked the lst file. All the handlers are between 0x0300 and 0x0600
The maximum code adress for a piclf877a is 0x1FFF.
| Code: | #include "NS.h"
#include <string.h>
//#include <C:\Documents and Settings\christophe.seyen\My Documents\Hardware\PIC\BOOTLOADER\Bootloader.h>
//******************** Constanten voor heel het programma ********************//
// Indien dit gebruikt wordt de strcmp functies aanpassen!
/*
const int8 Command_Strings [5][5] = {
"COMM",
};
*/
//************** Globale variabelen voor heel het programma ******************//
// V07 = 5.51074219
// V100 = 5.89965820
//float f_Vbat, f_Vadap;
int16 Teller = 3000, Key = 0, Hrs_A, Alarm_hours, int16_Vbat, int16_Vadap;
signed int16 V07 , V100, V_X;
char Buffer_Matrix [9] = { 255,255,255,255,255,255,255,255,255 }, Data_RX_RS232 [BUFFER_SIZE],
Data_Copy [40];
int1 LADEN_BEZIG, ADAPTER_IN, E3_SLEEP = FALSE,
ALLES_LOS = TRUE, SPACE_PRESSED_WHILE_SHDN = FALSE, On_Off_State,
OFF_TIMER_AFGELOPEN = FALSE, BUTTON_DEBOUNCED = FALSE,
BOOTED = FALSE, BYTE_RECEIVED = FALSE, KEYCLICK = TRUE,
OFF_TIMER_ENABLED = FALSE, KEYPAD_DEBOUNCED_1 = FALSE,
ENABLE_KEYPAD_SCAN = TRUE, ON_FIRST_PRESS = TRUE,
LOW_POWER_E3 = FALSE, ADAPTER_DEBOUNCED = FALSE, SECOND_COUNTED = FALSE,
ALARM_TIMER_ENABLED = FALSE, ALARM_TIMER_AFGELOPEN = FALSE,
GIVE_ALARM = FALSE, BRAILLE_TIMER_ENABLED = FALSE, BATTERY_CALIBRATION = FALSE,
LADER_UIT_DEBOUNCED = FALSE, V_07_TIMER_ENABLED = FALSE,
V_07_TIMER_AFGELOPEN = FALSE, SUSPEND = FALSE,
CURSOR_TIMER_AFGELOPEN = FALSE, CURSOR_GOES_DOWN, LADEN_OVER_Debounced = FALSE,
SEND_VADAP_NOW = TRUE, VADAP_TOO_LOW = FALSE ;
int8 Secs_O = 0, Secs_C = 0, Mins_O = 0, Mins_C = 0, Hrs_O = 0, Read_Pointer = 0, Write_Pointer = 0,
No_Loop_Pointer, Off_Mins, Off_Hours, EXT_Debounce_Counter = 255,
KEYPAD_Debounce_Counter_2 = 255, KEYPAD_Debounce_Counter_1 = 255,
ADAPTER_Debounce_Counter = 255, Second_Counter = 255, Percentage_Loaded = 0,
Secs_A = 0, Mins_A = 0, Alarm_Mins, LADEN_OVER_Debounce_Counter = 255,
Secs_B = 0, Mins_B = 0, LADER_UIT_Debounce_Counter = 255, Secs_07 = 0, Mins_07 = 0,
Cursor_Timer = 255, Cursor_Position, Copy_Datalengte, tempvar, Seconde_Teller = 100, temp_teller;
int32 Ticker_O, Ticker_C, Ticker_A, Ticker_B, Ticker_07;
//********************** Declaraties functies ********************************//
#SEPARATE
void Br_Clear ();
#SEPARATE
void Br_Slaap ();
#SEPARATE
void Br_Wake ();
#SEPARATE
int16 Get_Key_To_Send ();
#SEPARATE
int8 Check_Commando ();
//#SEPARATE
//void Send_Float_RS232 (float Float_to_send, int1 mode); // mode 0 = Vbat, mode 1 = vadap
#SEPARATE
void Send_int16_RS232 (int16 Int16_to_send, int1 mode);
#SEPARATE
void BUZZER ();
#SEPARATE
void Read_Buffer ();
#SEPARATE
void Toggle_E3 ();
#SEPARATE
void Booting_00 ();
#SEPARATE
void Booting_20 ();
#SEPARATE
void Booting_40 ();
#SEPARATE
void Boot_E3 ();
#SEPARATE
void Click ();
#SEPARATE
void Long_Beep ();
//#SEPARATE
//void To_IEEE (int *Value);
#SEPARATE
int8 Read_Matrix ();
#SEPARATE
void Initialize_RTC ();
#SEPARATE
void WRITE_INT16_EEPROM (int8 n, signed int16 data);
#SEPARATE
signed int16 READ_INT16_EEPROM (int8 n);
//#SEPARATE
//float Meet_Spanning (int1 mode); // mode 0 = Vbat , mode 1 = Vadap
#SEPARATE
Int16 Meet_Spanning_2 (int1 mode); // mode 0 = Vbat , mode 1 = Vadap
#SEPARATE
void SEND_RS232_50_0 ();
//#SEPARATE
//void Send_String_RS232 ( int8 Command , int8 datalength, int8 databyte );
#SEPARATE
void myputc (int8 x);
#SEPARATE
void Disable_SPI ();
#SEPARATE
void no_rs232_error_warning (); // Géén extra ROM voor deze dummy functie
//******************************* Constanten *********************************//
//
/*int8 Boot_bericht[22] = {0b10100000, 0b10000110, 0b11101010, 0b10000110,
0b11000110, 0b01001000, 0 ,0 , 0b01001000, 0b10001010, 0, 0b1010000,
0b00001100, 0b01001010, 0b01001010, 0b11000110, 0b10000100, 0b11001010,
0b11001100, 0,0,0};
*/
//************************** Interrupt routines ******************************//
//**************************** GLobale interrupt *****************************//
//Een interrupt gebeurt die niet wordt opgevangen door een andere handler
#int_default
void GLOBAL_Isr ()
{
temp_Teller++;
}
//***************************** RDA interrupt ********************************//
//Als een karakter wordt ontvangen door de UART; inlezen en opslaan.
#int_RDA
void RDA_Isr ()
{
// int8 t;
data_RX_RS232 [Read_Pointer] = getc (); // Lees byte vd seriële poort
// t = Read_Pointer;
Read_Pointer = ( Read_Pointer + 1 ) % BUFFER_SIZE; // Verhoog read-pointer
// if (Read_Pointer == Write_Pointer);
// Read_Pointer = t;
Byte_Received = TRUE; // Geef aan met vlag
// if (yp_startupBuzzer)
// CLICK();
}//RDA ISR
//************************** Timer1 interrupt RTC ****************************//
//Deze Timer werkt als RTC.
#int_TIMER1
void TIMER1_isr()
{
//********************************** OFF TIMER *********************************
if ( OFF_TIMER_ENABLED )
{
Ticker_O -= 65536; // Decrement ticker by clocks per interrupt
if ( Ticker_O < 65536 ) // If second has expired
{
Ticker_O += TIMER1_FREQUENCY; // Increment ticker by clocks per second
Secs_O++; // Increment number of seconds
if ( Secs_O == 60 ) // Seconden, minuten en uren tellen
{
Mins_O++;
secs_O = 0;
if ( Mins_O == 60 )
{
Hrs_O++;
Mins_O = 0;
}
if ( (Mins_O == Off_Mins) && (Hrs_O == Off_Hours) ) // Minuten en uren bereikt?
{
OFF_TIMER_AFGELOPEN = TRUE; // Geef aan met vlag
OFF_TIMER_ENABLED = FALSE; // Zet de OFF-TIMER uit
}
}
}
} // OFF_TIMER_ENABLED
//********************************** ALARM TIMER *******************************
if ( ALARM_TIMER_ENABLED )
{
Ticker_A -= 65536;
if ( Ticker_A < 65536 )
{
Ticker_A += TIMER1_FREQUENCY;
Secs_A++;
if ( Secs_A == 60 )
{
Mins_A++;
secs_A = 0;
if ( Mins_A == 60 )
{
Hrs_A++;
Mins_A = 0;
}
if ( (Mins_A == Alarm_Mins) && (Hrs_A == Alarm_Hours) )
{
ALARM_TIMER_AFGELOPEN = TRUE;
ALARM_TIMER_ENABLED = FALSE;
}
}
}
} // IF ALARM_TIMER_ENABLED
//*********************************** BRAILLE TIMER ****************************
if ( BRAILLE_TIMER_ENABLED )
{
Ticker_B -= 65536;
if ( Ticker_B < 65536 )
{
Ticker_B += TIMER1_FREQUENCY;
Secs_B++;
if ( Secs_B == 60 )
{
Mins_B++;
secs_B = 0;
if ( (Mins_B == MAX_BRAILLE_ON_TIME) ) // Na MAX_BRAILLE_ON_TIME tijd: Braille timer is afgelopen.
{
BRAILLE_TIMER_ENABLED = FALSE;
output_low (BR_SLEEP); // 200 V uit
}
}
}
}
//************************************ V_07 TIMER ******************************
if ( V_07_TIMER_ENABLED )
{
Ticker_07 -= 65536;
if ( Ticker_07 < 65536 )
{
Ticker_07 += TIMER1_FREQUENCY;
Secs_07++;
if ( Secs_07 == 60)
{
Mins_07++;
secs_07 = 0;
if ( (Mins_07 == V_07_TIME) )
{
V_07_TIMER_AFGELOPEN = TRUE;
V_07_TIMER_ENABLED = FALSE;
}
}
}
}
//******************************* CHARGE TIMER *********************************
if ( LOW_POWER_E3 && !input (CHARGE_ON) ) // Als LOW POWER MODE en Laden bezig
{ // Tel minuten
Ticker_C -= 65536;
if ( Ticker_C < 65536 )
{
Ticker_C += TIMER1_FREQUENCY;
Secs_C++;
if ( Secs_C == 60 )
{
Mins_C++;
secs_C = 0;
}
}
}
} // Timer_1
//************************** Timer2 interrupt ********************************//
//Timer0 overloopt elke 20 ms. (50Hz) Gebruikt om 1. minutenteller 2. off timer
//3. Debounce timer voor keypad en adapter 4. seconde teller
#int_Timer2
void Timer2_Isr ()
{
//******************* Minutenteller voor batterijspanning **********************
if ( Teller )
--Teller;
//******************* Secondenteller voor batterijspanning *********************
// Elke 2 seconden de adapterspanning meten
if ( Seconde_Teller )
--Seconde_Teller;
//************************ EXT Debouncing: 40 ms teller ************************
// Externe ITR: schakelaar omhoog of beneden bewegen
if ( EXT_Debounce_Counter == 0 )
{
if ( On_Off_State == input (AAN_UIT) )
{
BUTTON_DEBOUNCED = TRUE; // Geef debounced aan met vlag
EXT_Debounce_Counter = 255; // 255 : debouncing timer uitzetten
}
}
else if ( EXT_Debounce_Counter < 255 )
{
--EXT_Debounce_Counter;
}
//*************************** KEYPAD Debouncing 1 ******************************
// Bij het indrukken van een toets niet dadelijk doorsturen.
if ( KEYPAD_Debounce_Counter_1 == 0)
{
KEYPAD_DEBOUNCED_1 = TRUE;
KEYPAD_Debounce_Counter_1 = 255;
}
else if ( KEYPAD_Debounce_Counter_1 < 255 )
{
--KEYPAD_Debounce_Counter_1;
}
//*************************** KEYPAD Debouncing 2 ******************************
// Scannen uitzetten na het loslaten van een combinatie
if ( KEYPAD_Debounce_Counter_2 == 0 )
{
ENABLE_KEYPAD_SCAN = TRUE; // Keypad scannen aanzetten (pas na 20 mS)
KEYPAD_Debounce_Counter_2 = 255;
}
else if ( KEYPAD_Debounce_Counter_2 < 255 )
{
--KEYPAD_Debounce_Counter_2;
}
//************************* ADAPTER Plug in debouncing *************************
if ( ADAPTER_Debounce_Counter == 0 )
{
ADAPTER_DEBOUNCED = TRUE;
ADAPTER_Debounce_Counter = 255;
}
else if ( ADAPTER_Debounce_Counter < 255 )
{
--ADAPTER_Debounce_Counter;
}
//***************************** Seconde Tellen *********************************
if ( Second_Counter == 0 )
{
SECOND_COUNTED = TRUE;
Second_Counter = 255;
}
else if ( Second_Counter < 255 )
{
--Second_Counter;
}
//************************* Lader uitgetrokken debouncer ***********************
if ( LADER_UIT_Debounce_Counter == 0 )
{
LADER_UIT_DEBOUNCED = TRUE;
LADER_UIT_Debounce_Counter = 255;
}
else if ( LADER_UIT_Debounce_Counter < 255 )
{
--LADER_UIT_Debounce_Counter;
}
//************************** 350 ms Cursor knipperen ***************************
if ( Cursor_Timer == 0 )
{
CURSOR_TIMER_AFGELOPEN = TRUE;
Cursor_Timer = 255;
}
else if ( Cursor_Timer < 255 )
{
--Cursor_Timer;
}
//************************* Lader uitgetrokken debouncer ***********************
if ( LADEN_OVER_Debounce_Counter == 0 )
{
LADEN_OVER_DEBOUNCED = TRUE;
LADEN_OVER_Debounce_Counter = 255;
}
else if ( LADEN_OVER_Debounce_Counter < 255 )
{
--LADEN_OVER_Debounce_Counter;
}
}// TIMER2
//************************** EXTERNAL interrupt ******************************//
//Interrupt als de AAN/UIT schakelaar wordt bewogen
#INT_EXT
void Ext_Isr ()
{
On_Off_State = input (AAN_UIT); // status aan / uit schakelaar
EXT_Debounce_Counter = 2; // begin debouncing
}
//*********************************** Main ***********************************//
//*********************************** Main ***********************************//
void MAIN ()
{ |
|
|
 |
Ttelmah Guest
|
|
Posted: Tue Jan 16, 2007 4:20 am |
|
|
Again, the problem of your 'adding' this problem to an existing thread, rather than launching a new one. The original posts were about a 18 chip, not a 16 chip.
Now, seriously, your interrupt handlers are damnably long. On the 16 chip, the edge of the first bank, is 0x7FF in the program memory. My guess, would be that something, is going over this boundary, and causing a problem with the bootloader present. Look to see if you can simplify what you are doing in the handler (both in terms of code volume, and tme involved...).
I'd suggest that you just run one software timer routine in timer_1, that perfoms the 32bit arithmetic, with the required 'wraps', to give seconds, and then do the tests inside this, for the individual counters being enabled, and handle their timers. Though 32 bit arithmetic is not 'too bad' inside an interrupt, it still takes about 20 instruction times, and adding up if all five routines trigger at once, you have something over 300 instructions in this interrupt alone, making it both large, and relatively slow. My suspicion is that with the bootloader present, one or more of the routines, is ending up having to perform a bank switch, and is becoming both larger, and slower as a result, leading to the problem. This is why it does not immediately occur, but takes a few characters.
Now, the number of characters you mention as the point where the problem shows, is suspiciously close to the size of your serial buffer. I'd again suggest altering the code for this. Either expanding the buffer to 16 characters, or if it will still be large enough, reducing it to 8. Then in the serial routine, instead of:
Read_Pointer = ( Read_Pointer + 1 ) % BUFFER_SIZE;
Use:
Read_pointer = (Read_pointer+1) & (BUFFER_SIZE-1);
The former, takes around 100 instruction cycles, and is relatively large. The latter takes only a handful of instructions, but will only work for 'binary' buffer sizes (8, 16 etc., characters).
Best Wishes |
|
 |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Tue Jan 16, 2007 4:35 am |
|
|
| Code: | | #define BUFFER_SIZE 64 |
That buffer is 64 bytes.
Another strange thing is that some variables do get changed after 3 X while loop. A flag is being set to false somehow and I don't know why.
I'll soon make a new topic.
edit:
| Quote: | Read_Pointer = ( Read_Pointer + 1 ) % BUFFER_SIZE;
Use:
Read_pointer = (Read_pointer+1) & (BUFFER_SIZE-1); |
that is exactly the same ROM code.. |
|
 |
|
|
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
|