motor control center 0

Hi peeps. I'm struggling with a project i really want out the way and hoped i could call upon the genius f the Arduino community.

I have been given an old RC car running from an old style TX/RX @ 27MHZ. Iv'e always wanted to get my head around programming so thought this project would be ideal as a learning curve. Ive got the outputs from the RX module through a LPF to clean up the signal and straight into pin 9 +10 of the Arduino. The thing giving me a headache is i cant seem to get a symmetrical pwm output too control the motor MosFet. Pretty much want 255, 0, 255 when mapped from the serial value coming from PWM input from the RX.
I know i need to use 'If' with two 'map' but just cant get my head round it. So in black and white (0, 1023) would equal to (255, 255) but would drop to 0 half way through the sweep. so when the stick on the controller is resting (in the center) the output would be zero and would move towards 255 when moving the stick closer to both extremes.

iv'e already gotten lights and a reverse polarity relay to trigger in the right places. its just this center zero pwm output that's totally eluded me.

i do have a second problem, but i can wok around it and don't want to over stay my welcome on here. i really appreciate any help anyone can give me. and i hope once iv'e learned a bit more, i can contribute back to the community.

i already have a background in electronics, iv'e just always avoided anything to do with programming. and i realize this is such a trivial problem for most Arduinists, but i am really new and learn better from people rather than tutorials (which i tried first bBTW, tried everything before this but due to a learning disability i cant absorb the information that way)

even if no one replies to this post i really appreciate you reading it. thank you all in advance.

BTW, i love this site and the projects people make!! there's almost no one here i can talk t about this stuff and it feels great to talk to people who understand what your saying!!!

I'm running Arduino UNO.

Something like:

signalOut = abs(512 - signalIn);

?

Hi Outsider, Not sure what ‘abs’ is as not need to use it yet. Let me just read up on it.

Thanks so much for replying. I’m sure yuve hit the nail on the head straight away, but need to see what ‘abs’ is first so i’m on the same page.

Two ticks…

Just had a quick read on it. Am i right in thinking 'abs' can change a (-) number to a (=) one? so i can take

val = map(val, 0, 1023, -255, 255)

and it will output a 0 at 512 and 255 at either 0 or 1023?

No, with that, a 0 in will produce a -255 out and a 1023 in will produce a 255 out.

Also, no number has any (=) attribute. What on earth do you mean?

I think i need to read up on it before i look like an absolute baffon and waste everyones time.

abs means absolute number (sign is ignored), abs(-512) = 512.

signalOut = abs(512 - signalIn) / 2;

aarg:
No, with that, a 0 in will produce a -255 out and a 1023 in will produce a 255 out.

Also, no number has any (=) attribute. What on earth do you mean?

the (=) was meant to be a plus sign. many apologies aarg. i really need a new keyboard lol the shift key isn't the best (neither is my typing)

the message was supposed to read (although i already know i was wrong anyway).....

"Just had a quick read on it. Am i right in thinking 'abs' can change a (-) number to a (+) one? so i can take

val = map(val, 0, 1023, -255, 255)

and it will output a 0 at 512 and 255 at either 0 or 1023?"

I know now that it was wrong anyway but at least that might clear up my mistake.

Hi,

Write a simple bit of code using the abs example with your joystick and output it to the serial monitor.

That way you can see your joystick input values and your PWM duty cycle values and see how it works.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Hi Tom. I'd be more than happy to share my circuit with as man annotations as i can make. But i will have to wait until tomorrow as its too late at the moment and i have t be up at 5am lol. Thanks everyne for your replies so far . i know i've frustrated a few of you as this seems so simple for a lt of you but i really am just a beginner in every sense of the word. i could have gone the analogue route or even digital with cmos but really wanted to get this right and learn a valuable skill.

i will post a circuit diagram tomorrow and in the meantime lok up more about some functions and get a better handle on things..

night night guys n gals. :slight_smile: