View Single Post
  #12   Spotlight this post!  
Unread 03-05-2008, 22:32
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is online now
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,721
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Automatic counter-Encoder

Quote:
Originally Posted by Generalx5 View Post
Part I:

Woah there! Plenty of help, thanks!

As for Kevins code: count = (count + ((dig_in ^ old_dig_in)?1:0))%30;
old_dig_in = dig_in;

Do I simply replace dig_in with rc_dig_in05 for example if im using digital 05 as my input. Will I have to replace old_dig_in with anything or leave it as is....

So everytime I need to call back to find where the count is, I have to refer to using "count"? right? so in the case that count = 25 is true, do this etc etc...if count is 26 do this and so on. Would it be possible to start the count when the switch is either a 0 or a 1? For example, I always want the first number 1 to be when the switch is 1, and then when the switch is 0, that would become 2, if I had to reset, and the current switch is sitting at 0, it would not start the count unless the switch is at 1.

So can someone run this through with me? When the system boots up, what is it doing initially? It has no count to begin with? Does it start counting as soon as it detects that a change has occured?

Could it be made so that initially, if the switch is 0, it would count it as a 1, and when the switch starts with a 1, it would count is as an automatic 2. This way, each 0 that comes back from the switch becomes an odd number, while each 1, is an even number.

If you are wondering what this wheel is, it is actually a motor that I've been making in the shop. its made to track distance covered by the rotations.

Part II:

How do I print the current count in a printf format?
alright, so first, this is a 0-29 counter.

Second, yes you can leave old_dig_in as is. I'd recommend renaming it old_rc_dig_in05, though, in case you want to duplicate this code for another counter.

Third, as I said, ^ will be true and you'll increment your count whenever rc_dig_in05 and old_rc_dig_in05 aren't equal. So logically, it doesn't count when those two are equal. So, if you want count to start at 0 if rc_dig_in05 = 0 at the start, then what would you want to set old_rc_dig_in05 equal to to start out? If you get that right, then your second desire follows naturally.

You'll need to set count = 0 in your definition or in the initialization code or some such to have it start as 0. Or set it to whatever you like, but do recall that this is a 0-29 counter.

The printf would be printf("blah-ty-blah %d", (int) count); And the (int) IS important, as printf expects ints, and you can get some odd results giving it a char. (And you should be using a char for this.)


Finally, this only counts in one direction, if you want to change directions, it'll be a little different.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter