Home / How To / Arduino Resolver module: 4 steps

Arduino Resolver module: 4 steps



Copy Paste Arduino code below to your sketch in Arduino IDE

What this code should do goes to the PWM Resolver module. That module will excite the resolver and produce a quarter wave on the resolver's secondary coils. The signals coming out of Sin + and Cos + may be fed to an OPAMP which will center the Wave and reduce the output so that it goes between 0-5 Volts.

Sin + and Cos + are as they mean. The sin is 90 degrees out of phase with the Cos wave.

Since they are 90 degrees out of phase, we must use the function Atan2 (Cos, Sin) to get the correct coordinate for the resolver position.

Then Arduino will spit out, after it has received 4 samples, a value between -3.1

4 and 3.14 representing -180 degrees and +180 degrees, respectively. That is why if you want to use the resolver for absolute position you only have to use between -180 and 180 with over rotating or else you roll over and think you are back at the beginning or end of your actuator stroke. This would be a problem if you decided to use a x or y axis resolver for a 3D printer and rolled over and caused the 3D printer to interfere.

I could have made the code a little better with interruptions to have more continuous PWMing but it will be enough for this application. Int A = A0;

int B = A1; int pwm = 9; int c1 = 0; int c2 = 0; int c3 = 0; int c4 = 0; int c5 = 0; int c6 = 0; int s1 = 0; int s2 = 0; int s3 = 0; int s4 = 0; int s5 = 0; int s6 = 0; flow output = 0.00; int sin1 = 0; int cos1 = 0; int position_state = 1; int get_position = 0; void settings () {// insert your installation number here to run once: pinMode (pwm, OUTPUT); Serial.start (115200); } Void loop () {

(get_position <5){ switch(position_state){ case(1): digitalWrite(pwm, HIGH); delayMicroseconds(15); position_state +=1; break; case(2): position_state +=1; delayMicroseconds(5); break; case(3): position_state +=1; c1+= analogRead(A); s1+= analogRead(B); delayMicroseconds(5); break; case(4): position_state +=1; c2+= analogRead(A); s2+= analogRead(B); delayMicroseconds(5); break; case(5): position_state +=1; delayMicroseconds(5); break; case(6): position_state +=1; digitalWrite(pwm, LOW); delayMicroseconds(5); break; case(7): position_state +=1; delayMicroseconds(5); break; case(8): position_state +=1; c3+= analogRead(A); s3+= analogRead(B); delayMicroseconds(5); break; case(9): position_state +=1; c4+= analogRead(A); s4+= analogRead(B); delayMicroseconds(5); break; case(10): position_state = 1; get_position +=1; delayMicroseconds(5); break; default: break; } } else if(get_position> = 5) {cos1 = (c1 + c2) – (c3 + c4); sin1 = (s1 + s2) – (s3 + s4); output = atan2 (cos1, sin1); c1 = 0; c2 = 0; c3 = 0; c4 = 0; s1 = 0; s2 = 0; s3 = 0; s4 = 0; Serial.print ("Position:"); Serial.println (output); get_position = 1; }

// put your master code here to run repeatedly:

}


Source link