Hi,
I am trying to read a pwm signal from a flight controller that comes through hardware interrupts on pin 2 of an arduino uno and the signal comes through clean and all working until I try to drive a IBT_2 BTS7960 with a remapped value of the input signal, the input signal becomes messed up and starts spiking up and down rapidly and reading very large incorrect readings. at first I though it was interference from the motors but I shielded the wires and then even tested just driving the motors at full speed with one Arduino while reading the signal with another and it was fine any help would be appreciated
Here is the code:
#define RCPin 2
volatile long StartTime = 0;
volatile long CurrentTime = 0;
volatile long Pulses = 0;
int PulseWidth = 0;
volatile int MOL = 0;
int MOR = 0;
int L_PWM = 6;
int R_PWM = 5;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(RCPin, INPUT_PULLUP);
pinMode(5, OUTPUT);
pinMode(9, OUTPUT);
attachInterrupt(digitalPinToInterrupt(RCPin), PulseTimer, CHANGE);
}
void loop() {
// put your main code here, to run repeatedly:
if(Pulses < 2000){
PulseWidth = Pulses;
delay(50);
}
MOL = map(PulseWidth, 1100, 1900, 0, 255);
if(PulseWidth >= 1100 && PulseWidth <= 1900){
MOL = map(PulseWidth, 1100, 1900, 0, 255);
}
Serial.println(MOL);
if(MOL > 10){
analogWrite(R_PWM, 0);
analogWrite(9, MOL);
}
}
void PulseTimer(){
CurrentTime = micros();
if(CurrentTime > StartTime){
Pulses = CurrentTime - StartTime;
StartTime = CurrentTime;
}
}
Sounds like a power supply problem. Please post a schematic diagram of the system, along with a link to the motor data sheet and the motor power supply.
Keep in mind that motors briefly draw the stall current (5-10x the rated current) every time they start moving, and shielding won't help if the voltage sags.
@jremington Sorry for late response I do not have a direct schematic, but the motor controllers that power and controll the motors are connected to an 18v ryobi battery, the arduino and the flight controller I am reading the pwm signal from are connected to power through my computer currently and also can take power through 9v batteries. Here is the motor datasheet: https://nfpshop.com/wp-content/uploads/2022/02/24V-Dc-Worm-Gear-Motor-5840-31Zy-Spec.pdf