I think I might have a stack overflow problem or something similar in my firmware firmware. I am a new programmer and have never done SO, so I'm not sure if this is happening or not.
The firmware controls a device with a wheel that has magnets evenly spaced around it, and the board has a hall effect sensor that detects when a magnet is above it. My firmware controls the stepper amplifier and also checks the steps when monitoring the magnet sensor to determine if the wheel has stopped.
I use a timer interrupt on my chip (8 bits, 8057 acres) to set the output ports for motor control and for detecting a shutdown. The stall detection code looks like this:
StallDetector++;
if(PosSensor != LastPosMagState)
{
StallDetector = 0;
LastPosMagState = PosSensor;
}
else
{
if (PosSensor == ON)
{
if (StallDetector > (MagnetSize + 10))
{
HandleStallEvent();
}
}
else if (PosSensor == OFF)
{
if (StallDetector > (GapSize + 10))
{
HandleStallEvent();
}
}
}
, ISR . PosSensor - . MagnetSize - , . GapSize - . , .
, , "StallDetector > (MagnetSize + 10)", StallDetector, 220! , MagnetSize 35. , 46, - 220? .
- , ?
ISR
void Timer3_ISR(void) interrupt 14
{
OperateStepper();
TMR3CN &= ~0x80;
}
HandleStallEvent , ...
#pragma save
#pragma nooverlay
void HandleStallEvent()
{
PulseMotor = 0;
SetMotorPower(0);
MotorSpeed = LOW_SPEED;
SetSpeedHz();
ERROR_STATE = 2;
DEVICE_IS_HOMED = FALSE;
DEVICE_IS_HOMING = FALSE;
DEVICE_IS_MOVING = FALSE;
HOMING_STATE = 0;
MOVING_STATE = 0;
CURRENT_POSITION = 0;
StallDetector = 0;
return;
}
#pragma restore