-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Hello Christopher,
I would like to report a peculiar behaviour in setChannel(). I was trying to test the library without any analog signals in an Arduino Uno V3 and Arduino IDE 2.3.6. Simple code, just:
#include "PPMEncoder.h"
#define OUTPUT_PIN 10
void setup() {
ppmEncoder.begin(OUTPUT_PIN);
}
void loop() {
ppmEncoder.setChannel(0, 1500);
ppmEncoder.setChannel(1, 2000);
//delay(1);
}
The code just sets channel 0 to 1500, channel 1 to 2000. I monitored the output with an oscilloscope. All channels remained at the same neutral value (500us low + 500us high)!
After I uncommented the delay(1), it worked properly with the correct pulse widths. (500us low + 1000us high + 500us low + 1500us high +remaining channels).
Strangely enough, the below code worked properly without any delay()
void loop() {
ppmEncoder.setChannelPercent(0, 50);
ppmEncoder.setChannelPercent(1, 100);
}
Also, another test case. If the first channel is an analog channel as in the code below, the output is also correct:
void loop() {
ppmEncoder.setChannel(i,map((uint32_t)analogRead(0, 0, 1023, 1000, 2000)) ;
ppmEncoder.setChannel(1, 1500);
ppmEncoder.setChannel(2, 2000);
}
It seems that the small delay, either in the analogRead or with the map() within setChannelPercent(), or with the delay() function is necessary for things to work properly.
While I was writing this issue report and having some thoughts on the usage of variables in interrupt procedures, I changed line 17 of PPMEncoder.h from
int16_t channels[10];
to
volatile int16_t channels[10];
And it worked properly, without any additional delay()!
Thank you