I'm working one one right now. I just got started playing with AVRs
(professionally I work with Freescale parts)
My personal goal is to create digital readouts for the little lathe
and mill I have out in the garage. I intend this to be a
multiprocessor device, with a separte AT90S2313 doing the quadrature
(the scales attached to the machine put out a 90 degree phase-shifted
waveform) decoding and counting for each axis (2 for the lathe, 3 for
the mill) and I haven't made up my mind what I'm going to use for a
master display processor. At first, I'm going to want to just have a
basic display of position, but then, as I go along, I want to add
really fancy features such as: "Enter a center point, a diameter, a
number of holes, and whether or not I'm making an arc or a circle.
Then compute the locations for each hole in the arc or circle and
adjust the display so I can manually center the workpiece for each
hole before drilling". Maybe some day perhaps go all the way to
complete numerical control.
If someone could share a nice quadrature decoding routine?
Zack Widup wrote:
> Is there an assembly language version of that?
>
> Zack
>
> On Tue, Nov 3, 2009 at 4:19 AM, Marc R.J. Brevoort <mrjb@dnd.utwente.nl>wrote:
>
>>
>> Hi Erik,
>>
>>
>>> Who ever came up with this orignally was a frickin' genius.
>>> Sure, it's for PIC but the code is in C.
>>> A little helpful cut-n-paste to give you the basic idea.
>>>
>>> ;static unsigned clock_A,clock_B,debounced_state;
>>> ;unsigned debounce(unsigned new_sample)
>>> ;{
>>> ; unsigned delta;
>>> ; unsigned changes;
>>> ;
>>> ; delta = new_sample ^ debounced_state; //Find all of the changes
>>> ;
>>> ; clock_A ^= clock_B; //Increment the counters
>>> ; clock_B = ~clock_B;
>>> ;
>>> ; clock_A &= delta; //Reset the counters if no changes
>>> ; clock_B &= delta; //were detected.
>>> ;
>>> ; changes = ~(~delta | clock_A | clock_B);
>>> ; debounced_state ^= changes;
>>> ;
>>> ; return changes;
>>> ;} /* debounce */
>>> ;
>>>
>>> The cool thing is that this can debounce a whole port at once. It
>>> runs in an interrupt routine.
>> Thanks. I've got a single button debounce by now, but this one is
>> quite nice due to its multi-input nature. I've saved it to my favs for
>> future reference.
>>
>> Best,
>> MarcMessage
Re: [AVR-Chat] ATtiny2313 button handler
2009-11-03 by erikc
Attachments
- No local attachments were found for this message.