You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
1.9 KiB

/*
* pru_adc.c
*
* Created on: Aug 24, 2016
* Author: gagua
*/
#include "pru_adc.h"
void init_adc1( void ){
uint8_t index;
ADC1_REGS.CTRL &= 0xFFFFFFFE; // Disable ADC
ADC1_REGS.CTRL_bit.PREAMP_BYPASS = ADC_ENABLE; // Bypas Preamps
ADC1_REGS.CTRL_bit.STEP_ID_TAG = ADC_ENABLE;
#ifdef ADC_WORK_SIMULTANEOUS_MODE
ADC1_REGS.CTRL_bit.SIMULTANEOUS_CONTROL = ADC_ENABLE; // ADC1+ADC0 control
#else
ADC1_REGS.CTRL_bit.SIMULTANEOUS_CONTROL = ADC_DISABLE; // ADC1+ADC0 control
#endif
ADC1_REGS.CLKDIV = 0; // Full Speed
ADC1_REGS.IDLECONFIG = 0;
ADC1_REGS.STEPEN = 0; // Disable FSM
// Configure FSM
for( index = 0; index< 8; index++ ){ // Use 8 slots of FSM to preform conversion of 8 channels
ADC1_REGS.STEPCONFIG[index].CONFIG = 0; // Reset Step Config
// Set to One-Shot mode
ADC1_REGS.STEPCONFIG[index].CONFIG_bit.MODE = ADC_MODE_SOFT_ONESHOT;
// Set Input Positive Chanel
ADC1_REGS.STEPCONFIG[index].CONFIG_bit.SEL_INP = index;
// Set Input Negative Chanel
ADC1_REGS.STEPCONFIG[index].CONFIG_bit.SEL_INM = ADC_INM_VREFN;
// Set Reference Positive Chanel
ADC1_REGS.STEPCONFIG[index].CONFIG_bit.SEL_RFP = ADC_RFP_VDDA;
// Set Reference Negative Chanel
ADC1_REGS.STEPCONFIG[index].CONFIG_bit.SEL_RFM = ADC_RFM_VREFN;
ADC1_REGS.STEPCONFIG[index].CONFIG_bit.RANGE_CHECK_INTR = ADC_DISABLE;
ADC1_REGS.STEPCONFIG[index].CONFIG_bit.DIFF_CNTRL = ADC_DISABLE;
ADC1_REGS.STEPCONFIG[index].CONFIG_bit.AVERAGING = ADC_AVERAGE_NONE;
ADC1_REGS.STEPCONFIG[index].STEPDELAY_bit.OPENDELAY = 200;
ADC1_REGS.STEPCONFIG[index].STEPDELAY_bit.SAMPLEDELAY = 10;
};
ADC1_REGS.CTRL_bit.ADC_EN = ADC_ENABLE;
};
uint32_t getADC_FIFO( uint32_t id ){
if( id == 0 ){
return ADC1_REGS.FIFO0COUNT;
};
return ADC1_REGS.FIFO1COUNT;
};
void captureAll( void ){
ADC1_REGS.STEPEN = 0x01FE; // Enable 8 Steps of FSM
};