Poor mans encoder

Started by bsjoelund January 5, 2004
Hi,
Is this doable with PIC16F84 (DYI poormans encoder)

Input waveform 2 channels (up to 200/rev)
Ch1 ----____----____----____----____----____----____----____
Ch2 --____----____----____----____----____----____----____
CH3 ----____---------------
sync 1/rev or x/rev

RA0 Ch1
RA1 Ch2
RA2 Ch3 (if needed and as many pulses/rev as needed)
RA3 Sync ( as many pulses/rev as needed)

outputs to be multiplied (examples)
RB0 2x Ch1
RB1 2x Ch2
RB2 4x Ch1
RB3 4x Ch2
RB4 10x Ch1
RB5 10x Ch2
RB6 100x Ch1
RB7 100x Ch2

Any help would be appreciated, I would like to do remote jogging
wheel for CNC lathe with no manual feed. I still like to have the
*manual* feeling in my hand :)

Bengt




Hello Bengt,
yes that is easily done in a F84.

My suggestion is to put the bit pattern (ch1, ch2) in a byte, then do a bit test on bit 7(ch1) and bit 4(ch2) and move those bits to their
port pins. If you then do a rotate on the byte you have the next ch1, ch2 levels. The output frequency will be 1/2 the rotate frequency.

You'll have to use a timer to measure the input pulse width of  i.e. ch1, process that data (with multiplication factor) and load it into the second timer which is then used to generate variable frequency interrupt. The interrupt handler will of course run the above mentioned bit rotate routine.
Ch3 will have to be processed separately if your encoder has many lines.

Rotate this byte left and bit 7(ch1) and bit 4(ch2) should give you the quadrature output you're looking for.
b7 is obviously rotated into bit0.

ch1 ch2
 |      |
 11001100 <-
|__________|
 
 

bsjoelund wrote:

 Hi,
Is this doable with PIC16F84 (DYI poormans encoder)

Input waveform 2 channels (up to 200/rev)
Ch1 ----____----____----____----____----____----____----____
Ch2 --____----____----____----____----____----____----____
CH3 ----____---------------
sync 1/rev or x/rev

RA0 Ch1
RA1 Ch2
RA2 Ch3 (if needed and as many pulses/rev as needed)
RA3 Sync ( as many pulses/rev as needed)

outputs to be multiplied (examples)
RB0 2x Ch1
RB1 2x Ch2
RB2 4x Ch1
RB3 4x Ch2
RB4 10x Ch1
RB5 10x Ch2
RB6 100x Ch1
RB7 100x Ch2

Any help would be appreciated, I would like to do remote jogging
wheel for CNC lathe with no manual feed. I still like to have the
*manual* feeling in my hand :)

Bengt
 
 
 
 

to unsubscribe, go to http://www.yahoogroups.com and follow the instructions
 


Yahoo! Groups Links
  • To

--
*******************************************
VISIT MY HOME PAGE:
<http://home.online.no/~eikarlse/index.htm>
LAST UPDATED: 23/08/2003
*******************************************
Best Regards
Eirik Karlsen
 



Part of the question of frequency multiplication must revolve around
what is meant by multiply.

If, for a single transition of the input, the output should
transition at some maximum speed for 10 steps and then wait for the
next input transition, that is easy. For every input transition,
send 10 output transitions. And hope that the output is finished
before the next input comes along. Or queue the input transitions
and deal with it.

If the output should be an exact replica of the input at 10x
frequency then a phase locked loop would be appropriate and that
would be difficult with a PIC. We would have to measure the time
between two transitions (t0 and t1) and then output 10 equally
spaced transitions between t1 and t2 assuming that the time between
t1 and t2 was identical to the time between t0 and t1. And we
couldn't start before t1 arrived.

Even with a phase locked loop there is the assumption that the input
transitions are reasonably periodic and the frequencies are often
quite high. --- In , Eirik Karlsen <eikarlse@o...> wrote:
> Hello Bengt,
> yes that is easily done in a F84.
>
> My suggestion is to put the bit pattern (ch1, ch2) in a byte, then
do a bit test on bit 7(ch1) and bit 4(ch2) and move those bits to
their
> port pins. If you then do a rotate on the byte you have the next
ch1, ch2 levels. The output frequency will be 1/2 the rotate
frequency.
>
> You'll have to use a timer to measure the input pulse width of
i.e. ch1, process that data (with multiplication factor) and load it
into the second
> timer which is then used to generate variable frequency interrupt.
The interrupt handler will of course run the above mentioned bit
rotate routine.
> Ch3 will have to be processed separately if your encoder has many
lines.
>
> Rotate this byte left and bit 7(ch1) and bit 4(ch2) should give
you the quadrature output you're looking for.
> b7 is obviously rotated into bit0.
>
> ch1 ch2
> | |
> 11001100 <-
> |__________| >
> bsjoelund wrote:
>
> > Hi,
> > Is this doable with PIC16F84 (DYI poormans encoder)
> >
> > Input waveform 2 channels (up to 200/rev)
> > Ch1 ----____----____----____----____----____----____----____
> > Ch2 --____----____----____----____----____----____----____
> > CH3 ----____---------------
> > sync 1/rev or x/rev
> >
> > RA0 Ch1
> > RA1 Ch2
> > RA2 Ch3 (if needed and as many pulses/rev as needed)
> > RA3 Sync ( as many pulses/rev as needed)
> >
> > outputs to be multiplied (examples)
> > RB0 2x Ch1
> > RB1 2x Ch2
> > RB2 4x Ch1
> > RB3 4x Ch2
> > RB4 10x Ch1
> > RB5 10x Ch2
> > RB6 100x Ch1
> > RB7 100x Ch2
> >
> > Any help would be appreciated, I would like to do remote jogging
> > wheel for CNC lathe with no manual feed. I still like to have the
> > *manual* feeling in my hand :)
> >
> > Bengt
> >
> >
> >
> >
> >
> > to unsubscribe, go to http://www.yahoogroups.com and follow the
instructions
> >
> >
> > -----------------------
----
> > Yahoo! Groups Links
> >
> > * To
> >
> --
> *******************************************
> VISIT MY HOME PAGE:
> <http://home.online.no/~eikarlse/index.htm>
> LAST UPDATED: 23/08/2003
> *******************************************
> Best Regards
> Eirik Karlsen




It was kinda late last night and my post reflects that......
 

After giving it a little more thought it appears as the multiplication routine can be made much simpler and better ;
-no timers
-no interrupts
-no 'advanced' math
-input PPR multiplication
-taking care of the index pulse
-very little code, maybe less than 100 instructions in total.
 

The basic idea is to use the input pulse to trigger a counter loop (multiplier). The output routine, which is called from within the
counter loop, generates one period of ch1 and ch2.

OUTPUT ROUTINE:
two counter loops runs in parallel, each counts modulo two, one starts at one while the other starts at zero (giving the 90deg phase shift).
When any one of these counters rolls over its corresponding port pin is toggled (ch1, ch2). This routine produces one output period for
every 4 times it is called. A direction flag is passed to the routine telling it what direction to produce (invert one output).

MULTIPLIER ROUTINE:
This is a simple loop. When it sees a trigger flag it loads the counter with the mull factor (i.e from a x8 DIL SW), runs trough the loop
N times, then clears the trigger flag and returns.
The mull factor can be any number but 1-255 are preferred because it fits in a byte.

INPUT ROUTINE:
Encoder Pulse Pr Revolution (PPR)...if you count on the leading edge of ch1 you'll get what is known as PPR X1 multiplication (or no multiplication). If you count on the leading edge of both ch1 and ch2 you get PPR X2. If you count on both leading and trailing edge of both
ch1 and ch2 you get PPR X4. This is the maximum possible PPR multiplication. So for your 200 PPR encoder you can actually get
800 PPR. In addition to deriving the clock one must also examine the state of ch1 and ch2 to determine the direction.
The input routine would:
determine the direction and set/clr the direction flag, derive the clockpulse, and when it is ready call the multiplier routine.
When the index comes it sets the index flag. This info is used by the output routine to generate a 2 calls wide (or any width) index pulse.
 

All this is simple 'beginners code'.
Speed and bandwidth:
The F84 can handle it, but if you use X4 and a large mull factor, and in addition literally spins the encoder wheel fast enough the PIC may
loose track....but since you're going to use a hand wheel as input it does not really matter...you'll just be missing input counts...so you turn
the wheel a little further.
 

Hope this can get you started.
Write some code and simulate it in MPLAB.
 
 
 
 
 
 

Eirik Karlsen wrote:

Hello Bengt,
yes that is easily done in a F84.

My suggestion is to put the bit pattern (ch1, ch2) in a byte, then do a bit test on bit 7(ch1) and bit 4(ch2) and move those bits to their
port pins. If you then do a rotate on the byte you have the next ch1, ch2 levels. The output frequency will be 1/2 the rotate frequency.

You'll have to use a timer to measure the input pulse width of  i.e. ch1, process that data (with multiplication factor) and load it into the second timer which is then used to generate variable frequency interrupt. The interrupt handler will of course run the above mentioned bit rotate routine.
Ch3 will have to be processed separately if your encoder has many lines.

Rotate this byte left and bit 7(ch1) and bit 4(ch2) should give you the quadrature output you're looking for.
b7 is obviously rotated into bit0.

ch1 ch2
 |      |
 11001100 <-
|__________|
 
 

bsjoelund wrote:

 Hi,
Is this doable with PIC16F84 (DYI poormans encoder)

Input waveform 2 channels (up to 200/rev)
Ch1 ----____----____----____----____----____----____----____
Ch2 --____----____----____----____----____----____----____
CH3 ----____---------------
sync 1/rev or x/rev

RA0 Ch1
RA1 Ch2
RA2 Ch3 (if needed and as many pulses/rev as needed)
RA3 Sync ( as many pulses/rev as needed)

outputs to be multiplied (examples)
RB0 2x Ch1
RB1 2x Ch2
RB2 4x Ch1
RB3 4x Ch2
RB4 10x Ch1
RB5 10x Ch2
RB6 100x Ch1
RB7 100x Ch2

Any help would be appreciated, I would like to do remote jogging
wheel for CNC lathe with no manual feed. I still like to have the
*manual* feeling in my hand :)

Bengt
 
 
 
 

to unsubscribe, go to http://www.yahoogroups.com and follow the instructions
 


Yahoo! Groups Links
  • To
--
*******************************************
VISIT MY HOME PAGE:
<http://home.online.no/~eikarlse/index.htm>
LAST UPDATED: 23/08/2003
*******************************************
Best Regards
Eirik Karlsen
 

to unsubscribe, go to http://www.yahoogroups.com and follow the instructions
 


Yahoo! Groups Links
  • To

--
*******************************************
VISIT MY HOME PAGE:
<http://home.online.no/~eikarlse/index.htm>
LAST UPDATED: 23/08/2003
*******************************************
Best Regards
Eirik Karlsen
 


Hello Eirik,

I want to thank you for your kind answer to my *problem*. I will pass
this to my son who is more into PIC programming and see if he is able
to get some code to me.

I will report my *progress*

Take care
Bengt

--- In , Eirik Karlsen <eikarlse@o...> wrote:
> It was kinda late last night and my post reflects that...... > After giving it a little more thought it appears as the
multiplication routine can be made much simpler and better ;
> -no timers
> -no interrupts
> -no 'advanced' math
> -input PPR multiplication
> -taking care of the index pulse
> -very little code, maybe less than 100 instructions in total. > The basic idea is to use the input pulse to trigger a counter loop
(multiplier). The output routine, which is called from within the
> counter loop, generates one period of ch1 and ch2.
>
> OUTPUT ROUTINE:
> two counter loops runs in parallel, each counts modulo two, one
starts at one while the other starts at zero (giving the 90deg phase
shift).
> When any one of these counters rolls over its corresponding port
pin is toggled (ch1, ch2). This routine produces one output period for
> every 4 times it is called. A direction flag is passed to the
routine telling it what direction to produce (invert one output).
>
> MULTIPLIER ROUTINE:
> This is a simple loop. When it sees a trigger flag it loads the
counter with the mull factor (i.e from a x8 DIL SW), runs trough the
loop
> N times, then clears the trigger flag and returns.
> The mull factor can be any number but 1-255 are preferred because
it fits in a byte.
>
> INPUT ROUTINE:
> Encoder Pulse Pr Revolution (PPR)...if you count on the leading
edge of ch1 you'll get what is known as PPR X1 multiplication (or no
> multiplication). If you count on the leading edge of both ch1 and
ch2 you get PPR X2. If you count on both leading and trailing edge of
both
> ch1 and ch2 you get PPR X4. This is the maximum possible PPR
multiplication. So for your 200 PPR encoder you can actually get
> 800 PPR. In addition to deriving the clock one must also examine
the state of ch1 and ch2 to determine the direction.
> The input routine would:
> determine the direction and set/clr the direction flag, derive the
clockpulse, and when it is ready call the multiplier routine.
> When the index comes it sets the index flag. This info is used by
the output routine to generate a 2 calls wide (or any width) index
pulse.
>
>
> All this is simple 'beginners code'.
> Speed and bandwidth:
> The F84 can handle it, but if you use X4 and a large mull factor,
and in addition literally spins the encoder wheel fast enough the PIC
may
> loose track....but since you're going to use a hand wheel as input
it does not really matter...you'll just be missing input counts...so
you turn
> the wheel a little further. > Hope this can get you started.
> Write some code and simulate it in MPLAB. >
>
> Eirik Karlsen wrote:
>
> > Hello Bengt,
> > yes that is easily done in a F84.
> >
> > My suggestion is to put the bit pattern (ch1, ch2) in a byte,
then do a bit test on bit 7(ch1) and bit 4(ch2) and move those bits
to their
> > port pins. If you then do a rotate on the byte you have the next
ch1, ch2 levels. The output frequency will be 1/2 the rotate
frequency.
> >
> > You'll have to use a timer to measure the input pulse width of
i.e. ch1, process that data (with multiplication factor) and load it
into the
> > second timer which is then used to generate variable frequency
interrupt. The interrupt handler will of course run the above
mentioned bit rotate
> > routine.
> > Ch3 will have to be processed separately if your encoder has many
lines.
> >
> > Rotate this byte left and bit 7(ch1) and bit 4(ch2) should give
you the quadrature output you're looking for.
> > b7 is obviously rotated into bit0.
> >
> > ch1 ch2
> > | |
> > 11001100 <-
> > |__________|
> >
> >
> >
> > bsjoelund wrote:
> >
> >> Hi,
> >> Is this doable with PIC16F84 (DYI poormans encoder)
> >>
> >> Input waveform 2 channels (up to 200/rev)
> >> Ch1 ----____----____----____----____----____----____----____
> >> Ch2 --____----____----____----____----____----____----____
> >> CH3 ----____---------------
> >> sync 1/rev or x/rev
> >>
> >> RA0 Ch1
> >> RA1 Ch2
> >> RA2 Ch3 (if needed and as many pulses/rev as needed)
> >> RA3 Sync ( as many pulses/rev as needed)
> >>
> >> outputs to be multiplied (examples)
> >> RB0 2x Ch1
> >> RB1 2x Ch2
> >> RB2 4x Ch1
> >> RB3 4x Ch2
> >> RB4 10x Ch1
> >> RB5 10x Ch2
> >> RB6 100x Ch1
> >> RB7 100x Ch2
> >>
> >> Any help would be appreciated, I would like to do remote jogging
> >> wheel for CNC lathe with no manual feed. I still like to have the
> >> *manual* feeling in my hand :)
> >>
> >> Bengt
> >>
> >>
> >>
> >>
> >>
> >> to unsubscribe, go to http://www.yahoogroups.com and follow the
instructions
> >>
> >>
> >> ------------------------
---
> >> Yahoo! Groups Links
> >>
> >> * To
> >>
> > --
> > *******************************************
> > VISIT MY HOME PAGE:
> > <http://home.online.no/~eikarlse/index.htm>
> > LAST UPDATED: 23/08/2003
> > *******************************************
> > Best Regards
> > Eirik Karlsen
> >
> >
> > to unsubscribe, go to http://www.yahoogroups.com and follow the
instructions
> >
> >
> > ------------------------
---
> > Yahoo! Groups Links
> >
> > * To
> >
> --
> *******************************************
> VISIT MY HOME PAGE:
> <http://home.online.no/~eikarlse/index.htm>
> LAST UPDATED: 23/08/2003
> *******************************************
> Best Regards
> Eirik Karlsen




Since you're into DIY stuff you may want to look at some ink jet printers...
Visit a computer repair shop and get some (free) scrap printers, or look trough
their scrap container. Some of the newer printers, most notably the faster ones,
does not use steppers but use permanent magnet motor servo drives for both carriage and paper feed.
If you crack open such a printer you'll see a narrow linear encoder strip running trough the carriage,
this is probably not of much use to you, but if you look down to the left there may be a large round
transparent encoder wheel for the paper feed motor. These wheels are about 5-10 cm in diameter
and they have 100's or maybe over a thousand lines. Obviously there are also a matching optical reader
for that wheel...

bsjoelund wrote:

 Hello Eirik,

I want to thank you for your kind answer to my *problem*. I will pass
this to my son who is more into PIC programming and see if he is able
to get some code to me.

I will report my *progress*

Take care
Bengt

--
*******************************************
VISIT MY HOME PAGE:
<http://home.online.no/~eikarlse/index.htm>
LAST UPDATED: 23/08/2003
*******************************************
Best Regards
Eirik Karlsen
 

--- In , "bsjoelund" <tecnoconsult@t...> wrote:
> Hi,
> Is this doable with PIC16F84 (DYI poormans encoder)
>
> Input waveform 2 channels (up to 200/rev)
> Ch1 ----____----____----____----____----____----____----____
> Ch2 --____----____----____----____----____----____----____
> CH3 ----____---------------
> sync 1/rev or x/rev
>
> RA0 Ch1
> RA1 Ch2
> RA2 Ch3 (if needed and as many pulses/rev as needed)
> RA3 Sync ( as many pulses/rev as needed)
>
> outputs to be multiplied (examples)
> RB0 2x Ch1
> RB1 2x Ch2
> RB2 4x Ch1
> RB3 4x Ch2
> RB4 10x Ch1
> RB5 10x Ch2
> RB6 100x Ch1
> RB7 100x Ch2
>
> Any help would be appreciated, I would like to do remote jogging
> wheel for CNC lathe with no manual feed. I still like to have the
> *manual* feeling in my hand :)
>
> Bengt

Hi Bengt,

google grey wheel for the pattern you may want.

A single line encoder will offer a pulse for each state change, and a
A second line will offer the abiltiy to determin rotation.

The grey wheel pattern is set so that you can determine posistion, or
in your case, distance from the starting point.

Someone mentioned newer printers, but I have some old-old printers
that have encoders on the DC heads. From a time before steppers.....

Dave