|
// //########################################################################### // // FILE: Example_28xAdc.c // // TITLE: DSP28 ADC Example Program. // // ASSUMPTIONS: // // This program requires the DSP28 header files. To compile the // program as is, it should reside in the DSP28/examples/adc // sub-directory. // // As supplied, this project is configured for "boot to H0" operation. // // DESCRIPTION: // // This example sets up the PLL in x10/2 mode, divides SYSCLKOUT // by six to reach a 25Mhz HSPCLK (assuming a 30Mhz XCLKIN). The // clock divider in the ADC is not used so that the ADC will see // the 25Mhz on the HSPCLK. Interrupts are enabled and the EVA // is setup to generate a periodic ADC SOC on SEQ1. Two channels // are converted, ADCINA3 and ADCINA2. // // Watch Variables: // // Voltage1[10] Last 10 ADCRESULT0 values // Voltage2[10] Last 10 ADCRESULT1 values // ConversionCount Current result number 0-9 // LoopCount Idle loop counter // // //########################################################################### // // Ver | dd mmm yyyy | Who | Description of changes // =====|=============|======|=============================================== // 0.58| 18 Jun 2002 | D.F. | Original Release //###########################################################################
// Step 0. Include required header files // DSP28_Device.h: device specific definitions #include statements for // all of the peripheral .h definition files. // DSP28_Example.h is specific for the given example.
#include "DSP28_Device.h"
// Prototype statements for functions found within this file. interrupt void adc_isr(void);
// Global variables used in this example: Uint16 LoopCount; Uint16 ConversionCount; Uint16 Voltage1[10]; Uint16 Voltage2[10];
main() {
// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to default state: // This function is found in the DSP28_SysCtrl.c file. InitSysCtrl();
// For this example, set HSPCLK to SYSCLKOUT / 6 (25Mhz assuming 150Mhz SYSCLKOUT) EALLOW; SysCtrlRegs.HISPCP.all = 0x3; // HSPCLK = SYSCLKOUT/6 EDIS; // Step 2. Select GPIO for the device or for the specific application: // This function is found in the DSP28_Gpio.c file. // InitGpio(); // Not required for this example
// Step 3. Initialize PIE vector table: // The PIE vector table is initialized with pointers to shell Interrupt // Service Routines (ISR). The shell routines are found in DSP28_DefaultIsr.c. // Insert user specific ISR code in the appropriate shell ISR routine in // the DSP28_DefaultIsr.c file.
// Disable and clear all CPU interrupts: DINT; IER = 0x0000; IFR = 0x0000;
// Initialize Pie Control Registers To Default State: // This function is found in the DSP28_PieCtrl.c file. InitPieCtrl();
// Initialize the PIE Vector Table To a Known State: // This function is found in DSP28_PieVect.c. // This function populates the PIE vector table with pointers // to the shell ISR functions found in DSP28_DefaultIsr.c. InitPieVectTable();
// Step 4. Initialize all the Device Peripherals to a known state: // This function is found in DSP28_InitPeripherals.c // InitPeripherals(); // For this example just init the ADC InitAdc(); // DSP28_Adc.c
// Step 5. User specific functions, Reassign vectors (optional), Enable Interrupts: // Reassign ADC ISR. // Reassign the PIE vector for the ADC to point to a different ISR then // the shell routine found in DSP28_DefaultIsr.c. // This is done if the user does not want to use the shell ISR routine // but instead wants to use their own ISR. This step is optional: EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.ADCINT = &adc_isr; EDIS; // This is needed to disable write to EALLOW protected registers
// Include application specific functions. This is for this example:
// Enable ADCINT in PIE PieCtrlRegs.PIEIER1.bit.INTx6 = 1; // Enable CPU Interrupt 1 IER |= M_INT1; // Enable Global INT1
// Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM
LoopCount = 0; ConversionCount = 0; // Configure ADC AdcRegs.ADCMAXCONV.all = 0x0001; // Setup 2 conv's on SEQ1 AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x3; // Setup ADCINA3 as 1st SEQ1 conv. AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // Setup ADCINA2 as 2nd SEQ1 conv. AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1; // Enable EVASOC to start SEQ1 AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
// Configure EVA // Assumes EVA Clock is already enabled in InitSysCtrl(); EvaRegs.T1CMPR = 0x0080; // Setup T1 compare value EvaRegs.T1PR = 0xFFFF; // Setup period register EvaRegs.GPTCONA.bit.T1TOADC = 1; // Enable EVASOC in EVA EvaRegs.T1CON.all = 0x1042; // Enable timer 1 compare (upcount mode)
// Wait for ADC interrupt while (1) { LoopCount++; }
}
interrupt void adc_isr(void) {
Voltage1[ConversionCount] = AdcRegs.ADCRESULT0; Voltage2[ConversionCount] = AdcRegs.ADCRESULT1;
// If 40 conversions have been logged, start over if(ConversionCount == 9) { ConversionCount = 0; } else ConversionCount++;
// Reinitialize for next ADC sequence AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1 AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE return; }
|