Alex said:
Maxim MAXQ2000: Maxim's answer to the MSP430
Only for the LCD routine, there's a timer interrupt
every 3/4 of a second or so. The A and B encoder lines are
continuously polled in an endless loop and if I get a result
that indicates a missed increment say 1,1 to 0,0 I look back
to the previous change to determine if it's up or down and then
increment or decrement by 2 accordingly. It's fast enough if
you don't manually flick the encoder shaft fast up and down
repeatedly.
More efficent way of coding the conversion ? lookup
table ?
I threw away the "encoder counter to degrees" conversion routine to
reduce code size and write the encoder binary data directly to
LCD registers using the routines below:
The extraction of each individual decimal digit from the 16 bit
binary count relies on a modulus by a power of ten to remove
the digits above the wanted digit then a divide by a power of
ten to reduce the digit to a value between 0 and 9 including
decimal places which I then trim by saving into an integer.
I'm using the hardware multiplier as much as possible: a multiply
by a reciprocal- A * 0.1, instead of A / 10 saves about 30 bytes
at compile time, I'm assuming because the compiler does the
divide in code
So the conversion uses a modulus and a multiply to get each
of the five digits which are then converted to seven segment
form with an array look up to return a byte to write to the LCD
I/O register.
By setting the compile time options to "fastest" and turning off
all debug options I get the code down from 2200 odd bytes to
below 600 bytes and still have the very occasional problem that
may not affect the production units as I doubt you could spin
them that fast due to physical mass considerations.
What about using a second slave micro conected via spi?
You already have the tools and are used to using them.
Depends on what you want/requirements.
A larger / faster micro maybe cheaper than adding a cpld.
If its just a simple quadrature decoder circuit with
a serial shift register output of a binary up/down counter.
You maybe able to replace the micro with a cpld.
I'm going to use the LSI LS7366R to start with: it's a 4X
quadrature decoder /binary counter IC with SPI interface. After
that I'll have time to build a simple logic 4X quadrature
decoder circuit in logic gates to interface with the micro's hardware
up/down binary counter. Either option would then have the micro only
handling the conversion of the binary value to seven segment LCD.
One solution that just occurred to me is that I can detect
when the encoder is stationary and then and only then, run the LCD
update: this may entirely fix the problems.
Mark