I want to fit an analog signal with variable resistance. Help me!

Hello, I am a college student who is coding using the Aduino program!
To measure the angle of the step motor, the angle of the step motor was printed on the serial monitor according to the level of the variable resistance, using the variable resistance to rotate the step motor when the step motor rotates due to

The problem is that the variable resistance is the same between 0º and 20º and 250º to 270º. (This is the angle measured by the protractor).
And analog signals are not ideal waveforms...
The professor at my university told me I had to fitting.

I've been Googleing a little bit about fitting, and I've noticed that polynomial curve fitting is MATLAB.
MATLAB is used only for analysis and is asked to try with C...
If you know how to do it, please answer me.

I think there are a lot of words that I don't understand because I am using a translator.
If you don't understand, please reply.

i want analog signal , fitting
Thank you for reading it.

tjdwls:
Hello, I am a college student who is coding using the Aduino program!
To measure the angle of the step motor, the angle of the step motor was printed on the serial monitor according to the level of the variable resistance, using the variable resistance to rotate the step motor when the step motor rotates due to

The problem is that the variable resistance is the same between 0º and 20º and 250º to 270º. (This is the angle measured by the protractor).
And analog signals are not ideal waveforms...
The professor at my university told me I had to fitting.

Sorry but I cannot create a picture in my mind of what you are trying to do.

Maybe there is a language section of the Forum for your first language?

if you do wish to continue here then a diagram showing the project might help with understanding. It would also help if you describe the complete project so we can understand the context of your questions.

For example I can't figure if you are turning a potentiometer by hand to indicate the angle for the stepper motor to move or whether the moving motor is itself turning a potentiometer to provided feedback about its position.

I don't understand the reference to analog signals. Stepper motors use digital signals.

What do you mean by "fitting"?

...R

"Fitting" is adjusting the values in a polynomial until it produces a curve matching the accumulated data.

I think it has to do with statistical analysis, in which I have absolutely no interest!

Paul

Paul_KD7HB:
"Fitting" is adjusting the values in a polynomial until it produces a curve matching the accumulated data.

If this was a law court you would be accused of putting words in the witness's mouth :slight_smile:

The OP has given no indication that there is data to which a curve might be fitted, or for what purpose that technique might be needed. I was hoping s/he would enlighten us.

...R

Actually this quote: "The problem is that the variable resistance is the same between 0º and 20º and 250º to 270º. (This is the angle measured by the protractor).
And analog signals are not ideal waveforms...
The professor at my university told me I had to fitting.", told me he has a bunch of values that do not fit his ideal waveform and he wants to derive an equation that he can program to modify his analog readings to allow them to look like the ideal waveform.

I, too, am waiting for clarification.

Paul

Thank you for your answer. I think the translation was wrong. What I’m trying to do is not matter what kind of signals the stepper motors use. The step motor was coded so that it rotated one step per second.

I have a step motor and variable resistance. When the motor rotates, the variable resistance will also rotate.
The number of variable resistance will vary depending on how much the motor is running.

The variable resistance figure originally ranges from 0 to 1023, but was changed from 0 to 270, using the map function.
As the motor rotates, the variable resistance reading changes and the serial monitor succeeded in receiving the value.
However, when the variable resistance angle is between 0 and 20 degrees, the value remains unchanged from 0 and is between 250 and 270 degrees, and it is also fixed at 270 degrees.
I want to solve these things.

Do I need to use an oscilloscope?

If you can’t fix it by fitting, is there another way?

Thanks for reading it!

Image from Reply #5 so we don't have to download it. See this Simple Image Posting Guide

...R

I can't figure out what you want to "fix it by fitting". What outcome do you want to achieve?

My advice would be to get a better quality potentimeter - maybe get a multi-turn potentiometer.

Also I think you should do your calculations with the higher resolution 0-1023 rather than mapping to a smaller range.

...R

PS ... the gearbox in a 28BYJ-48 stepper motor has a lot of backlash - I wonder is that what is giving rise to the strange numbers?

