Created Fri, 24 Apr 2015 20:12:57 +0000 by ATX John
Fri, 24 Apr 2015 20:12:57 +0000
Hey everyone,
I've been building an RC robot using an Arduino Uno to control my motor drives. My code begins with a 10 second calibration period to establish the neutral, maximum, and minimum pulse widths from the RC controller. On the Uno, this worked as expected. I recently hit the hardware I/O ceiling on the Arduino as I've tried to integrate more sensors, so I decided to switch over to a Max32 board that was laying around. Unfortunately, the Max32 doesn't seem to enter or exit calibration mode properly.
On the Arduino, here is the behavior that I'm seeing in sequence;
Replacing the Arduino with the Max32 gives me the following behavior in sequence;
I suspect that the true issue is that I'm somehow never entering calibration mode and that garbage calibration values are causing the strange behavior. I've simplified my code to the relevant sections for flow control into and out of the MODE_PROGRAM state I use for calibration;
void setup()
{
...
ulProgramModeExitTime = millis() + 10000;
gMode = MODE_PROGRAM;
}
void loop()
{
...
// Calibration mode, automatically entered on boot
if(gMode == MODE_PROGRAM)
{
...
if(ulProgramModeExitTime < millis())
{
ulProgramModeExitTime = 0;
gMode = MODE_RUN;
}
else
{
// Store calibration values
}
}
if(gMode == MODE_RUN)
{
// Motion code here
}
}
Am I missing something that is causing MODE_PROGRAM to exit early or never be entered in the first place? I'm using the latest release of MPLAB for compilation (0023, linux64 if that matters). Full code attached. Thanks in advance for any help!
Sat, 25 Apr 2015 08:47:58 +0000
Just had a power cut while looking over your code, and now I have to head out. I'll look in more detail later on tonight, but one thing that I notice is you don't have any default values to your static variables in loop(). You should give them a default value or they will start with who knows what.
Sun, 26 Apr 2015 00:55:36 +0000
What is the type of ulProgramModeExitTime? Probably should be a unsigned int (32 bits on a PIC32).
Jacob
Wed, 29 Apr 2015 00:50:31 +0000
Hey Jacob,
It's a uint32_t
Thu, 14 May 2015 03:33:28 +0000
John,
I took a look at your whole program, nothing stands out as to why its not working. You might trying to rolling back to version 20140316 of MPIDE. The latest was hastily put out to get support for MZ parts in the midsts of trying to get MPIDE upto Arduino 1.6.3 compatibility.
Jacob