This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Mathematical operations on DSP



Hi all,

I have ADC_SOC edited program. In my program I am having only one input. That is only one signal is converted and saved in voltage buffer. How can I find the rms value of that signal. I am using ccs 3.3

Regards,

Fasil

  • Hi Fasil,

    Check this thread: e2e.ti.com/.../317928

    Regards,
    Gautam
  • My requirement is that i need to find rms of a signal 0-3V which I have given as input to ADC. It has sampled and stored in a buffer register. The program I used is ADCSOC with slight variations. Now what should I do to find its rms.?? This is f28335 and using CCS v3.3. Is it possible to view the answer in CCS?
  • You'll first be able to observe the digital values in ADCRESULTx register in Watch window while debugging. You need to then convert the same into equivalent analog value ie 0-3V. Once you get the analog value you need to multiply the same with the gain value and calculate the rms accordingly.
    These are the steps which you need to be aware of!

    Regards,
    Gautam

  • What is the significance of this command:
    va_ADC = AdcRegs.ADCRESULT0 >>4;
  • This will give you the digital value.
    AdcRegs.ADCRESULT0 >>4 will give you a 12bit digital value ie 0V represents 0 and 3V -> 4095
  • is it possible to display rms value in ccs?
  • how to display value in ccs?
  • I edited the interrupt function of my program(ADCSOC) , for finding rms. Please tell me the mistakes in this:

    interrupt void adc_isr(void)
    {
    int sum=0;
    int rms=0;
    int va_ADC;

    Voltage1[ConversionCount] = AdcRegs.ADCRESULT0 >>4;
    va_ADC = AdcRegs.ADCRESULT0 >>4;
    sum = sum + va_ADC*va_ADC;

    // If 40 conversions have been logged, start over
    if(ConversionCount == 1999)
    {
    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;
    rms = sqrt(sum/2000);
    }
  • Fasil Mohamed said:
    how to display value in ccs?

    While in debug mode in Watch Window you can display real-time variable values

    Check this link:

    Why don't you go through the workshop material for F28335:

    Regards,

    Gautam

  • Can you please figure out the mistake:-

    #include "DSP28x_Project.h" // Device Headerfile and Examples Include File

    // 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[2000];

    Uint16 sum=0;
    Uint16 rms=0;
    Uint16 va_ADC;
    Uint16 va;
    main()
    {

    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the DSP2833x_SysCtrl.c file.
    InitSysCtrl();

    EALLOW;
    #if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
    #define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
    #endif
    #if (CPU_FRQ_100MHZ)
    #define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
    #endif
    EDIS;

    // Step 2. Initialize GPIO:
    // This example function is found in the DSP2833x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    // InitGpio(); // Skipped for this example

    // 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 DSP2833x_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 DSP2833x_DefaultIsr.c.
    // This function is found in DSP2833x_PieVect.c.
    InitPieVectTable();

    // Interrupts that are used in this example are re-mapped to
    // ISR functions found within this file.
    EALLOW; // This is needed to write to EALLOW protected register
    PieVectTable.ADCINT = &adc_isr;
    EDIS; // This is needed to disable write to EALLOW protected registers

    // Step 4. Initialize all the Device Peripherals:
    // This function is found in DSP2833x_InitPeripherals.c
    // InitPeripherals(); // Not required for this example
    InitAdc(); // For this example, init the ADC
    // For this example, only initialize the ePWM


    // Step 5. User specific code, enable interrupts:

    // Enable ADCINT in PIE
    PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
    IER |= M_INT1; // Enable CPU Interrupt 1
    EINT; // Enable Global interrupt INTM
    ERTM; // Enable Global realtime interrupt DBGM

    LoopCount = 0;
    ConversionCount = 0;


    // Enable global Interrupts and higher priority real-time debug events:
    EINT; // Enable Global interrupt INTM
    ERTM; // Enable Global realtime interrupt DBGM

    // Configure ADC
    AdcRegs.ADCMAXCONV.all = 0x0000; // Setup 2 conv's on SEQ1
    AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x3; // Setup ADCINA3 as 1st SEQ1 conv.

    AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;// Enable SOCA from ePWM to start SEQ1
    AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)

    // Assumes ePWM1 clock is already enabled in InitSysCtrl();
    EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
    EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
    EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
    EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
    EPwm1Regs.TBPRD = 400; // Set period for ePWM1
    EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2; // Clock ratio to SYSCLKOUT
    EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV2;
    // Wait for ADC interrupt
    for(;;)
    {
    LoopCount++;
    }
    }
    interrupt void adc_isr(void)
    {


    Voltage1[ConversionCount] = AdcRegs.ADCRESULT0 >>4;
    va_ADC = AdcRegs.ADCRESULT0 >>4;
    va = (va_ADC*3)/4096;
    sum = sum + (va*va);

    // If 40 conversions have been logged, start over
    if(ConversionCount == 1999)
    {
    ConversionCount = 0;
    }
    else ConversionCount++;
    rms = sqrt(sum/2000);
    // 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;

    }
  • What is the issue you're facing with this code? With the code you need to describe the issue too.
  • I am giving a sine wave with maximum voltage 3 and offset 1.5V. This program doesn't give me the correct rms.
  • Fasil Mohamed said:
    This program doesn't give me the correct rms.

    What is the deviation? Also, did you check this thread thoroughly?

  • I found the mistake. thanks
  • Great! Please close this thread by verifying the answer.

    Goodluck & Regards,
    Gautam
  • Fasil,

    int sum=0;
    sum = sum + va_ADC*va_ADC;
    rms = sqrt(sum/2000);

    I do not know which device your are using but I guess your variable 'sum' may not big enough to calculate correctly. It will get an overflow sooner or later. And sum is declared only locally, this does not make much sense...

    Best regards,

    Karlheinz