The angles which you describe at the end of the potentiometer range are where the wiper in the potentiometer is not running on the resistance tracks, but on the conductive metal end pieces which are used to connect to the resistance element so the resistance does not vary. This is just how the variable resistor is constructed.

It may be possible to find a variable resistor which is constructed differently, but it will be difficult.

The suggestion of using a multi-turn (generally ten turn) potentiometer might be of some use to you but then the whole 360º of a single turn would be mapped to only one tenth of the resistance range and you would lose 90% of your resolution.

You need to explain just why you want to know the angle of the stepper motor and as part of that explanation, just what total angle you wish to measure?

Thank you for your answer.
I actually don't know the reason for fitting...The professor of department told me I had to get fitted, so I thought it would work out if I just got fitted.

Get a better quality potentiometer...You want me to change the variable resistance?
If not, do you know the difference between variable resistance and multiple turning potentiometers?

Map 0 to 27000. The reason why 270 multiplied by 100 wanted to measure the angle of the step motor to the decimal point.
I don't know if mapping is possible in numbers higher than 1023.
But when I checked with the serial monitor, it looked like there was nothing wrong.

I didn't think step motors were a problem. I thought there was a problem with variable resistance. Am I wrong?

It appears you have not followed my explanation.

And we still do not understand what it is you are expecting to do. :astonished:

The variable resistance figure originally ranges from 0 to 1023, but was changed from 0 to 270, using the map function.

That is a mistake do not do it. Trying to correct any non linearity after that is going to fail because you have thrown away all your resolution.

As pointed out a normal pot will not work anyway. You can get conductive film continuously rotating pots designed for servos. R.S. Electronics from the UK stock them but they are not cheap.

Normally a rotary Encoder is used for this sort of thing. However these will normally be of a lower resolution than your motor steps. If I had to do this I would use a 10 bit Hall effect absolute rotary encoder, this will require a special type of magnet on the end of the motor and a separation distance of a mm or so. This is much cheaper than the rotating pots.

Grumpy_Mike:
As pointed out a normal pot will not work anyway.

[…]

Normally a rotary Encoder is used for this sort of thing.

The problem I have is that we have no idea what “this sort of thing” is in this case.

For example if the OP is content for the motor to move within the normal operating range of a standard potentiometer then it should be fine. On the other hand if he wants a greater range why is he using a standard pot in the first place - presumably his professor has seen his apparatus.

From Reply #9 it seems that the OP himself has no idea what is the purpose of “fitting”

…R

[made some small edits to add clarity]

the photo shows a stepper motor and a potentiometer.
the potentiometer is also called a pot.

the pot you have moves from 0 to 270 degrees.
the pot is connected to 5v, to ground, and connected to an analog pin.
the output is a voltage between 0 and 5volts

when I look at the picture, I see the stepper motor shaft and the pot shaft are not connected.
a 'fitting' can be a mechanical thing. for this picture, it could be a shaft coupler.
a shaft coupler could be some plastic tubing. or it could be a metal part.

when you say that the output of the pot. I think of the input voltage.
270 / 1023 = 0.2040 volts per step.
270 / 1024 = 0.26367 volts per step
[ you may not get any reading for some of the steps, so you might need to adjust for the parts you have ]

when we look at a graph, we would expect that to be a straight line.
you said that the output does not have much change from over 250 degrees to 270 degrees
and that there is not much change under 20 degrees to 0 degrees

it is not uncommon to have errors from the straight line.

for you to map the curve, I would offer that you set the stepper so that the pot is at 0
move the stepper 1 step and record the output
move the stepper 1 more step and record the output
record the output for each step from 0 to 270
repeat this from 270 down to 0
save the data.

you can use a serial print to the Arudino IDE serial monitor
then highlight all and copy and paste to a spread sheet.

do this 4 or 5 times.
make a graph to see the error.

FITTING
someone said that the word 'fitting' might have to do with using correction factors to make the curve with errors into a straight line.
If you want to get the raw output of the pot.
and you want to correct the curve to make it a straight line.
Please let us know.

please also note that there are forums for other languages. go to the forum list and scroll all the way down.

