예제 #1
0
파일: system.c 프로젝트: dz3/CpE391
void SetupADC(void)
{
    unsigned int config1;
    unsigned int config2;
    unsigned int config3;
    unsigned int config4;
    unsigned int configport_h;
    unsigned int configport_l;
    unsigned int configscan_h;
    unsigned int configscan_l;

// TODO explain these settings
    config1 = ADC_MODULE_ON & ADC_IDLE_STOP & ADC_ADDMABM_ORDER & ADC_AD12B_12BIT & ADC_FORMAT_INTG
            & ADC_CLK_AUTO & ADC_AUTO_SAMPLING_OFF & ADC_SIMULTANEOUS & ADC_SAMP_OFF;
    config2 = ADC_VREF_AVDD_AVSS & ADC_SCAN_OFF & ADC_DMA_ADD_INC_1 & ADC_ALT_BUF_OFF
            & ADC_ALT_INPUT_OFF;
    config3 = ADC_SAMPLE_TIME_4 & ADC_CONV_CLK_SYSTEM & ADC_CONV_CLK_6Tcy;
    config4 = ADC_DMA_BUF_LOC_1;

    configport_h = ENABLE_ALL_DIG_16_31;
    configport_l = ENABLE_AN0_ANA;

    configscan_h = SCAN_ALL_16_31;
    configscan_l = SCAN_ALL_0_15;

    OpenADC1(config1,config2,config3,config4,configport_l,configport_h, configscan_h,configscan_l);
    DisableIntADC1();
}
예제 #2
0
static void adcSetupPeripheral(void){
	unsigned int AD1CON1value, AD1CON2value, AD1CON3value, AD1CON4value, 
				AD1PCFGHvalue, AD1PCFGLvalue, AD1CSSHvalue, AD1CSSLvalue, 
				AD1CHS0value, AD1CHS123value;

	//Setup:
	//ADC1 : Ch0 - AN11 then AN1
	//		 Ch1 - AN0 then AN3
	//ADC2 : Left unconfigured for user applications

	AD1CON1value = ADC_MODULE_ON & 			//ADC module is enabled
				   ADC_IDLE_CONTINUE & 		// ADC will continue in idle mode 
                   ADC_AD12B_10BIT & 		// ADC in 10 bit mode
				   ADC_FORMAT_INTG & 		// ADC in integer format (CLARIFY)
				   ADC_CLK_MPWM & 			// MCPWM interval ends sampling and starts conversion
                   ADC_SIMULTANEOUS & 		//Simultaneously sample CH0 and CH1
				   ADC_ADDMABM_ORDER &		//DMA buffers are written in the order of conversion
				   ADC_AUTO_SAMPLING_ON & 	//ADC does not need to be triggered manually
				   ADC_SAMP_ON;				//sample / hold amplifiers are sampling  (maybe incorrect)
    AD1CON2value = ADC_VREF_AVDD_AVSS & 	//Vref+ = AVdd , Vref- = AVss
				   ADC_SCAN_OFF & 			//Do not scan through ADC channels
				   ADC_SELECT_CHAN_01 & 	//Sample & convert 
				   ADC_ALT_BUF_OFF &		//Use one 16 word buffer
				   ADC_ALT_INPUT_ON & 		// Alternate between MUXA and MUXB
				   ADC_DMA_ADD_INC_2;		//Increment DMA address after 2 samples, to account for alt. sampling
    AD1CON3value = ADC_CONV_CLK_SYSTEM & 	//Use System clock, not internal RC osc
				   ADC_CONV_CLK_3Tcy & 		//Tad = 3 * Tcy
				   ADC_SAMPLE_TIME_1; 		//Sample Time = 1*Tad
	AD1CON4value = ADC_DMA_BUF_LOC_4; 		//This may be wrong (TODO)
	
    
	AD1CHS123value = ADC_CH123_NEG_SAMPLEA_VREFN & 	// Sample A, Vref- = AVss
					 ADC_CH123_POS_SAMPLEA_0_1_2 & 	// Sample A, CH1=AN0, CH2=AN1, CH3=AN2
					 ADC_CH123_NEG_SAMPLEB_VREFN & 	// Sample B, Vref- = AVss
					 ADC_CH123_POS_SAMPLEB_3_4_5;  	// Sample B, CH1=AN3, CH2=AN4, CH3=AN5

 	AD1CHS0value = ADC_CH0_NEG_SAMPLEA_VREFN & 		// Sample A, Vref- = AVss
				   ADC_CH0_POS_SAMPLEA_AN11 & 		// Sample A, CH0 = AN11
				   ADC_CH0_NEG_SAMPLEB_VREFN & 		// Sample B, Vref- = AVss
				   ADC_CH0_POS_SAMPLEB_AN1; 		// Sample A, CH0 = AN1
					 

    AD1CSSHvalue = SCAN_NONE_16_31; 				//Skip AN16-AN131 for Input Scan
	AD1CSSLvalue = SCAN_NONE_0_15; 					//Skip AN0-AN15 for Input Scan

	//Set pins to analog inputs; also check init_default.c
	AD1PCFGHvalue = ENABLE_ALL_DIG_16_31; //Shouldn't matter, only AN0-15 on 706A
    AD1PCFGLvalue = ENABLE_AN0_ANA & ENABLE_AN1_ANA & ENABLE_AN3_ANA & ENABLE_AN11_ANA;
	 
    SetChanADC1(AD1CHS123value, AD1CHS0value);
    OpenADC1(AD1CON1value, AD1CON2value, AD1CON3value, AD1CON4value, AD1PCFGLvalue, AD1PCFGHvalue, AD1CSSHvalue, AD1CSSLvalue);
	
	IFS0bits.AD1IF = 0; // Clear the A/D interrupt flag bit
	IEC0bits.AD1IE = 0; //Disable A/D interrupt
}
예제 #3
0
void initAdc1(void)
{

	//Using the adc peripheral library, configure ADC1 as follows:
		// 12-bit
		// sample off of AN0
		// Use dedicated ADC RC oscillator
		// Automatically start new conversion after previous
		// Use Avdd and Avss as reference levels

	OpenADC1(
				ADC_MODULE_OFF & ADC_AD12B_12BIT & ADC_FORMAT_INTG & ADC_CLK_AUTO & ADC_AUTO_SAMPLING_ON,
				ADC_VREF_AVDD_AVSS & ADC_SCAN_OFF,
				ADC_SAMPLE_TIME_31 & ADC_CONV_CLK_INTERNAL_RC,
				ADC_DMA_BUF_LOC_1,
				ENABLE_AN0_ANA,
				ENABLE_ALL_DIG_16_31,
				0,
				0);

	AD1CON1bits.ADON = 1;	//Turn on ADC
}