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.

ISR for SGEN library

Other Parts Discussed in Thread: CONTROLSUITE

Hello, I'm trying to generating a sine signal using the SGEN library, and all the examples in controlSUITE are using a for loop to store the signal to an array. I wonder if I can write an ISR to store the signal data once at a time in a variable, if so, which interrupt is related, and should I write my own ISR and map it to the pievect table? By the way, I'm using the 28335 dev. kit. Please help and thank you!

Best regards, Haoyi

  • Hi Haoyi,

    Yes, you can very well use CPU_timer ISR and achieve the same functionality.

    Regards,
    Gautam
  • Hi Gautam,

    So I tried using cpu timer 0 ISR which is called TINT0_ISR in the DefaultIsr.c file, while cpu timer 1 and 2 are said to be reserved for ti use. I initialized the cpu timer 0 first and map my own ISR to the TINT0 in the pievect table, then the sgen module was initialized. The code built fine but when I debugged it, the two variables x1 and x2 which were supposed to change continuously remained 26816 and 0, and I did refresh the watch window. The code below is the main.c I used. Do you have some suggestions on it? There was no compiling bug, so I couldn't figure out what was wrong. Thanks again for your time and patience with a beginner.

    Best regards,
    Haoyi

    #include "DSP28x_Project.h" // Device Headerfile and Examples Include File
    #include <sgen.h>
    #include "IQmathLib.h"
    interrupt void signal_isr(void);
    SGENTI_2 sgen = SGENTI_2_DEFAULTS;
    int x1,x2;
    //20kHz
    float freq = 0.02;
    float period = 50;
    void main()
    {
    InitSysCtrl();
    InitCpuTimers();
    ConfigCpuTimer(&CpuTimer0,freq,period);
    DINT;
    InitPieCtrl();
    IER = 0x0000;
    IFR = 0x0000;
    InitPieVectTable();
    EALLOW;
    PieVectTable.TINT0 = &signal_isr;
    EDIS;
    // Enable CPU INT1
    IER |= M_INT1;
    // Enable TINT0 in the PIE: Group 1 interrupt 7
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
    // Enable Global interrupt INTM
    EINT;
    // Enable Global realtime interrupt DBGM
    ERTM;
    sgen.offset=1024;
    sgen.gain=_IQ15(0.03125);
    sgen.freq=6443;
    sgen.step_max=1000;
    sgen.phase=_IQ15(1);
    sgen.alpha=0;//8192;
    for(;;);

    }
    interrupt void signal_isr(void)
    {
    sgen.calc(&sgen);
    x1=sgen.out1;
    x2=sgen.out2;
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
    PieCtrlRegs.PIEIFR1.bit.INTx7 = 1;
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    }
  • Haoyi, try toggling GPIO in the ISR and check whether timer ISR is working as per expected.
  • Hi Gautam, I tried toggling gpio in both timer 0 and 1 interrupt which are TINT0_ISR and INT13_ISR at separate trials, but not one pin toggled when I scope them.

    I don't know if it is my problem of initializing or using the gpio.

    I initialized gpio 12 in my main function after the system control initialization.

    void Init12Gpio(void)
    {
    EALLOW;
    GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0x00;
    GpioCtrlRegs.GPADIR.bit.GPIO12 = 1;
    EDIS;
    }

    Then I modified the timer isr using code below.
    EALLOW;
    GpioDataRegs.GPATOGGLE.bit.GPIO12 = 1;
    EDIS;

    I didn't get error or warning, do you have any suggestion? Thanks.
  • Refer this for timer config: C:\ti\controlSUITE\device_support\f2833x\v133\DSP2833x_examples_ccsv4\cpu_timer
    Also, initialize GPIO before main and toggle the same in timer ISR.
    Let me know what you observe.

    Regards,
    Gautam
  • Hi Gautam,

    So the problem is solved, the pin toggled. I think it's probably because I initialized the timer wrong. And back to the original question, I also

    succeed in storing sine values in variables using timer ISR. But I still have this question, how do I determine the actual frequency of the sine

    signal? I'm not sure if it is the same frequency when I initialized sgen module. If yes, does that mean I need to increase the cpu interrupt

    frequency to get better sine signal resemblance? Thanks a lot for your guidance.

    Best regards,
    Haoyi
  • Your cpu_timer will have to be very small as when you're in a for loop there's a continuous execution and no delay. You'll have to observe the signal on DSO and tune accordingly.