Jump to content

Capture the highest value of AIN? (track and hold)


sneakthief
 Share

Recommended Posts

What's the best routine to capture the peak value from an analog in pin?

I'm working on a gesture-based instrument, in specific, a glove with a 3-axis accelerometer on it. It's obviously impossible to maintain some kind of constant acceleration with one's hand, so instead I want to choose a note based on how fast I move my hand along an axis.

That means taking the maximum (or minimum) AIN-reading each time it passes a threshold, like some kind of track-and-hold.

Here's my first prototype, with an accelerometer, flex sensor and finger contacts using conductive thread:

glovetest1.jpg

This is just for testing, unlike my 2nd prototype below which has a proper glove, smaller case and TQFP (!) SMD PIC18F:

glovetest1b.jpg

Link to comment
Share on other sites

Nice work! :)

I think that the a "deadband" algorithm would be sufficient, it's already integrated into MIOS -> MIOS_AIN_DeadbandSet

You could also dynamically decrease the deadband if your application notices a fast movement, and set it to a higher value again if it stops.

The C implementation of the deadband can be found in the MIOS32 variant under: http://svnmios.midibox.org/filedetails.php?repname=svn.mios32&path=%2Ftrunk%2Fmios32%2FLPC17xx%2Fmios32_ain.c

This one even supports a "spike filter", which could be helpful for your application as well! :)

Best Regards, Thorsten.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...