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.

TM4C129XNCZAD: fir implementation with sampling freq 10k

Part Number: TM4C129XNCZAD


hello,

 i posted earlier but till now i am unable to resolve problem.

my problem is explained below

i have a waveform which is addition of 1KHz and 10KHz. i want to remove 10KHz using fir filter . idesigned filter using fdatool in matlab. it gave me 27 coefficient. now i tried it to implement on tm4c129x board with a dac 7731 . i am not getting output as i want . can you please suggest any mistake or sin which i am doing in program.

/*
 * main.c
 */
 #include "stdbool.h"
#include "stdint.h"
#include "gpio.h"
#include "rom_map.h"
#include "driverlib/sysctl.h"
#include "inc/hw_memmap.h"
#include "pin_map.h"
#include "emac.h"
#include "systick.h"
#include "drivers/pinout.h"
#include "utils/ustdlib.h"
#include "driverlib/adc.h"
#include "math.h"
#include "driverlib/ssi.h"
#include "inc/tm4c129xnczad.h"
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/slider.h"
#include "drivers/frame.h"
#include "drivers/kentec320x240x16_ssd2119.h"
#include "drivers/sound.h"
#include "drivers/touch.h"
#include "driverlib/rom.h"
#include "driverlib/udma.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
//#include "inc/hw_ints.h"

#define GPIO_PA2_SSI0CLK        0x0000080F
#define GPIO_PA3_SSI0FSS        0x00000C0F
#define GPIO_PA4_SSI0TX      0x0000100F
#define GPIO_PA5_SSI0RX      0x0000140F
void MT_SSIConfigure(void);
void MT_ADCConfigure(void);
//void Timer0IntHandler(void);
float xval[61],dac_count,value;
    float sum,temp,voltage,value;
uint32_t pui32ADC0Value[2];
void DAC_ldac(void);
uint32_t ui32Period;
uint32_t ui32SysClock;
uint32_t pui32DataTx;
const double firCoeffs32[26] = {

                                0.00042786716307723429,
                                 0.002919136775687219,
                                 0.0087411768920698726,
                                 0.01728389646188545,
                                 0.023790092406399139,
                                 0.020625746649647263,
                                 0.0026178235631764959,
                                -0.025784577131922413,
                                -0.047619527772776261,
                                -0.039756341015621199,
                                 0.012766667411548112,
                                 0.10310658429302662,
                                 0.20045692369728618,
                                 0.26366156038852501,
                                 0.26366156038852501,
                                 0.20045692369728618,
                                 0.10310658429302662,
                                 0.012766667411548112,
                                -0.039756341015621199,
                                -0.047619527772776261,
                                -0.025784577131922413,
                                 0.0026178235631764959,
                                 0.020625746649647263,
                                 0.023790092406399139,
                                 0.01728389646188545,
                                 0.0087411768920698726,
                                 0.002919136775687219,
                                 0.00042786716307723429,





};
void MT_ADCConfigure()
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
    GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_1);
    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH17 | ADC_CTL_IE |
                                 ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 3);
    ADCIntClear(ADC0_BASE, 3);
}
void MT_SSIConfigure()
{
        SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        GPIOPinConfigure(GPIO_PA2_SSI0CLK);
        GPIOPinConfigure(GPIO_PA3_SSI0FSS);
        GPIOPinConfigure(GPIO_PA4_SSI0TX);
        GPIOPinConfigure(GPIO_PA5_SSI0RX);
        GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2);
        SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3,
                               SSI_MODE_MASTER, 10000, 16);
        SSIEnable(SSI0_BASE);
}

