Go Down

### Topic: encoder (Read 39519 times)previous topic - next topic

#### mingki

#30
##### Feb 08, 2008, 02:28 amLast Edit: Feb 08, 2008, 10:02 am by mingki Reason: 1
Hi, mem. i've tried with your way below.
Quote
You could do something like:

int startCount;

startCount = encoder0Pos;   // put this in setup();

// and this in your loop
if(encoder0Pos > startCount + 40){
StartCount = encoder0Pos;  // I assume you want to reset the counter
digitalWrite(3, HIGH);
delay(1000);
}

The result is when a potentiameter send 0.16~0.20V to analog input, arduino's digital pin #6 gets HIGH.
I've set digital pin #6 as the following.
else if (val < 40) {
if(encoder0Pos > startCount + 512){  // testing if the encoder count is greater than 512
startCount = encoder0Pos;
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(6, LOW);
delay(1000);
The number 512 is the resolution of my encoder per one revolution.
i've realized that 40 is equal to 0.16~0.20V.
At this point, What I hope to do is when i continuosly roll potentiameter all the way to the right and all the way to the left(to literally create variables between 0~5V and 5V~0), i hope arduino could recognize(in the middle of encoder's rotational movement) the particular variables which has been programed as "if(val < 40)" and count 512 to make digital pin # in a HIGH state.
That means, the variables(analog) won't be staying(fixed) for encoder to count 512 at its presence but just a split of second.
i believe arduino can do this, but how can i make a sketch for this process?

mingkimingki@gmail.com

#### mingki

#31
##### Feb 08, 2008, 01:59 pmLast Edit: Feb 08, 2008, 02:04 pm by mingki Reason: 1
i figured it would be better to use two arduinos to do this process. First arduino for potentiameter and second arduino for encoder.
For potentiamer, i think "if (val < 40)" statement is sufficient. so I made this arduino to receive potentiameter's analog variable and to get HIGH(digital pin )when it gets to a certain designated value. I had the idea to make another arduino to receive this signal and get HIGH on digital pin #13 when encoder rotate for 512 steps.
But, the point was to create variable analog input signals controlling the potentiameter randomly left, right, left, right continuously and quickly so that i could only provide short input receiption time for first arduino.
So, i tried this sketch.
void loop(){
if (val == HIGH && encoder0Pos > startCount + 512)
{
startCount = encoder0Pos;
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
}
but, the 13th digital pin of second arduino only lights up when i spin the encoder for 512 steps at the input presence of 0.16~0.20V analog variable from the first arduino. so no difference.

mingkimingki@gmail.com

#### mem

#32
##### Feb 08, 2008, 04:06 pmLast Edit: Feb 08, 2008, 04:08 pm by mem Reason: 1
First, lets make sure that I understand what you want to do. if the following is not correct then please change the description so it says what you want to do:

Get a count threshold from the position of a pot

The threshold will be proportional to the value from analogRead on the pot pin.

The minimum count threshold is x? and the maximum is y? (what are x and y?)

When the encoder count is greater than the threshold, LED13 will flash and the count will start over again.

#### mingki

#33
##### Feb 09, 2008, 12:01 am
thank you.
yes, LED 13 blinks when i set the pot at 0.16V~0.20V after encoder count reached to 512 steps.
when i roate encoder till 512 steps, LED 13 doesn't blink. But, at this point, when i set the potentiameter at 0.16V~0.20V(equal to "val < 40"), it blinks.
what i wish to do is the opposite.
i want LED 13 to be blinked when i rotate encoder till 512 steps after the pot is set at 0.16V~0.20V(only for a short time, not staying).
when i continuously roll the pot left and right, then variables will between 0~5VDC. i hope arduino could sense the particular variable(in this case, it's 0.16V~0.20V) among those rapidly changing variables between 0~5V and wait until encoder reach to 512 steps.

mingkimingki@gmail.com

#### mem

#34
##### Feb 09, 2008, 08:26 amLast Edit: Feb 09, 2008, 08:31 am by mem Reason: 1
Quote
when i continuously roll the pot left and right, then variables will between 0~5VDC. i hope arduino could sense the particular variable(in this case, it's 0.16V~0.20V) among those rapidly changing variables between 0~5V and wait until encoder reach to 512 steps.

that statment does not explain the relationship between the pot and the encoder count. I think you want the threshold at which the encoder count will trigger a flash of the LED to be related to the pot position, but you dont say how. Answering the following four questions will help me understand what you want to do:

If the pot value is 0 (fully CCW), what should the encoder count threshold be?
If the pot value is 512 (mid posiiton), what should the encoder count  threshold be?
If the pot value is 1023 (fully CW), what should the encoder count  threshold be?
Should the count be proportional for pot position in between the above?

#### mingki

#35
##### Feb 09, 2008, 10:28 am
if the pot value is 0, then, i don't want LED to be blinked since the particular number in 'if (val <     )" statement will be above 0.
if the pot value is in the mid position, the threshold would be 20.
if the pot value is in the full position, the threshold would be 40.
if first arduino(which is taking potentiameter's variables) meets a threshold of 20, i will make one of its digital pin gets HIGH so that the second arduino could sense the HIGH or LOW state of the fist arduino. if it senses HIGH state(get HIGH for 1000milisec) from the digital pin of first arduino, then i want it to wait until encoder count 512 steps and get HIGH on pin #13.
even if second arduino senses another HIGH state from the first arduino in the middle of counting till 512(for first HIGH state), i want second arduino could also count 512 for the second HIGH state, too.
if second arduino sensed HIGH state and start to count until 512 step, (let's say it has counted 300 and has 212 to go) if it senses HIGH state again(from the first arduino), then want it to count for both remaining 212 steps as well as counting for second HIGH state(counting 512 steps) at the same time.

mingkimingki@gmail.com

#### mem

#36
##### Feb 09, 2008, 10:45 am
Maybe it would be easier for me to understand exactly what you are trying to do if you explained the task you are trying to perform without any reference to how you would implement it using arduino.

Here are some things I am not clear about.

What do you want to happen when the pot values are between the examples you gave. Should the threshold smoothly increase from 0 to 40 as the pot rotates to the right?

Are there two encoders?

If so, is the second encoder counting the number of times the first encoder hits the threshold, or is to counting something else.

#### mingki

#37
##### Feb 09, 2008, 12:21 pmLast Edit: Feb 09, 2008, 12:22 pm by mingki Reason: 1
Quote

What do you want to happen when the pot values are between the examples you gave. Should the threshold smoothly increase from 0 to 40 as the pot rotates to the right?
Are there two encoders?
thank you. yes, i want the threshold to be increased from 0 to 40 smoothly according to the rotation of the encoder. I use only one encoder and two arduinos.

mingkimingki@gmail.com

#### mem

#38
##### Feb 09, 2008, 01:21 pm
I think I now understand that you want the count threshold to increase smoothly from 0 to 40 as the pot is rotated to the right.

Could you describe in words what you want to happen when the count exceeds the threshold. Try to explain what you want see as output, not how you think your sketch would be implemented.

Perhaps post a table showing what you would expect to see if you printed the threshold and count for various values:

Threshold = 1  count = 0  LED is off
Threshold = 1  count = 1 LED flashes , count is reset to 0
Threshold = 10 count = 9 led is off
Threshold = 10 count = 10 led flashes, count reset to 0

Change the wording above so it describes what you want to see. add whatever values clarify what you expect to happen

#### mingki

#39
##### Feb 09, 2008, 01:57 pmLast Edit: Feb 09, 2008, 02:00 pm by mingki Reason: 1
thanks. i've put it in the following way.
threshold "if (val < 1)" = 0 count = No LED is on
threshold "if (val > 20)" = 40 counts = #2 LED is on
threshold "if (val > 40)" = 80 counts = #3 LED is on
so, when the count exceeds one particular threshold, i want the exceeded counts to be corresponded to another threshold which will be higher than previous one.
if a certain threshold meets its condition, i want one of digital pin go HIGH for second arduino to sense that state and count for a designated amount of steps so that its digital pin 13 get HIGH in order to light up an LED on it.

mingkimingki@gmail.com

#### mem

#40
##### Feb 09, 2008, 02:47 pm
I was hoping that you could describe what task you have for your application without reference to code.

I don't understand if you want to use two arduinos because you think one is not capable of doing what you want or if there is some reason you want to use two that you haven't explained.

I also do not understand the relationship between the thresholds and the encoder counts.

It seems to me that your descriptions contain a little bit of what you want to do and a little bit of how you want to do it. But there is not enough of either for me to get a clear enough idea of the purpose of your application so I can  guide you.

So it would really help me to help you if you could think about describing what actions you want your application to perform as the count thresholds are reached,  before speculating about how it could be implimented.

#### mem

#41
##### Feb 09, 2008, 04:00 pm
It will help me understand if you can explain what you said in the previous post but pretend that there is just one arduiono. I am not saying you shouldn't use two (although I don't understand why you are) but I am getting confused by the stuff you are doing to talk from one to the other.

So, pretend that your entire application was implemented on only one board, what do you want the LED to do when the count reaches a specified number? Should anything else also happen at this time.  And what should happen after that

#### mingki

#42
##### Feb 09, 2008, 04:32 pmLast Edit: Feb 09, 2008, 04:34 pm by mingki Reason: 1
i want the analog input(from potentiameter) act as a commend to initialize the encoder count for specified steps.
when the specified steps reached, i want the corresponding LED flashed. that's what i want to do.

mingkimingki@gmail.com

#### mem

#43
##### Feb 09, 2008, 05:15 pm
try something like this:

int startCount;
int steps

startCount = encoder0Pos;   // put this in setup();

// and this in your loop
steps = analogRead(potpin) / 25 ;   //  this gives 40 steps, a pot value of 1023 = 40
if(encoder0Pos > startCount + steps){
startCount = encoder0Pos;  // I assume you want to reset the counter
digitalWrite(13, HIGH);       // flash an LED
delay(1000);
digitalWrite(13, HIGH);
}

#### mingki

#44
##### Feb 10, 2008, 06:19 amLast Edit: Feb 10, 2008, 06:25 am by mingki Reason: 1
I tried your sketch like the following.
void loop(){
if (val > 1 && val < 20)
{
if(encoder0Pos > startCount + steps){
startCount = encoder0Pos;
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(3, LOW);
delay(1000);
}
}
but,  #3 digtal pin LED doesn't flash.

mingkimingki@gmail.com

Go Up

Please enter a valid email to subscribe