Part Number: TMS320F28379D
Tool/software: Code Composer Studio
Hi,
I modified the code adc_soc_software_cpu01.c for acquire all 16 ADC channels available, but I don't know how to print this data with the function printf to the console. Data are stored in AdcRegs and I can see them during the run of the code. The problem is: how can I print data stored in registers like variables (possibly in decimal value and not in hexadecimal)? I looked for in internet and in the forum but I didn't find anything. Thanks for answers.
//
// Included Files
//
#include "F28x_Project.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <file.h>
#include <math.h>
//
// Function Prototypes
//
void ConfigureADC(void);
void SetupADCSoftware(void);
//
// Globals
//
Uint16 AdcaResult0;
Uint16 AdcaResult1;
Uint16 AdcaResult2;
Uint16 AdcaResult3;
Uint16 AdcaResult4;
Uint16 AdcaResult5;
Uint16 AdcbResult0;
Uint16 AdcbResult1;
Uint16 AdcbResult2;
Uint16 AdcbResult3;
Uint16 AdccResult0;
Uint16 AdccResult1;
Uint16 AdccResult2;
Uint16 AdccResult3;
Uint16 AdcdResult0;
Uint16 AdcdResult1;
void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xD_SysCtrl.c file.
//
InitSysCtrl();
//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xD_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
InitGpio();
//
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
//
DINT;
//
// Initialize the 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 F2837xD_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 F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
//
InitPieVectTable();
//
// Enable global Interrupts and higher priority real-time debug events:
//
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
//
//Configure the ADCs and power them up
//
ConfigureADC();
//
//Setup the ADCs for software conversions
//
SetupADCSoftware();
//
//take conversions indefinitely in loop
//
do
{
//
//convert, wait for completion, and store results
//start conversions immediately via software, ADCA
//
AdcaRegs.ADCSOCFRC1.all = 0x003F; //SOC0 to SOC5
//
//start conversions immediately via software, ADCB
//
AdcbRegs.ADCSOCFRC1.all = 0x000F; //SOC0 to SOC3
//
//start conversions immediately via software, ADCC
//
AdccRegs.ADCSOCFRC1.all = 0x000F; //SOC0 to SOC3
//
//start conversions immediately via software, ADCD
//
AdcdRegs.ADCSOCFRC1.all = 0x0003; //SOC0 and SOC1
//
//wait for ADCA to complete, then acknowledge flag
//
while(AdcaRegs.ADCINTFLG.bit.ADCINT1 == 0);
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
//
//wait for ADCB to complete, then acknowledge flag
//
while(AdcbRegs.ADCINTFLG.bit.ADCINT1 == 0);
AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
//
//wait for ADCC to complete, then acknowledge flag
//
while(AdccRegs.ADCINTFLG.bit.ADCINT1 == 0);
AdccRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
//
//wait for ADCD to complete, then acknowledge flag
//
while(AdcdRegs.ADCINTFLG.bit.ADCINT1 == 0);
AdcdRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
//
//store results
//
AdcaResult0 = AdcaResultRegs.ADCRESULT0;
AdcaResult1 = AdcaResultRegs.ADCRESULT1;
AdcaResult2 = AdcaResultRegs.ADCRESULT2;
AdcaResult3 = AdcaResultRegs.ADCRESULT3;
AdcaResult4 = AdcaResultRegs.ADCRESULT4;
AdcaResult5 = AdcaResultRegs.ADCRESULT5;
AdcbResult0 = AdcbResultRegs.ADCRESULT0;
AdcbResult1 = AdcbResultRegs.ADCRESULT1;
AdcbResult2 = AdcbResultRegs.ADCRESULT2;
AdcbResult3 = AdcbResultRegs.ADCRESULT3;
AdccResult0 = AdccResultRegs.ADCRESULT0;
AdccResult1 = AdccResultRegs.ADCRESULT1;
AdccResult2 = AdccResultRegs.ADCRESULT2;
AdccResult3 = AdccResultRegs.ADCRESULT3;
AdcdResult0 = AdcdResultRegs.ADCRESULT0;
AdcdResult1 = AdcdResultRegs.ADCRESULT1;
//
//at this point, conversion results are stored
//
//
//software breakpoint, hit run again to get updated conversions
//
asm(" ESTOP0");
}while(1);
}
//
// ConfigureADC - Write ADC configurations and power up the ADC for
// ADC A, B, C and D
//
void ConfigureADC(void)
{
EALLOW;
//
//write configurations
//
AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdccRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcdRegs.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);
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 ADCs
//
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;
}
//
// SetupADCSoftware - Setup ADC channels and acquisition window
//
void SetupADCSoftware(void)
{
Uint16 acqps;
//
// Determine minimum acquisition window (in SYSCLKS) based on resolution
//
if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION)
{
acqps = 14; //75ns
}
else //resolution is 16-bit
{
acqps = 63; //320ns
}
//
//Select the channels to convert and end of conversion flag
//ADCA
//
EALLOW;
AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0; //SOC0 will convert pin A0
AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1; //SOC1 will convert pin A1
AdcaRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC2CTL.bit.CHSEL = 2; //SOC2 will convert pin A2
AdcaRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC3CTL.bit.CHSEL = 3; //SOC3 will convert pin A3
AdcaRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC4CTL.bit.CHSEL = 4; //SOC4 will convert pin A4
AdcaRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCSOC5CTL.bit.CHSEL = 5; //SOC5 will convert pin A5
AdcaRegs.ADCSOC5CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 5; //end of SOC5 will set INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
//ADCB
AdcbRegs.ADCSOC0CTL.bit.CHSEL = 2; //SOC0 will convert pin B2
AdcbRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC1CTL.bit.CHSEL = 3; //SOC1 will convert pin B3
AdcbRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC2CTL.bit.CHSEL = 4; //SOC2 will convert pin B4
AdcbRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCSOC3CTL.bit.CHSEL = 5; //SOC3 will convert pin B5
AdcbRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 3; //end of SOC3 will set INT1 flag
AdcbRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
//ADCC
AdccRegs.ADCSOC0CTL.bit.CHSEL = 2; //SOC0 will convert pin C2
AdccRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC1CTL.bit.CHSEL = 3; //SOC1 will convert pin C3
AdccRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC2CTL.bit.CHSEL = 4; //SOC2 will convert pin C4
AdccRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCSOC3CTL.bit.CHSEL = 5; //SOC3 will convert pin C5
AdccRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdccRegs.ADCINTSEL1N2.bit.INT1SEL = 3; //end of SOC3 will set INT1 flag
AdccRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
AdccRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
//ADCD
AdcdRegs.ADCSOC0CTL.bit.CHSEL = 14; //SOC0 will convert pin D14
AdcdRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcdRegs.ADCSOC1CTL.bit.CHSEL = 15; //SOC1 will convert pin D15
AdcdRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is acqps +
//1 SYSCLK cycles
AdcdRegs.ADCINTSEL1N2.bit.INT1SEL = 1; //end of SOC1 will set INT1 flag
AdcdRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
AdcdRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
EDIS;
}
//
// End of file
//