-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fast analog #27
Fast analog #27
Conversation
fsr/FastADC.h
Outdated
@@ -0,0 +1,19 @@ | |||
// defines for setting and clearing register bits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the stuff in this file is small enough that it can just be in the main ino for now (and also move the fsr.ino back to the original location). I do plan on splitting up the file a bit later down the road.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh ok, i figured that a lot of the features needed to be double wrapped (e.g. EEpromEX for ATmega vs teensy is different) and a bunch of those C++ classes could move. But if you want to do that on your own i'll move everything back.
fsr/fsr.ino
Outdated
#include <inttypes.h> | ||
|
||
#if !defined(__AVR_ATmega32U4__) && !defined(__AVR_ATmega328P__) && \ | ||
!defined(__AVR_ATmega1280__) && !defined(__AVR_ATmega2560__) | ||
#define CAN_AVERAGE | ||
#define FASTADC 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if statement is for boards that ARE teensy. I would remove this altogether in favor of the changes suggested above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, sorry i didnt do it right ;(
fsr/fsr.ino
Outdated
@@ -1,10 +1,14 @@ | |||
#include "FastADC.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this library and do the following:
At the top have this:
#if defined(_SFR_BYTE) && defined(_BV) && defined(ADCSRA)
#define CLEAR_BIT(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define SET_BIT(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
And then in setup do
#if defined(CLEAR_BIT) && defined(SET_BIT)
// Set the ADC prescaler to 16 for boards that support it,
// which is a good balance between speed and accuracy.
// More information can be found here: http://www.gammon.com.au/adc
SET_BIT(ADCSRA, ADPS2);
CLEAR_BIT(ADCSRA, ADPS1);
CLEAR_BIT(ADCSRA, ADPS0);
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on wrapping that second part in a function such as SetFastAnalog()?
I made all the changes. If you want i can squash them all into one (or you can do that :) ) :) |
Hi just nudging this since the sooner its merged the better :) |
AH SORRY I didn't really see the update. I think this looks good! I haven't personally tested this for Teensy (and it seems like it's possible for it to run for Teensy with the current control flow). Do you know if this works for Teensys and the behavior one might see? |
Unfortunately I am a poor Australian who can only afford a bucket of pro micros, so I have not tested with teensy. |
Yeah I think it should be okay too. I'll merge this and if someone complains that something has been broken I can always adjust things easily. Thanks for the PR! |
(Also what's your discord so I can credit you?) |
Short PR to allow Fast Analog reads on non Teensies.
I've also moved the
.ino
file into a folder calledfsr
, so that relative imports work cleanly.