rt_uint8_t battery_adc_initialize(void) { ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ROM_ADCHardwareOversampleConfigure(ADC0_BASE,64); ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2); ADCSequenceConfigure(ADC0_BASE, 3,ADC_TRIGGER_PROCESSOR, 0); ROM_ADCSequenceStepConfigure(ADC0_BASE,3, 0, ADC_CTL_CH1| ADC_CTL_IE |ADC_CTL_END); ROM_ADCSequenceEnable(ADC0_BASE, 3); rt_kprintf("battery_adc_initialize\n"); return 0; }
//***************************************************************************** // // Initializes the ADC. // //***************************************************************************** void ADCInit(void) { // // Set the ADC speed to 1 Msps. // ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); // // Configure the GPIOs used with the analog inputs. // GPIOPinTypeADC(ADC_POSITION_PORT, ADC_POSITION_PIN); GPIOPinTypeADC(ADC_CURRENT_PORT, ADC_CURRENT_PIN); GPIOPinTypeADC(ADC_VBUS_PORT, ADC_VBUS_PIN); GPIOPinTypeADC(ADC_VBOOTA_PORT, ADC_VBOOTA_PIN); GPIOPinTypeADC(ADC_VBOOTB_PORT, ADC_VBOOTB_PIN); // // Configure the ADC sample sequence that is triggered by PWM // generator 2 // ROM_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PWM0, 0); ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CURRENT_CH); ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_VBUS_CH); ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_POSITION_CH); ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 3, (ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END)); ROM_ADCSequenceEnable(ADC0_BASE, 0); // // Enable interrupts // ROM_ADCIntEnable(ADC0_BASE, 0); ROM_IntEnable(INT_ADC0SS0); // // Set the zero current to indicate that the initial sampling has just // begun. // g_usCurrentZero = 0xffff; }
//***************************************************************************** // // This function initializes the ADC hardware in preparation for data // acquisition. // //***************************************************************************** void AcquireInit(void) { unsigned long ulChan; // // Enable the ADC peripherals and the associated GPIO port // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |GPIO_PIN_7 | GPIO_PIN_3); ROM_GPIOPinTypeADC(GPIO_PORTP_BASE, GPIO_PIN_0); // ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V); //ROM_ADCR ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); HWREG(GPIO_PORTB_BASE + GPIO_O_AMSEL) |= GPIO_PIN_6; ADCSequenceDisable(ADC0_BASE,SEQUENCER); ROM_ADCSequenceConfigure(ADC0_BASE, SEQUENCER, ADC_TRIGGER_TIMER, 0); for(ulChan = 0; ulChan < 2; ulChan++) { unsigned long ulChCtl; if (ulChan ==1) { ROM_ADCSequenceStepConfigure(ADC0_BASE, SEQUENCER, ulChan, ADC_CTL_CH1|ADC_CTL_IE | ADC_CTL_END); } else if(ulChan==0) { ulChCtl = ADC_CTL_CH0; ROM_ADCSequenceStepConfigure(ADC0_BASE, SEQUENCER, ulChan, ADC_CTL_CH0); } } ADCHardwareOversampleConfigure(ADC0_BASE, 1); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER ); //100 micro unsigned long freq=SAMPLING_FREQUENCY; unsigned long period=(2*ROM_SysCtlClockGet()/(freq)); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A,period); ROM_TimerControlTrigger(TIMER0_BASE, TIMER_A, true); //ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); //ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() /2); CFAL96x64x16Init(); GrContextInit(&sDisplayContext, &g_sCFAL96x64x16); sRect1.sXMin = 0; sRect1.sYMin = 0; sRect1.sXMax = GrContextDpyWidthGet(&sDisplayContext) - 1; sRect1.sYMax = 23; sRect2.sXMin = 0; sRect2.sYMin = 23; sRect2.sXMax = GrContextDpyWidthGet(&sDisplayContext) - 1; sRect2.sYMax = GrContextDpyHeightGet(&sDisplayContext) - 1; snprintf(text,sizeof(text),"STart"); GrContextForegroundSet(&sDisplayContext, ClrDarkBlue); GrRectFill(&sDisplayContext, &sRect1); GrContextForegroundSet(&sDisplayContext, ClrWhite); //GrRectDraw(&sDisplayContext, &sRect1); GrContextFontSet(&sDisplayContext, g_pFontCm12); GrStringDrawCentered(&sDisplayContext,text, -1, GrContextDpyWidthGet(&sDisplayContext) / 2, 10, 0); //GrContextForegroundSet(&sDisplayContext, ClrDarkBlue); //GrRectFill(&sDisplayContext, &sRect1); //GrContextForegroundSet(&sDisplayContext, ClrWhite); //GrRectDraw(&sDisplayContext, &sRect1); /*GrContextForegroundSet(&sDisplayContext, ClrDarkBlue); GrRectFill(&sDisplayContext, &sRect2); GrContextForegroundSet(&sDisplayContext, ClrWhite); GrRectDraw(&sDisplayContext, &sRect2); */ compute_filter(); maxi1=0; maxi2=0; max1=0; max2=0; res=0; res1=0; g_ulADCCount=0; buffer_index=0; ulLastADCCount=0; }