Last active
August 17, 2017 20:25
-
-
Save urmil0071/86a5b0b58a6363362a64bca1c76eef76 to your computer and use it in GitHub Desktop.
Read ADC Value on interrupt basis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<Arduino.h> | |
volatile int analogVal; | |
void setup() | |
{ | |
Serial.begin(9600); | |
ADMUX=0xC0; /// 1.1 V refrrence, Right adjust, channel 0 | |
bitWrite(ADCSRA,7,1); /// ADC Enabled | |
bitWrite(ADCSRA,5,1); /// Auto Triggering Enabled | |
ADCSRA |= B00000111; /// Pre Scaler to 1/128 | |
bitWrite(ADCSRA,3,1); ///Enabling ADC Interrupt | |
sei(); /// Enables Global Interrupt | |
bitWrite(ADCSRA,6,1); ///Start Convertion | |
} | |
void loop() | |
{ | |
} | |
ISR(ADC_vect) | |
{ | |
analogVal = ADCL + (ADCH << 8); | |
Serial.println(analogVal,DEC); | |
bitWrite(ADCSRA,6,1); ///Start Convertion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment