Teensy code is working but seems to stop running after a few minutes
The project is to convert a G guage electric loco from track dc power to battery + rc control
Goals include
* Motor control speed and direction
* Motor current monitoring for safety and as an input to sound routines
* Sound (not yet implemented)
* chuff driven by some combination of motor load axle sensor
* playable simulated whistle by rc
* bell and other thematic sounds (all aboard etc) from wav files on the sdcard plan is to use a pt8211 board
Current hardware setup is:
PPM from a orangeR610X to pin 23 using pulse position
Teensy 3.5
pins 33-35 are connected to a L298N motor driver. with 35 being pwm enable
The Teensy seems to stop executing code after a period of time. I'm wondering if it's a stack crash or something but it's all quite small. I have the following sketch running on a Teensy 3.5 programming using teensyduino:
Help or advice on how to determine what's going on would be greatly appreciated.
The project is to convert a G guage electric loco from track dc power to battery + rc control
Goals include
* Motor control speed and direction
* Motor current monitoring for safety and as an input to sound routines
* Sound (not yet implemented)
* chuff driven by some combination of motor load axle sensor
* playable simulated whistle by rc
* bell and other thematic sounds (all aboard etc) from wav files on the sdcard plan is to use a pt8211 board
Current hardware setup is:
PPM from a orangeR610X to pin 23 using pulse position
Teensy 3.5
pins 33-35 are connected to a L298N motor driver. with 35 being pwm enable
The Teensy seems to stop executing code after a period of time. I'm wondering if it's a stack crash or something but it's all quite small. I have the following sketch running on a Teensy 3.5 programming using teensyduino:
Code:
#include <PulsePosition.h>
// ppm channel order for dsm2/dsmx
#define AILCHAN 1
#define ELECHAN 2
#define THRCHAN 3
#define RUDCHAN 4
#define AUXCHAN 5
#define GEARCHAN 6
//pin definitions for motor control
#define MCDIR1 33 // connected to inA 1
#define MCDIR2 34 // connected to inA 2
#define MCPPM 35 //connected to L298 inA enable
int8_t numchans=0; // number of channels + 1
float rcvals[7]; // The orange R610x only outputs 6 channels if we change to frsky this will need to be 17.
// Create PulsePosition and define a pin for the RX
PulsePositionInput myIn;
#define RCPPMINPUT 23 // recieves PPM from Orange R610x
void setup() {
myIn.begin(RCPPMINPUT);
pinMode(MCDIR1, OUTPUT);
pinMode(MCDIR2, OUTPUT);
}
void getrcvalues() {
// Every time new data arrives, store it in an array
// to the Arduino Serial Monitor.
uint8_t num = myIn.available();
// Check if there is new data
if (num > 0) {
numchans = num;
for (int8_t i = 1; i<=numchans; i++) {
rcvals[i] = myIn.read(i);
};
};
}
void printrcvalues() {
//only print if we have data.
//Serial.println(numchans);
for(int i=1; i<=numchans; i++){
Serial.print("\t");
Serial.print(rcvals[i]);
};
Serial.println();
}
void controlmotor(int8_t dir, uint16_t speed) {
switch (dir) {
case 1: // set forward
analogWrite(MCPPM, speed);
digitalWrite(MCDIR1, HIGH);
digitalWrite(MCDIR2, LOW);
//Serial.println("GOING FORWARD");
break;
case 0 : //set stop
analogWrite(MCPPM, 0);
digitalWrite(MCDIR1, HIGH);
digitalWrite(MCDIR2, LOW);
//Serial.println("GOING FISHIN'");
break;
case -1 : //set reverse
analogWrite(MCPPM, speed);
digitalWrite(MCDIR1, HIGH);
digitalWrite(MCDIR2, LOW);
// Serial.println("GOING BACkWARD");
break;
default ://set stop
analogWrite(MCPPM, 0);
digitalWrite(MCDIR1, LOW);
digitalWrite(MCDIR2, LOW);
//Serial.println("GOING NOWHERE");
break;
}
}
void loop() {
getrcvalues();
//Decode the aux channel and use it to set direction
int8_t motdir;
if (rcvals[AUXCHAN]>1800)
motdir=1;
else if (rcvals[AUXCHAN] <1300)
motdir = -1;
else
motdir = 0;
float throttle = (rcvals[THRCHAN]-1110)/3.34;
controlmotor(motdir, throttle);
if (false) {
printrcvalues();
Serial.print(motdir);
Serial.print(" ");
}
// Serial.print(rcvals[THRCHAN]);
// Serial.print(" ");
// Serial.println(throttle);
}
Help or advice on how to determine what's going on would be greatly appreciated.