Reseting optical shaft encoders

is there any way that i can program my robot so it resets the opitcal shaft encoder so i can get a differnt reading each time it runs through my code please help

just set the variable back to 0

How do i set the varible back each time

if your using easy C, read the help on encoders, it will be in there. If your using C, I don’t really know.

so would the preset option be the thing that i use to change the value back to one because i tried it and it wouldnt work

here is my code it is suposed to be monitering rps (revolutions per sec) It does that but with out geting rid of the first rps the second reading always just adds to the first one

#include “Main.h”

void main ( void )
{
int loop = 1;
int encoder = 0;

  //Connect Encoder to Interrupt 2
  //There are 90 encoder counts per revolution
  while ( loop == 1 )
  {
        StartEncoder ( 2 ) ;
        encoder = GetEncoder ( 2 ) ;
        encoder /= 90 ;
        Wait ( 1000 ) ;
        PrintToScreen ( "encoder%d\n" , (int)encoder ) ;
  }

}

Yes if you are using easy c v2 just drag the reset block in to the program and then set the ports and stuff that it asks you.

If you are not using easy c then i cannot help you, the post before mine is much more helpful in this matter.

yea i tried that when i read the help thing about it but it didnt work i put the preset block right at the end of the loop and then i wouldnt even display my rps it just displayed encoder 0 every second kinda like my program but it wouldnt display the rps

A. start the encoder outside the loop.

B. If you want the have it start at 0 every time you run through the code then you want the preset for the encoder to be at the Top of your loop.

C. I don’t know exactly what you are trying to do but right now you are Getting the value of the encoder immediately after you set it to 0 so it is always going to return 0. You might want to put a wait in between the reset and get.

i did what you said and it wouldnt even read any rps it just stayed on zero

What i want to do is every time it up dates i want it to display the current rps wich would work if i could reset it each time

the code up there just keeps counting up the rpses

ok srry i am really confused, you say you want to “reset” your optical encoder, all you need to do is set the variable back to 0, which would “reset” it back (i.e. at the start of the program the variable is 0, then the robot moves forward and the variable goes up to 200 (example) then when you’re done reading that you set it back to 0)

if this is what you mean and it’s not working maybe you have a broken encoder? is this the new one? maybes theres some trick to the new one?

well i am building basicly a tachometer ,shows current rpm, i want it to show the current rps so the old reading keeps adding to the new reading and the number keeps adding up and up and when the shaft stops i want it to be zero

I have the old encoder and they arnt broken

Yeah, you need to reset the variable each time through the loop in addition to reseting the encoder. That should fix your problem.

how do you reset the varible is that the value?

so what i need to do is do the preset thing for the encoder and then do something i dont know how to do to reset the varible

Here is an example of how to preset the encoders and your value.
encoderFun.zip (1.14 KB)

Thank you so much i am very novice at programing because my school doesnt hvae a programing class and i dont have the resources to really learn about c programing thank you again i had to put a wait after the stuff you added and it worked like a charm