MAP Command Questions

Status
Not open for further replies.

dereckbc

Well-known member
OK I want to read an Analog 0 to 3.3 volts or perhaps 0 - 5.0 volts if there is an advantage, and scale that voltage to 0 - 1000 micro-seconds for a PPM Encoder. I have read the MAP command and believe I understand it correctly and should look something like:

map(0, 1023. 0, 1000) Correct?

The 0 to 1023 is for a 10 bit resolution. Correct me if I am wrong but I am using a Teensy 3.2, does that mean I can also declare 11 bit or map(0, 2047, 0, 1000)?

Is there any benefit or consequences using 0-5 volt analog input?

THX
 
Last edited:
5V only safe to connect to a T_3.2 digital pin - but anything over 3.3V will read as full scale resolution so no point unless you drop the voltage.

IIRC - map(0, 2047, 0, 1000) usage looks to be correct
 
FYI Map function takes 5 parameters (https://www.arduino.cc/en/Reference/Map).

so yes your map val = map(input_val, 0, 1023, 0, 1000) will map your values. Or maybe you need the order reversed (map(input_val, 0, 1023, 1000, 0) if your slider or knob is going in the opposite direction than you wish the values to be. Or maybe if you need the values to be centered on 1500, it might work like:
map(input_val, 0, 1023, 1000, 2000)... Again depending on what values you need

Kurt
 
FYI Map function takes 5 parameters (https://www.arduino.cc/en/Reference/Map).

My bad syntax kicks my newb butt. Here is the real line of code I use:

AI_AEL = map(AI_Raw_AEL, 0, 1023, 0, 1000) + AelTrim;

so yes your map val = map(input_val, 0, 1023, 0, 1000) will map your values. Or maybe you need the order reversed (map(input_val, 0, 1023, 1000, 0) if your slider or knob is going in the opposite direction than you wish the values to be. Or maybe if you need the values to be centered on 1500, it might work like:
map(input_val, 0, 1023, 1000, 2000)... Again depending on what values you need

Kurt

Thanks Kurt and all. I get it. The reason I ask is I have read Scaling may not work like one suspects. Example one reference I see is map(val, 0,1023, 0, 255) does NOT give you 1 click output with 4 clicks input as one would assume. Am I reading old Arduino history or is there some truth to it?

Would perhaps scaling to 12 or 13 bits input work better, or just wasting time? I can live with 1023 us or 1:1 ratio. I can shave 23 us off with my pulse limit check sub if needed. all it would do is slightly over drive a servo 2.3% which is rare to ever go to extremes except throttle.

To bad it cannot take a 0-5 volt analog scale. I am an EE and what we learned is to measure with a micrometer, mark it with chalk, and then cut it with an ax. So the larger the piece, the more accurate it is and more likely to work.

Perhaps this might help you help me. My objective is 1 us resolution as that is as good as it gets for a radio controlled model PPM Encoder. I am using 6-channels. Each channel pulse is a min of 1000 us, max 2000 us, and a Frame rate of 20,000 us. Minimum Frame Space is 6000 us allows up to 7 channels on a 50 Hz Frame
 
Last edited:
The compiler would have told you about the missing in val.

You could run a simple for() loop over the map() range of interest to see its behavior.

How sensitive do staying steady or jittering should it be? If you have 1000 points and 1000 values - any change would be a movement. If you had 4095 or 8191 for 1000 points you could safely adjust up or down and have some built in room to ignore small changes but still hit every point.
 
The compiler would have told you about the missing in val.
It was just a brain fart when queried here.

You could run a simple for() loop over the map() range of interest to see its behavior.

Greek to this newb.

How sensitive do staying steady or jittering should it be? If you have 1000 points and 1000 values - any change would be a movement. If you had 4095 or 8191 for 1000 points you could safely adjust up or down and have some built in room to ignore small changes but still hit every point.

I am looking at adding some sort of SMOOTHING. I am trying to figure out how to work it in. or where to insert it.

I have no problem scaling up to say 11 to 13 bit input if there are no consequences. For some reason I seem to remember it takes a lot more time for the A/D for each bit added. At some point that has to have consequences on how many scans you can scan and still be useful if true.

I got the thing working and testing on scope. Now it is fine tuning.
 
Just for grins what would this do?

map(val, 0, 1000, 0, 1000);

Or do you have to use all the input bits set to 1111111111 aka 1023?
 
Status
Not open for further replies.
Back
Top