void initADCDMA (void) { // Configure Oscillator to operate the device at 40Mhz // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 // Fosc= 8M*40/(2*2)=80Mhz for 8M input clock PLLFBD=38; // M=40 CLKDIVbits.PLLPOST=0; // N1=2 CLKDIVbits.PLLPRE=0; // N2=2 OSCTUN=0; // Tune FRC oscillator, if FRC is used // Disable Watch Dog Timer RCONbits.SWDTEN=0; // clock switching to incorporate PLL __builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary Oscillator with PLL (NOSC=0b011) __builtin_write_OSCCONL(OSCCON || 0x01); // Start clock switching while (OSCCONbits.COSC != 0x03); // Wait for Clock switch to occur while(OSCCONbits.LOCK!=1) {}; // Wait for PLL to lock // Peripheral Initialisation initDma0(); // Initialise the DMA controller to buffer ADC data in conversion order initAdc1(); // Initialize the A/D converter to convert Channel 5 //Loop Endlessly - Execution is interrupt driven //from this point on. }
int main(void) { initAdc1(); //initialize ADC while (1) { calc_Vout(); //Calculate ADC result as a voltage calc_temp(); //Calculate Temperature } } //End of main
/**************************************************************************** Function: void AccelerometerInit( void ) Description: This routine sets up the ADC to sample the tri-axial outputs of the Accelerometer. Precondition: None Parameters: None Return Values: None Remarks: None ***************************************************************************/ void AccelerometerInit( void ) { initAdc1(); // Initialize the A/D sample accelerometer outputs }