void InitADC(void) { EALLOW; //write configurations AdcaRegs.ADCCTL2.bit.PRESCALE = 0X2; //set ADCCLK divider to /4 AdcbRegs.ADCCTL2.bit.PRESCALE = 0X2; //set ADCCLK divider to /4 AdccRegs.ADCCTL2.bit.PRESCALE = 0X2; //set ADCCLK divider to /4 AdcdRegs.ADCCTL2.bit.PRESCALE = 0X2; //set ADCCLK divider to /4 AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); AdcSetMode(ADC_ADCC, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); AdcSetMode(ADC_ADCD, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); //Set pulse positions to late AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1; AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1; AdccRegs.ADCCTL1.bit.INTPULSEPOS = 1; AdcdRegs.ADCCTL1.bit.INTPULSEPOS = 1; //power up the ADC AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1; AdccRegs.ADCCTL1.bit.ADCPWDNZ = 1; AdcdRegs.ADCCTL1.bit.ADCPWDNZ = 1; //delay for 1ms to allow ADC time to power up DELAY_US(1000); EDIS; SetupADC(); }
void InitADC(void) { //ADCINB2// //pin 26 on board// AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); EALLOW; CpuSysRegs.PCLKCR13.bit.ADC_B = 1; //ADC_B Clock Enable AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //ADCCLK = Input Clock / 4.0 = 50MHz AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1; //All analog circuitry inside the core is powered up AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1; //Interrupt pulse generation occurs at the end of the conversion AdcbRegs.ADCSOC0CTL.bit.TRIGSEL = 0x0B; //ADCTRIG11 - ePWM4, ADCSOCA trigger; AdcbRegs.ADCSOC0CTL.bit.CHSEL = 2; //ADCIN2: pin 26 on baord AdcbRegs.ADCSOC0CTL.bit.ACQPS = 40; //sample window is number + 1 SYSCLK cycles AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //EOC0 is trigger for ADCINT1 AdcbRegs.ADCINTSEL1N2.bit.INT1E = 1; //Enable ADCINT1 PieVectTable.ADCB1_INT = &adcb1_isr; //int 1.2 IER |= M_INT1; //Enable group 1 interrupts EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM PieCtrlRegs.PIEIER1.bit.INTx2 = 1; //Interrupt Enable for INT1.2 ClkCfgRegs.PERCLKDIVSEL.bit.EPWMCLKDIV = 1; //PWMFeq=100MHz CpuSysRegs.PCLKCR2.bit.EPWM4=1; //Disable Clock Gating EPwm4Regs.TBCTL.bit.CTRMODE = 00; //Up count mode EPwm4Regs.TBCTL.bit.HSPCLKDIV = 0x0; //Clock ratio to SYSCLKOUT = 1 EPwm4Regs.TBCTL.bit.CLKDIV = 0x0; EPwm4Regs.TBPRD = 2000; //freq: 50kHz EPwm4Regs.ETSEL.bit.SOCASEL = 1; // Enable event time-base counter equal to zero EPwm4Regs.ETPS.bit.SOCAPRD = 1; // 1 Event has occured for SOCA EPwm4Regs.ETSEL.bit.SOCAEN = 1; // Enable SOCA CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1; //start PWM counters EDIS; }
// // ConfigureADC - Write ADC configurations and power up the ADC for both // ADC A and ADC B // void ConfigureADC(void) { EALLOW; // //write configurations // AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4 AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); // //Set pulse positions to late // AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1; // //power up the ADC // AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; // //delay for 1ms to allow ADC time to power up // DELAY_US(1000); EDIS; }
void main() { volatile int status = 0; uint16_t i; volatile FILE *fid; // If running from flash copy RAM only functions to RAM #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif // Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the F2806x_SysCtrl.c file. InitSysCtrl(); // For this example, only init the pins for the SCI-A port. EALLOW; GpioCtrlRegs.GPCMUX2.bit.GPIO84 = 1; GpioCtrlRegs.GPCMUX2.bit.GPIO85 = 1; GpioCtrlRegs.GPCGMUX2.bit.GPIO84 = 1; GpioCtrlRegs.GPCGMUX2.bit.GPIO85 = 1; EDIS; // Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the F2806x_PieCtrl.c file. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in F2806x_DefaultIsr.c. // This function is found in F2806x_PieVect.c. InitPieVectTable(); // Initialize SCIA scia_init(); //Initialize GPIOs for the LEDs and turn them off EALLOW; GpioCtrlRegs.GPADIR.bit.GPIO12 = 1; GpioCtrlRegs.GPADIR.bit.GPIO13 = 1; GpioDataRegs.GPADAT.bit.GPIO12 = 1; GpioDataRegs.GPADAT.bit.GPIO13 = 1; EDIS; // Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM // Configure the ADC: // Initialize the ADC EALLOW; //write configurations AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4 AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4 AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); //Set pulse positions to late AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1; AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1; //power up the ADCs AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1; //delay for 1ms to allow ADC time to power up DELAY_US(1000); //ADCA EALLOW; AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0x0E; //SOC0 will convert pin ADCIN14 AdcaRegs.ADCSOC0CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles AdcaRegs.ADCSOC1CTL.bit.CHSEL = 0x0E; //SOC1 will convert pin ADCIN14 AdcaRegs.ADCSOC1CTL.bit.ACQPS = 25; //sample window is acqps + 1 SYSCLK cycles AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 1; //end of SOC1 will set INT1 flag AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared //Redirect STDOUT to SCI status = add_device("scia", _SSA, SCI_open, SCI_close, SCI_read, SCI_write, SCI_lseek, SCI_unlink, SCI_rename); fid = fopen("scia","w"); freopen("scia:", "w", stdout); setvbuf(stdout, NULL, _IONBF, 0); //Print a TI Logo to STDOUT drawTILogo(); //Twiddle LEDs GpioDataRegs.GPADAT.bit.GPIO12 = 0; GpioDataRegs.GPADAT.bit.GPIO13 = 1; for(i = 0; i < 50; i++){ GpioDataRegs.GPATOGGLE.bit.GPIO12 = 1; GpioDataRegs.GPATOGGLE.bit.GPIO13 = 1; DELAY_US(50000); } //LEDs off GpioDataRegs.GPADAT.bit.GPIO12 = 1; GpioDataRegs.GPADAT.bit.GPIO13 = 1; //Clear out one of the text boxes so we can write more info to it clearTextBox(); currentSample = sampleADC(); //Main program loop - continually sample temperature for(;;) { //Sample ADCIN14 currentSample = sampleADC(); //Update the serial terminal output updateDisplay(); //If the sample is above midscale light one LED if(currentSample > 2048){ GpioDataRegs.GPADAT.all = 0x2000; }else{ //Otherwise light the other GpioDataRegs.GPADAT.all = 0x1000; } DELAY_US(1000000); } }