Hello all and thanks for reading my question
I have this code t.every(5000, doSomething);
doSomething is actually a function in the code, the 5000 is a value from memory.
My problem is that the Arduino dumps out a pulse generated in doSomething every 5 seconds as predicted for a while. However, after some period of time, within 24 hours it changes from the 5 seconds to a minute.
does anyone have any experience with a problem like that?
jurs
May 8, 2015, 6:26pm
3
rr1024:
My problem is that the Arduino dumps out a pulse generated in doSomething every 5 seconds as predicted for a while. However, after some period of time, within 24 hours it changes from the 5 seconds to a minute.
does anyone have any experience with a problem like that?
In programming and information security, a buffer overflow or buffer overrun is an anomaly whereby a program writes data to a buffer beyond the buffer's allocated memory, overwriting adjacent memory locations.
Buffers are areas of memory set aside to hold data, often while moving it from one section of a program to another, or between programs. Buffer overflows can often be triggered by malformed inputs; if one assumes all inputs will be smaller than a certain size and the buffer is created to b...
Looks like "a problem like that" is as old as the invention of programmable microcontrollers/microprocessors.
Timer t;
int tickEvent;
unsigned int FR_INTERVAL;
unsigned int P_WIDTH;
unsigned long seconds;
unsigned int minutes, hours, days, secs_left, mins_left;
void setup()
{
digitalWrite(OP_SHDN_L, OP_OFF);
pinMode(Debug_IO11, OUTPUT); //Debug IO13 pin 18
digitalWrite(Debug_IO11, LOW); //Debug IO13 pin 18
pinMode(Strobe_Out, OUTPUT);
digitalWrite(Strobe_Out, LOW);
analogReference(INTERNAL);
analogRead(BATT_PIN[0]);
LoadSettings();
Serial.begin(19200);
attachInterrupt(1, PulseMode, RISING );
state = mIDLE; //mIDLE
interrupts();
[b]tickEvent = t.every(FR_INTERVAL, doFreeRun);[/b]
}
/*
* loop()
* Desc - ?
* exeTime ~38uSec
* return - void
*/
void loop() {
char keypress;
int idx;
//digitalWrite(Debug_IO11, LOW); //Debug IO13 pin 18
//Serial.print("state in ");
//Serial.println(state);
//jumper not installed
if (digitalRead(FREE_RUN)){
if (state == FREERUN){
state = mIDLE;
digitalWrite(OP_SHDN_L, OP_OFF);
//Serial.println("enter state mIDLE"); //Debug
}
}else{
if ((state == mIDLE) & !SERCONTROL){
state = FREERUN;
digitalWrite(OP_SHDN_L, OP_ON);
//Serial.println("state mIDLE Entering FREERUN"); //Debug
}
}
//if the cal jumper is in place, draw the menu
if (!digitalRead(CAL_MODE)){
if (state != CALMENU){
state = initCALMENU; //cal mode
//Serial.println("state initCALMENU"); //Debug
}else{
state != CALMENU;
//Serial.println("state CALMENU"); //Debug
}
}
if (Serial.available() > 0){
keypress = ckSerialIn( Serial.read() ); //Serial.read(); //rev 1.5
//if (keypress == 'F'){
// SERCONTROL = true;
// }
if (!SERCONTROL){
//Serial.println(state); //Debug rev 1.5
//Serial.println(SERCONTROL); //Debug rev 1.5
//Serial.println(keypress); //Debug rev 1.5
Serial.println("Timer Stopped");
Serial.println("cmd R, S or I");
}
SERCONTROL = true;
t.stop(tickEvent);
state = mIDLE;
digitalWrite(OP_SHDN_L, OP_OFF);
//keypress = Serial.read(); //rev 1.5 moved to serial available() above
switch(keypress){
case ('R'): //resume rev 1.3
Serial.println("Freerun Started");
[b] tickEvent = t.every(FR_INTERVAL, doFreeRun); [/b]
state = FREERUN;
digitalWrite(OP_SHDN_L, OP_ON);
SERCONTROL = false;
pinMode(Background, ENABLE); //Pre //rev 1.4
digitalWrite(Background, HIGH); //rev 1.4
break;
case ('S'): //reset arduino stats rev 1.3
Serial.println("Reset Stats");
//reset usedCapacity to 0.0
for (idx = 0;idx < 8; idx++){
battery[idx].usedCapacity = 0.0;
}
cycles = 0;
break; //rev 1.2 added missing break
case ('I'): // get cal and status info rev 1.3
doPrintCalib();
break;
}
}
switch (state){
case (initCALMENU): //Hardware selected Jumper
delay(200);
LoadSettings();
clearAndHome();
drawCalMenu(0);
state = CALMENU;
digitalWrite(OP_SHDN_L, OP_OFF);
break;
case CALMENU:
serviceCalMenu();
break;
case mIDLE:
break;
case PULSE: // pin input trigger
doFreeRun();
delay(10); //100ms debounce/holdoff
state = mIDLE; //wait for the next trigger
break;
case FREERUN: //timer trigger
t.update();
break;
}
//digitalWrite(Debug_IO11, LOW); //Debug IO13 pin 18
}
/*
* doFreeRun()
* Desc - ?
* exeTime ~624mSec W/ doStatusDraw();
* return - void
*/
void doFreeRun()
{
String stringOne;
String stringTwo;
String stringThree;
unsigned long time;
int idx;
float voltage;
float ESR;
//digitalWrite(Debug_IO11, HIGH); //Debug IO13 pin 18
//char keypress;
//Pulse the external strobe pin to trigger the external DAQ module
pinMode(Strobe_Out, ENABLE); //Pre //rev 1.4
digitalWrite(Strobe_Out, HIGH); //rev 1.4
delay(500);
digitalWrite(Strobe_Out, LOW); //rev 1.4
delay(10);
cycles++;
readbatteries(); //Get the background voltages
for (idx = 0; idx < 8; idx++){ //copy the background voltages
battery[idx].backVolt=((float)batteryADC[idx]/1023.0*2.54)/10.0;
}
pinMode(Background, DISABLE); //rev 1.4
digitalWrite(Background, LOW); //disable internal pullup //rev 1.4
pinMode(spare, ENABLE); //pulse on spare //rev 1.4
digitalWrite(spare, HIGH); //rev 1.4
time = millis();
//delay(P_WIDTH-10); //1 second load minus the ADC time
while(millis()<(time+P_WIDTH-15)); //wait for pulse
readbatteries(); //Get the loaded values routine takes 11.2ms to complete
while(millis()<(time+P_WIDTH)); //wait for pulse
pinMode(spare, DISABLE); //rev 1.4
digitalWrite(spare, LOW); //disable internal pullup //rev 1.4
pinMode(Background, ENABLE); //Pre //rev 1.4
digitalWrite(Background, HIGH); //rev 1.4
if (mBlink == 1){
digitalWrite(LED,HIGH);
}else{
digitalWrite(LED,LOW);
}
mBlink = !mBlink;
[b]seconds = FR_INTERVAL/1000L; //units of seconds[/b]
for (idx = 0; idx < 8; idx++){ //compute the load voltages and ESR
battery[idx].loadVolt=((float)batteryADC[idx]/1023.0*2.54)/10.0;
voltage = battery[idx].backVolt - battery[idx].loadVolt; //voltage difference
battery[idx].ESR = voltage/((channel_Cal[idx].pulseCurrent - channel_Cal[idx].backCurrent)/1000000.0);
[b]battery[idx].usedCapacity += (channel_Cal[idx].backCurrent/1000.0) * ( (float)(FR_INTERVAL - P_WIDTH) / 3600000.0) ; //sum of background current (in mAHr)
battery[idx].usedCapacity += (channel_Cal[idx].pulseCurrent/1000.0) * ((float)P_WIDTH / 3600000.0); // sum of pulse current (in mAHr)[/b]
}
//digitalWrite(Debug_IO11, HIGH); //Debug IO13 pin 18
doStatusDraw(); //Output battery data to terminal
//digitalWrite(Debug_IO11, LOW); //Debug IO13 pin 18
}
I imagine the compiler doesn't like the [b] [/b]
in the middle of the code.
OMG, really...lol I thought it would bold the important parts for you but I guess this forum doesn't do that...
I did mention the Arduino was running which means the bolds could not have been there since it wouldn't compile ...lol
So how would I go about preventing buffer overflow, although I guess this is more of a memory overflow or something.
So how would I go about preventing buffer overflow
Don't write beyond the end of the buffer you have allocated. That's hardly a difficult concept to grasp.
Sorry but I'm new to embedded programming, I don't see anywhere that I have written anything beyond any buffer...lol
How do I control the buffer or how do I know it's bounds or evey where it is in my code?
system
May 8, 2015, 10:41pm
10
rr1024:
Sorry but I'm new to embedded programming, I don't see anywhere that I have written anything beyond any buffer...lol
How do I control the buffer or how do I know it's bounds or evey where it is in my code?
analogRead(BATT_PIN[0]);
Where did THAT array come from?
Why would you read a book blindfolded? If you don't care what the value is, why bother?
SERCONTROL = false;
By convention, all capital letter names are reserved for constants. Constants NEVER appear on the left of an equal sign, except when getting an initial value.
battery[idx].usedCapacity = 0.0;
Where did THAT array come from?
delay(500);
digitalWrite(Strobe_Out, LOW); //rev 1.4
delay(10);
In an interrupt service routine? There isn't a hope in hell of THAT working.
Posting code that won't even compile, and then claiming that it works "for a while" wastes everyone's time.