please tell us your native language. we may be able to help you find others who can help faster.

this is a poor picture of tubing as a shaft connector
but it can connect the two shafts if you need a mechanical 'fitting'

I'm sorry for the late reply. I really appreciate your reply.

I've read all your replies.
When I read Paul_B's answer, I understood that both ends of the variable resistance are in a position where the resistance does not change, so the values will be the same.

So I'm going to map from 0 to 1023, and then I'm going to hand turn the variable resistance to where the resistance changes, and then I'm going to measure the rotation angle of the step motor.
Or should the code be modified to measure the rotation angle of the step motor after the variable resistance has passed a certain angle?

I'm currently building an astrophilic tracker. The angle of the step motor is reversed by the angle at which the earth rotates. Earth's Rotation Visualized in a Timelapse of the Milky Way Galaxy - 4K - YouTube, please refer to the video at this address. My step motor rotates an angle of 0.088 per pulse and has an angle of 4096. We're going to use a step motor and an RTC module to rotate it 15 degrees for an hour to assemble it.
The RTC module was used to code 0.088 degrees every 21 seconds. But even after 10 hours, you have to make sure it's spinning properly.(Of course there are errors, but it's okay if it's not serious.) So we're measuring the rotation angle of the step motors using variable resistance.

I read Dave's answer.
Rotate the variable resistance between 0 and 270 degrees and 0 degrees multiple times to put the figure into the Excel graph. If so, it is appropriate.Did I get it right?

  • Arduino C code -

rtc.halt(false);
rtc.writeProtect(false);

Alarm.timerRepeat(21, Repeats); // 반복 타이머

/* Time setting === */
// rtc.setDOW(MONDAY);
// rtc.setTime(15, 23, 00);
// rtc.setDate(06, 04, 2020);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){

unsigned int val = analogRead(A0);
unsigned int value;

Serial.print(" 요일 : ");
Serial.print(rtc.getDOWStr());
Serial.print(" ");

Serial.print(" 날짜 : ");
Serial.print(rtc.getDateStr());
Serial.print(" ");

Serial.print(" 시간 : ");
Serial.print(rtc.getTimeStr());
Serial.print(" / ");

Alarm.delay(1);

Serial.print("맵핑된 value의 각도는 : ");
Serial.println(value); // Variable resistance value
}

//==================================================//

void Repeats(){ // Timer function

stepper(1);
i++;
// Serial.print(" 스텝모터의 진행 된 펄스 : ");
Serial.print(" / ");
Serial.println(i); // stepper moter pulse

}

Thanks for reading it !!!

tjdwls:
The RTC module was used to code 0.088 degrees every 21 seconds. But even after 10 hours, you have to make sure it's spinning properly.(Of course there are errors, but it's okay if it's not serious.) So we're measuring the rotation angle of the step motors using variable resistance.

That seems to me completely unnecessary.

If you know how many steps the motor has moved you will know the angular movement far more accurately than what you can learn from a potentiometer.

...R

It is pretty simple.

Either you know the specification for how many steps per revolution the (geared in this case) stepper makes, or you attach a pointer to the shaft, set it against a fixed index pointer, then use a program to generate and display the count of steps until the shaft makes a complete revolution and again points to the fixed index.

As Robin II said, I explained to the professor. But this means that the professor told me to learn how to use nonlinear sensors while studying variable resistance and ADC.
The professor wants me to learn the elements of the system through control and organization.

Instead of measuring the rotation angle of the step motor using pulses, I would like to measure the rotation angle using analog signal waveform of variable resistance.

Thank you very much for your reply. Thanks to you, I feel like I'm growing up. Thank you at all times !!!

tjdwls:
Instead of measuring the rotation angle of the step motor using pulses, I would like to measure the rotation angle using analog signal waveform of variable resistance.

Then you need a suitable variable resistance AND you need to ensure that the motor only operates within the working range of the variable resistance.

If, as suggested in Reply #8, you are allowing the motor to rotate the potentiometer beyond the range of its resistance track then you cannot expect any useful data and no amount of curve fitting will correct for that.

...R