int main(void)
{
     int i,k;
     float xval[27],dac_count,value;
     float sum,temp,voltage;
     uint32_t ui32SysClock,l;
     ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),120000000);
   ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
              ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
      ui32Period = (SysCtlClockGet() / 10000);
        TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
        TimerControlTrigger(TIMER0_BASE,TIMER_A,true);
     MT_ADCConfigure();
     MT_SSIConfigure();
     DAC_ldac();
                             for(i=0;i<=26;i++)
                                       {
                                               xval[i]=0;
                                       }

                                //     IntEnable(INT_TIMER0A);                               //
                                 //  TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);        //
                                                             //
                                     ROM_IntEnable(INT_TIMER0A);
                                       ROM_TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT);
                                       ROM_IntEnable(INT_ADC0SS3);
                                       ROM_ADCIntEnable(ADC0_BASE,3);

                                       ROM_IntMasterEnable();
                                       ROM_TimerEnable(TIMER0_BASE,TIMER_A);
                                   while(1)
                                   {
                                       MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,GPIO_PIN_5);
                                       MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3,GPIO_PIN_3);
                                   //    SysCtlDelay(8000);
                                    //   ADCProcessorTrigger(ADC0_BASE, 3);

                                                  //     while(!ADCIntStatus(ADC0_BASE, 3, false))
                                                   //           {
                                                    //          }

                                                  //        ADCIntClear(ADC0_BASE, 3);

                                          sum=0;
                                            for(k=0;k<=26;k++)
                                                  {
                                                        temp = (xval[k])*(firCoeffs32[k]);
                                                        sum = sum + temp;

                                                   }

                                            for(i=27;i>=1;i--)
                                                   {
                                                        xval[i] = xval[i-1];
                                                   }
                                             xval[0]=value;

                                              dac_count= (sum*8190);
                                                              pui32DataTx=dac_count;
                                                              SSIDataPut(SSI0_BASE, pui32DataTx);
                                                              while(SSIBusy(SSI0_BASE))
                                                                    {
                                                                    }
                                                             MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, 0);
                                                             SSIIntClear(SSI0_BASE,SSI_RXFF);
                                                          //

                                                            MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5,GPIO_PIN_5);

                                   }

    //return 0;
}
void DAC_ldac()
{
    ///  LDAC Signal
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5);
    MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5);
   // Reset Signal
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
    MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);
}

void ADC0SS3IntHandler(void)
{
     
     ADCIntClear(ADC0_BASE, 3);
     ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
     value=(*pui32ADC0Value*3.3)/4096;


}
void Timer0IntHandler(void)
{
    ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
}

please help me to complete it. now i am getting frustation. i saw many youtube video. but desire output is still missing

 

  • I am sorry. My ability to help is mostly limited to how to use the TM4C microcontrollers and the TivaWare library. Your question is more along the lines of needing help to debug your application. If after further debug you have a question about the operation of a specific peripheral, please start a new post.
  • can you tell me why my adc is not getting correct data i want to sample at 10KHz
  • No, but I did provide a working example in your other post:
    e2e.ti.com/.../703645
  • Feel your pain - yet vendor agent 'has' assisted - your unique 'total, custom solution' (really does) fall upon you...

    May i suggest your use of 'KISS' - which so often is able to, 'Speed, Ease & Enhance' such complex, Diagnostic Efforts?

    You state that your ADC is, 'Not getting correct data' - and while that (may) be true - it provides (very little) Diagnostic Value!       

    Instead - do advise:

    • what ADC Data you EXPECT to receive
    • and then how that compares/contrasts w/that data which you DO RECEIVE!

    That's of far greater Diagnostic value - don't you agree?

    To further guide/assist - I suggest that you:

    • present a known, constant, analog voltage to your ADC
    • then observe if that is 'correctly measured & recorded.'

    Such provides a 'key beginning (and much needed) reference point for you.     Only after that's (first) achieved - should you venture further.    

    A sequence of small - always 'measurable & checked small steps'  - proves a 'far better path'  - to your successful outcome...      (as you've noted - your 'all together' approach - has 'little chance!')

  • thnak for your reply as i have given const voltage it is giving exact output but when i give sine wave of 1 Khz with adc interrupt through timer of 10K sampling time i am not getting the exact value to get sine wave
  • What speed are you running the ADC? I do not see your call to ADCClockConfigSet() in the code you show above. If you have a high (>>50 Ohm) source impedance, you may need to increase the sample time to get accurate results.
  • It looks like you have two threads going on the same issue. To avoid confusion and wasted time, I will lock this thread and let's continue using the other thread:
    e2e.ti.com/.../2597054