Last active
October 3, 2016 17:35
-
-
Save Jacajack/02f1080df4cdb79b5ba5fed9f069eefe to your computer and use it in GitHub Desktop.
ATmega328p ADC snippet
This file contains hidden or 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 <avr/io.h> | |
#include <inttypes.h> | |
#include "adc.h" | |
void adcenable( ) | |
{ | |
//Enable ADC | |
ADCSRA = ( 1 << ADEN ); | |
} | |
void adcdisable( ) | |
{ | |
//Disable ADC | |
ADCSRA &= ~( 1 << ADEN ); | |
} | |
uint16_t adcread( uint8_t mux ) | |
{ | |
//Read data from selected ADC (VCC as reference volatge) | |
ADMUX = ( mux << MUX0 ) | ( 1 << REFS0 ); | |
ADCSRA |= ( 1 << ADSC ); | |
while ( ADCSRA & ( 1 << ADSC ) ); | |
return ADC; | |
} |
This file contains hidden or 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
#ifndef ADC_H | |
#define ADC_H | |
#include <avr/io.h> | |
#include <inttypes.h> | |
extern void adcenable( ); | |
extern void adcdisable( ); | |
extern uint16_t adcread( uint8_t mux ); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment