Skip to content
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

Merged
merged 4 commits into from
Nov 23, 2021
Merged

Fast analog #27

merged 4 commits into from
Nov 23, 2021

Conversation

alex-ong
Copy link
Contributor

Short PR to allow Fast Analog reads on non Teensies.
I've also moved the .ino file into a folder called fsr, so that relative imports work cleanly.

@alex-ong
Copy link
Contributor Author

Solves #26 and #21

fsr/FastADC.h Outdated
@@ -0,0 +1,19 @@
// defines for setting and clearing register bits
Copy link
Owner

@teejusb teejusb Oct 30, 2021

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.

Copy link
Contributor Author

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
Copy link
Owner

@teejusb teejusb Oct 30, 2021

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.

Copy link
Contributor Author

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 Show resolved Hide resolved
fsr/fsr.ino Outdated
@@ -1,10 +1,14 @@
#include "FastADC.h"
Copy link
Owner

@teejusb teejusb Oct 30, 2021

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

Copy link
Contributor Author

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()?

@alex-ong
Copy link
Contributor Author

I made all the changes. If you want i can squash them all into one (or you can do that :) )

:)

@alex-ong
Copy link
Contributor Author

Hi just nudging this since the sooner its merged the better :)

@teejusb
Copy link
Owner

teejusb commented Nov 23, 2021

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?

@alex-ong
Copy link
Contributor Author

Unfortunately I am a poor Australian who can only afford a bucket of pro micros, so I have not tested with teensy.
Teensy 2.0 uses 32U4, so it should automatically work.
For teensy 3.0+, they use MK20DX256 32 bit ARM Cortex-M4 72 MHz, so the code should slide by without affecting it. They might already read analog quickly; i don't know since i've never dabbled in teensy land

@teejusb
Copy link
Owner

teejusb commented Nov 23, 2021

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!

@teejusb teejusb merged commit aaa73ef into teejusb:master Nov 23, 2021
@teejusb
Copy link
Owner

teejusb commented Nov 23, 2021

(Also what's your discord so I can credit you?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants