chipKIT® Development Platform

Inspired by Arduino™

Strange timing behavior migrating from Arduino Uno to Max32

Created Fri, 24 Apr 2015 20:12:57 +0000 by ATX John


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;

  1. Robot and Arduino are powered on
  2. Arduino enters calibration mode, controls are actuated for measurement.
  3. Arduino remains in calibration mode for full programmed duration of 10 seconds.
  4. After 10 seconds has expired the RC transmitter is used to send commands which the robot executes as expected.

Replacing the Arduino with the Max32 gives me the following behavior in sequence;

  1. Robot and Max32 are powered on
  2. Max32 enters some kind of waiting mode, controls are actuated for attempted calibration
  3. Approximately 4-5 seconds later, the motor drives begin to command each wheel to spin at full speed in opposite directions.
  4. Commands issued by the RC transmitter have no discernible effect on the wheels spinning, robot must be stopped by removing power.

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!


majenko

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.


Jacob Christ

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


ATX John

Wed, 29 Apr 2015 00:50:31 +0000

Hey Jacob,

It's a uint32_t


Jacob Christ

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