Frank. You have a couple of things going. First, are you using the encoder on a dc motor, or on the Stepper motor you supplied the link for? If you are using a stepper, you don't need the encoder. The encoder, if properly installed should work just like the encoders used in these demonstrations. The only thing you will need to keep track of is the number of pulses per revolution that you need to convert pulse transitions into degrees.
Nice video, specially that array. I tried it, but hated the if's to determine the state. I renumbered your table to 11 being 3, 10 being 2, 00 being 1 and 01 being 1 I adjusted the array accordingly. For the state, I read portd, divide it by 8 and mask it (and) with 3 (in one line ;) speeds it up a little more.
So I have an incremental linear encoder spiting out serial data, 0 to 64k and rolls over back to zero again. It's stiff so it goes slow counting. My encoder has a 30ppr. I'm confused on what that means for that 0-64k. I'm trying to use it to get distance and or speed.
Hey, very good video, could you give some advice to implement your code to control the position of the motor, I.e. the motor is moving and an specific number of pulses (counter) it stops.
Dr Paz I tried to down load the lecture slides but, the server at control.nmsu.edu can't be found, because the DNS lookup failed. I know the slides have more information. How can I get a copy of the lecture slides. Please??
One idea is to add in a condition for state changes such as state 0 to 2. or state 3 to 1. Since theres no logical way for these transitions to happen it indicates a missed step count. at which point you could detect the miss and indicate a fault scenario. Would be very usefull for things where tracking is critical (ie cnc dimensional tracking)
Oh man, bummer, I was hoping I could some how just hook the 4 wires from the encoder on the motor and the two wires to the little PM Motor up to the adruino and maybe a motor driver, shoot some code into it from the hip and presto! "Not so Grass Hopper", says Robert, "spend two hours with me and I'll give you a simple introduction to it all", I might have to watch the whole two episodes yet...
// good 360 degree reading// rotary encoder type LPD3806-360BM-G5-24C //J733long float temp; int counter = 0; // volatile unsigned int temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder void setup() { Serial.begin (9600); pinMode(2, INPUT_PULLUP); // internal pullup input pin 2 pinMode(3, INPUT_PULLUP); // internalเป็น pullup input pin 3//Setting up interrupt //A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 Arduino. attachInterrupt(0, ai0, RISING); //B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 Arduino. attachInterrupt(1, ai1, RISING); } void loop() { // Send the value of counter if( counter != temp ){ Serial.println (temp/2,0); temp = counter; } } void ai0() { // ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH // Check pin 3 to determine the direction if(digitalRead(3)==LOW) { counter++; }else{ counter--; } } void ai1() { // ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH // Check with pin 2 to determine the direction if(digitalRead(2)==LOW) { counter--; }else{ counter++; } }
Making Progress on my code. I am a newbie. Still cannot get Robert's awesome Codes to work. I set up a pendulum to test this...// change detection // rotary encoder type LPD3806-360BM-G5-24C //J733long float temp; int counter = 0; int statePrevious; boolean stateLeft; boolean stateRight; int setLeft; int setRight; int Led7=7; int Led8=8; // volatile unsigned int temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder void setup() { Serial.begin (115200); pinMode(2, INPUT_PULLUP); // internal pullup input pin 2 pinMode(3, INPUT_PULLUP); // internal pullup input pin 3 pinMode(Led7, OUTPUT); pinMode(Led8, OUTPUT); //Setting up interrupt //A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino. attachInterrupt(0, ai0, RISING); //B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino. attachInterrupt(1, ai1, RISING); } void loop() { // Send the value of counter if( counter != temp ){ temp = counter; } } void ai0() { // ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH // Check pin 3 to determine the direction if(digitalRead(3)==LOW) { stateRight = true; stateLeft = false; if (stateRight == true && stateLeft == false) { Serial.println ("Going Right "); setLeft = counter - counter - counter + 1; Serial.println (temp,0); Serial.print (" Set left to "); Serial.println (setLeft); digitalWrite (Led7, HIGH); digitalWrite (Led8, LOW); // send stepper to last (setRight); } counter--; }else{ counter++; } } void ai1() { // ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH // Check with pin 2 to determine the direction if(digitalRead(2)==LOW) { stateRight = false; stateLeft = true; if (stateRight == false && stateLeft == true) { Serial.println ("Going Left "); setRight = counter - counter - counter - 1 ; Serial.println (temp,0); Serial.print (" Set Right to "); Serial.println (setRight); digitalWrite (Led7, LOW); digitalWrite (Led8, HIGH); // send stepper to last (setLeft); } counter++; }else{ counter--; } }
Looking at this in 2022: it is still the best in depth lecture series. Thank you for this gem of a video series.
DR Paz Great Video. Right now my head is trying to decode the 1x,2x,4x. I can’t wait for the next video
Congratulations from Brazil.
man! you are so good at explaining!
I liked this video and had good fun to see those hardware shown in one third of the pixel :-I)
Best fucking class, thank you mate. You're helping me at a final project for graduating in mechatronics. TY!
Frank. You have a couple of things going. First, are you using the encoder on a dc motor, or on the Stepper motor you supplied the link for? If you are using a stepper, you don't need the encoder. The encoder, if properly installed should work just like the encoders used in these demonstrations. The only thing you will need to keep track of is the number of pulses per revolution that you need to convert pulse transitions into degrees.
Nice video, specially that array. I tried it, but hated the if's to determine the state.
I renumbered your table to 11 being 3, 10 being 2, 00 being 1 and 01 being 1
I adjusted the array accordingly.
For the state, I read portd, divide it by 8 and mask it (and) with 3 (in one line ;)
speeds it up a little more.
Nice about the mentioning information security. Bravo :)
So I have an incremental linear encoder spiting out serial data, 0 to 64k and rolls over back to zero again. It's stiff so it goes slow counting. My encoder has a 30ppr. I'm confused on what that means for that 0-64k. I'm trying to use it to get distance and or speed.
Hey, very good video, could you give some advice to implement your code to control the position of the motor, I.e. the motor is moving and an specific number of pulses (counter) it stops.
I try to control the speed of dc motor with pwm by sensing of encoder. I got some idea from your video. Thanks so much.
Very Helpful , Thank you very much :D
Thank you so much, this was very helpful.
Pamela Patrick You are very welcome!
Instead of Achange and Bchange, can I combine them into one ABchange because the content of the ISR is the same?
+Thanh Do Good question. Did you figure it out?
Dr Paz I tried to down load the lecture slides but, the server at control.nmsu.edu can't be found, because the DNS lookup failed. I know the slides have more information. How can I get a copy of the lecture slides. Please??
The link has been fixed.
One idea is to add in a condition for state changes such as state 0 to 2. or state 3 to 1. Since theres no logical way for these transitions to happen it indicates a missed step count. at which point you could detect the miss and indicate a fault scenario. Would be very usefull for things where tracking is critical (ie cnc dimensional tracking)
Agreed. The issue of error detection and correction is the topic of a separate lecture itself!
where can i learn embeded system as a diploma?
Can you please provide us the link to the presentation?
Thanks
The youtube video is a presentation. Copy that.
Oh man, bummer, I was hoping I could some how just hook the 4 wires from the encoder on the motor and the two wires to the little PM Motor up to the adruino and maybe a motor driver, shoot some code into it from the hip and presto! "Not so Grass Hopper", says Robert, "spend two hours with me and I'll give you a simple introduction to it all", I might have to watch the whole two episodes yet...
// good 360 degree reading// rotary encoder type LPD3806-360BM-G5-24C //J733long float temp;
int counter = 0;
// volatile unsigned int temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder
void setup() {
Serial.begin (9600);
pinMode(2, INPUT_PULLUP); // internal pullup input pin 2
pinMode(3, INPUT_PULLUP); // internalเป็น pullup input pin 3//Setting up interrupt
//A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 Arduino.
attachInterrupt(0, ai0, RISING);
//B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 Arduino.
attachInterrupt(1, ai1, RISING);
}
void loop() {
// Send the value of counter
if( counter != temp ){
Serial.println (temp/2,0);
temp = counter;
} }
void ai0() {
// ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH
// Check pin 3 to determine the direction
if(digitalRead(3)==LOW) {
counter++;
}else{
counter--;
}
}
void ai1() {
// ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH
// Check with pin 2 to determine the direction
if(digitalRead(2)==LOW) {
counter--;
}else{
counter++;
}
}
amazing, thanks
I would like to go on and watch but for some reason I can not handle the format you have chosen.
Making Progress on my code. I am a newbie. Still cannot get Robert's awesome Codes to work. I set up a pendulum to test this...// change detection
// rotary encoder type LPD3806-360BM-G5-24C
//J733long float temp;
int counter = 0;
int statePrevious;
boolean stateLeft;
boolean stateRight;
int setLeft;
int setRight;
int Led7=7;
int Led8=8;
// volatile unsigned int temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder
void setup() {
Serial.begin (115200);
pinMode(2, INPUT_PULLUP); // internal pullup input pin 2
pinMode(3, INPUT_PULLUP); // internal pullup input pin 3
pinMode(Led7, OUTPUT);
pinMode(Led8, OUTPUT);
//Setting up interrupt
//A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino.
attachInterrupt(0, ai0, RISING);
//B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino.
attachInterrupt(1, ai1, RISING);
}
void loop() {
// Send the value of counter
if( counter != temp ){
temp = counter;
}
}
void ai0() {
// ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH
// Check pin 3 to determine the direction
if(digitalRead(3)==LOW) {
stateRight = true;
stateLeft = false;
if (stateRight == true && stateLeft == false) {
Serial.println ("Going Right ");
setLeft = counter - counter - counter + 1;
Serial.println (temp,0);
Serial.print (" Set left to ");
Serial.println (setLeft);
digitalWrite (Led7, HIGH);
digitalWrite (Led8, LOW);
// send stepper to last (setRight);
}
counter--;
}else{
counter++;
}
}
void ai1() {
// ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH
// Check with pin 2 to determine the direction
if(digitalRead(2)==LOW) {
stateRight = false;
stateLeft = true;
if (stateRight == false && stateLeft == true) {
Serial.println ("Going Left ");
setRight = counter - counter - counter - 1 ;
Serial.println (temp,0);
Serial.print (" Set Right to ");
Serial.println (setRight);
digitalWrite (Led7, LOW);
digitalWrite (Led8, HIGH);
// send stepper to last (setLeft);
}
counter++;
}else{
counter--;
}
}
thank you:)
shoulda talked about revolvers instead of potentiometers.... revolvers are a much better analogue example
fine explained video but bad code, just use FALLING and RISING state to determin, and waste too much time in the 'pulling' way
That's not what volatile means. en.wikipedia.org/wiki/Volatile_(computer_programming)
Booooring... could have be done in 20 minutes....