I have a maple native, IDE 12 on windows.
I am attempting to read two servo signal inputs on pins 9 and 10. They are from a RC car receiver. The input is about 3.4vdc, with a pulse width of 1-2 milliseconds.
My method (perhaps incorrect) is to detect the rising edge of each pulse to start the timers, then detect the falling edge and read the timer value and store that in another variable.
I am just getting either garbage numbers or constant unchanging numbers. Am I approaching this correctly?
HardwareTimer SteeringTimer(1);
HardwareTimer ThrottleTimer(2);
volatile uint32 time_t;
volatile uint32 time_s;
volatile uint32 steering_input;
volatile uint32 throttle_input;
void setup()
{
Serial1.begin(9600);
pinMode(9, INPUT);
pinMode(10, INPUT);
SteeringTimer.setPrescaleFactor(720);
ThrottleTimer.setPrescaleFactor(720);
attachInterrupt(9, S_Rise, RISING);
attachInterrupt(9, S_Fall, FALLING);
attachInterrupt(10, T_Rise, RISING);
attachInterrupt(10, T_Fall, FALLING);
}
void loop()
{
delay(1000);
Serial1.print("Throttle: ");
Serial1.println(throttle_input);
Serial1.print("Steering: ");
Serial1.println(steering_input);
}
/**********************Functions**and**stuff****************************************************/
void S_Rise()//restart timers on interupt
{
SteeringTimer.setCount(0);
}
void T_Rise()
{
ThrottleTimer.setCount(0);
}
void S_Fall()//calculate servo input from time markers, output in (% * 10) ie 1000 = 100.0%
{
SteeringTimer.pause();
time_s = SteeringTimer.getCount();
steering_input = time_s;
steering_input -= 1000;
}
void T_Fall()
{
ThrottleTimer.pause();
time_t = ThrottleTimer.getCount();
throttle_input = time_t;
throttle_input -= 1000;
}