Need help controlling hoverboard wheel with rc receiver

I am trying to control a hoverboard hub motor using an RC receiver, Arduino UNO R4 Minima, and a cheap speed controller.
RC receiver: Radiomaster R88
Speed controller: RioRand 350W 6-60V PWM DC Brushless Electric Motor Speed Controller with Hall

I was able to run the motor using just analog write and values from 0-255 and it was working as intended.
When I try taking the input of the rc receiver, use the map function, and analog write it does this weird stutter. Jumps speeds randomly and just isn't smooth motion for some reason.

Below is my code.

#define CH1In 2  //rc reciever to arduino
#define CH1Out 3  //arduino to speedcontroller
unsigned long duration; //pwm from rc reciever
int escvalue; //pwm value for analogwrite function for speed controller

void setup() {
Serial.begin(115200);
pinMode(CH1In, INPUT);
pinMode(CH1Out, OUTPUT);
}

void loop() {
duration = pulseIn(CH1In, HIGH);
escvalue = map(duration, 1000, 2000, 0, 255);
analogWrite(CH1Out,escvalue);
}

Below is my wiring

I've used serial.print on both duration and escvalue and they seem right to me but I don't know what I'm missing.

Help would be much appreciated!!

If pulseIn times out, duration will be 0, resulting in setting escvalue to -255, which analogWrite converts to 1 (which is the same result that you would have obtained if duration jumped to a value in the range 10041007).

Is there a way to verify that it's doing that?
Any workarounds or better commands for reading the receivers PWM signal?

Sorry super new to the Arduino world.

There is probably a better way to capture duration (but I do not know it), but you could keep the output from jumping out of bounds with "constrain()"

if (duration == 0) {
   Serial.println("WARNING: pulseIn() time-out!");
}

I did this and there was no time out warning in the serial monitor, still looked normal.

And the speed was still stuttering in those tests (when you did not see any time-out warning)?

In that case, add the following after your map() statement:

escvalue = constrain(escvalue, 0, 255);

Constraining helped shut the motor off at zero, but still having weird pulses/jitters.

Can you Serial.print() those values, then put those values in a spreadsheet to graph them (INSERT >> CHART >> LINE), which may show a trend and help find the solution?

You can further constrain these values so "0" is never in the motor drive equation, try something very different, like the following... and observe if "jumpy" still happens.

escvalue = constrain(escvalue, 100, 150);
`

That is correct.

I constrained the duration value before the map. That should do the same thing right?
My new void loop is

void loop() {
duration = pulseIn(CH1In, HIGH);
durationcon=constrain(duration,1000,2000);
escvalue = map(durationcon, 1000, 2000, 0, 255);
analogWrite(CH1Out,escvalue);

Serial.print(durationcon);
Serial.print("  ");
Serial.println(escvalue);
if (duration == 0) {
   Serial.println("WARNING: pulseIn() time-out!");
}
}

Test with current code to show stuttering motor

Took a video to show what it's doing.

If I only do analogWrite with specific values it works fine. So it's something with either the pulseIn or map I'm assuming.

That looks "good". Have you checked the hall sensors for missing glue or looseness?

Have you tried switching any two phase (power) wires?

I have checked them. It run fine with the built in potentiometer on the speed controller and just using straight up analogWrite from the Arduino. It's something to do with the rc receiver input/mapping. I tried a different receiver and it's doing the same thing.

map() looks good. pulseIn() is a mystery to me. I like to blame the things I do not understand. : ) (kidding - but it makes me feel better). Trying to find if pulseIn() is the cause...

Arduino says pulseIn() wants int values for pins, so change the #defines to ints... https://docs.arduino.cc/language-reference/en/functions/advanced-io/pulseIn/

Maybe the transmitter, then?

New discovery. I have been powering the arduino via the Vin pin with a 4S battery. I tried running it while plugged into the computer via USBC to check the values real time, and it was working as intended. I wonder if I was hitting some kind of current limit, or if there is some inefficiencies with vin dropping voltage to 5V. Guess I'm gonna go find a BEC and power it with the same battery but can plug into USBC.

I think VIN wants > 7.5VDC. Is your 4S = 4 x 4.2 or 4 x 3.7?

Fully charged is 4.2v per cell, but this one is probably around 3.7 as it was sitting at storage voltage when I started using it. It says that it supports voltage up to 24v on the product page. Might have a 2S battery around that I can try. I tried a 3S and it was doing the same thing. I'm also using the pin cables and header on the board to connect the battery. Wonder if that's a bad way to connect it.

I wonder if the load on the battery is not enough to let the battery management know it is being used?

Ebikes have two levels of auto-shutoff. The first level is "sleep" after a few minutes when the system is left ON with the display and any peripheral actively draining power. Eventually, the BMS will go to a deeper sleep when activity has not occurred for perhaps two weeks.