I am designing a circuit which will read analog values from an IR and map the value to PWM out.
The problem is when Analog read is at its mid point which is arount 511. The arduino should give PWM out 0 and 255 for an instance then back to the normal mappng.
mapping is working . i am using if condition for this instance pulse but nothing happening.
i am controlling DC motor circuit for cloth rolling machine IR sensors are installed on the rolling machine which keeps the cloth align from both sides
Reading the IR sensors data on arduino then sending control signal to the motor control board.
Motor control signal is -12V moving motor to left and +12V to move to the right and 0V at center.
When motor comes to center due to inertial load motor dont stop at center it moves to left or right ie the opposite side from which it is coming ..
I am writing code That when motor comes to center it arduino gives both signals ie -12 and +12 V so motor applies break
for -12 and +12 i am using amplifier IC whose input is 0 to 5V from arduino and output is -12 to +12 V respectively . output is 0 at 2.5 V from arduino.
asad9266:
I am writing code That when motor comes to center it arduino gives both signals ie -12 and +12 V so motor applies break
The way you are doing it seems strange, but if it works ...
for -12 and +12 i am using amplifier IC whose input is 0 to 5V from arduino and output is -12 to +12 V respectively . output is 0 at 2.5 V from arduino.
The PWM output from an Arduino is not a variable voltage. It is an ON-OFF signal of 0v or 5v with a varying duty cycle. You need external components to convert that to a varying voltage.
Note that analogWrite(pin, 0) is the same as digitalWrite(pin, LOW) analogWrite(pin,255) is the same as digitalWrite(pin, HIGH)
Coming back to your original question, can you describe in more detail the sequence that should happen (with timing) when the system approaches the centre? It sounds like a case for using PID control to avoid an overshoot.
I am designing a circuit which will read analog values from an IR and map the value to PWM out.
The problem is when Analog read is at its mid point which is arount 511. The arduino should give PWM out 0 and 255 for an instance then back to the normal mappng.
mapping is working . i am using if condition for this instance pulse but nothing happening.
Please help .
Asad
Hey,
Don't use the the "if else" statement for mapping of values. Use the map() function. You can see it here.
ArnavPawarAA:
Hey,
Don't use the the "if else" statement for mapping of values. Use the map() function. You can see it here.
..Arnav
Don't you even bother looking at the code before offering your useless advice? The OP is using map() for mapping and the if statement is for selection which is its intended purpose.
Robin2:
The way you are doing it seems strange, but if it works ...
The PWM output from an Arduino is not a variable voltage. It is an ON-OFF signal of 0v or 5v with a varying duty cycle. You need external components to convert that to a varying voltage.
Note that analogWrite(pin, 0) is the same as digitalWrite(pin, LOW) analogWrite(pin,255) is the same as digitalWrite(pin, HIGH)
Coming back to your original question, can you describe in more detail the sequence that should happen (with timing) when the system approaches the centre? It sounds like a case for using PID control to avoid an overshoot.
...R
yes I know about the PWM output of Arduino. i am using an amplifier IC to convert PWM to analog -12 to +12 V. The motor control circuit is built on 2 thyristors half wave assembly. which is already attached to the machine. i am designing only the input signal for that circuit. it moves the motor to left when -12 V signal is applied and moves right when +12V is applied. I am trying to do Is Breaking off the DC motor. which will achieve by turning both thyristors ON for a short moment.
PS: I have posted working of the system before up here.
Robin2:
You have not responded to my request for more detail about the sequence of events you want the Arduino to produce.
...R
Arduino Read values from IR sensor. IR is installed in a rolling machine which detects the position of Cloth running on rolling machine to keep it align.
. for 1023 it will give 0 of PWM and at 0 it will give 255.
then that value go to amplifier which will convert this signal to -12V to +12 V.
That signal will go to the motor control card.
0V to -12 V the motor moves to left AND +V to +12 V motor moves to Right. the higher the value, higher the speed of the motor.
Motor is used to align the assemble.
Motor and that assembly have some inertial load due to which we require to apply breaks to the motor which will achieve by applying -12V and +12V signal ie 0PWM and 255PWM from arduino for a very short instance and then keep giving value according to the analog input.
Breaking is achieve at midpoint analog value 511, PWM output at half ie around 125. but for a short moment when it comes to mid it should give 0 and 255.
I am not being able to achieve the breaking procedure that is mentioned above
What you sketch is doing is, whenever the analogRead() returns a value from 505 to 515 (inclusive) it sets the PWM output to 128-ish for a few microseconds, then 255 for a few microseconds, then 0 for a few microseconds and then repeats very quickly. How did you want it to act differently? Did you want the massive swing to NOT be repeated? Did you want the 128-ish value to not happen when the 0/255 swing happened? WHAT EXACTLY DO YOU WANT?
asad9266:
Breaking is achieve at midpoint analog value 511, PWM output at half ie around 125. but for a short moment when it comes to mid it should give 0 and 255.
How long is this short moment.
For how long must the value stay at 0 and for how long at 255 ?