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.

m3 PWM output SYS\BIOS v6

Other Parts Discussed in Thread: F28M35H52C, SYSBIOS

Hello everybody,

I'm working with the Concerto experiment kit, with f28m35h52c chip.
I want to clock an external device with 1-2Mhz clock form the concerto.

I tried using timers to do an interrupt every 0.5us and then toggle a GPIO pin but that got me up to 100Khz.

How can I use the GPIO timers to clock the device using SYS\BIOS v6?

Thanks,

Yoel 

  • Hi Yoel,

    Which version of SYS/BIOS are you using?

    Which timer are you using?

    How did you generate the interrupt (e.g. Hwi versus zero-latency)? Is the 100KHz an observed freq (since based on 0.5us, it should be 1MHz).?

    For a clock that fast, there must be a better way to generate it than using software. I'm not familiar with the Concerto timers. I'll check with the device development team to see if there is a better way.

    Todd

  • Hello Todd,

    I'm using sys\bios 6.32.05.54

    Timer1

    This is Hwi interrupt (number 37) and I wached the output with a scope and it shows 5us period.

    I thought there ought to be a better way than this and I would love to hear what the developement team has to say, this doesn't has to be a software solution.

    Thanks,

    Yoel

  • Hi Yoel,

    Unless you want to call any SYS/BIOS API in the interrupt routine, I think the zero-latency interrupt would work better (due to the frequent interrupts)

    Another option may perhaps be to run the Timer at a 50% PWM mode @ 1-2 MHz. This way, there would be no overhead or need to have SYS/BIOS to change a GPIO pin for you.

    Thanks,

    Tom

  • Hi Tom,

    This solution sounds good to me.

    By using the "Timer.h" (Driver for the timer module), is this code section the correct way to activate the timer? 

        // Enable the timer peripherals
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    // Configure the PWM timer.
    TimerConfigure(TIMER1_BASE, TIMER_CFG_A_PWM);
    TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet(2000000));
    TimerControlLevel(TIMER1_BASE, TIMER_A, true);

    // Enable the timers.
    TimerEnable(TIMER1_BASE, TIMER_A);
    
    
    If so, will the output be on "PA6_GPIO6"?
    Thanks,
    Yoel
  • I'm sorry Joel, I looked into this some further.

    I thought that the M3's general purpose timers had some sort of external outputs...but it doesn't.

    Did the zero-latency interrupt work? The interrupts aren't as frequent as I initially thought..

    The link below should help:

    http://processors.wiki.ti.com/index.php/SYS/BIOS_for_Stellaris_Devices#ZeroLatencyAnchor

    You will need to use the M3's Hwi module in your .cfg file.

    var Hwi = xdc.useModule('ti.sysbios.family.arm.m3.Hwi');

    Thanks,

    Tom

  • Hi Yeol,

    I ran the math in my head one more time (after a good night of sleep :))

    If you're planning to use software to toggle a GPIO at 1-2 MHz, you probably won't be able to do anything else on your M3.

    Assuming you're running the M3 core @ 75MHz with a timer interrupt generated every 0.5us means that you'll have an interrupt generated appox. every 38 cycles...

    Performing a zero-latency interrupt will consume at least 16 cycles to just get into the interrupt handler and then you need to add the number of instruction cycles to toggle the GPIO pin. This overall process will likely require a lot more cycles if you code ISR is run from flash due to the flash controller's wait states.

    You may want to look into using the C28's ePWM peripheral to generate the 1-2 MHz clock signal, but unfortunately I'm not familiar on how it's used.

    Thanks,

    Tom

  • Hey Tom,

    Sorry I took away your sleep...

    I got to the same conclusion myself after getting interrupt every 0.75us with the zero latency interrupts...

    I will try it on sunday (Yes, we work at sundays...) and tell everyone how it went.

    Thanks for the help!

    Yoel

  • Hey Tom,

    I managed to get the ePWM on the c28 to work at 2Mhz (maybe even more, didn't try it yet).
    As a neewbe in Concerto I had some trouble, so I tought I'd share them to others.

    First of all, the c28 need to get control over the ePWM ports from the m3 (that is why the setup_m3 example exists...).

    After that, I changed the code from one of the examples and I got 1Mhz PWM output on GPIO8 and GPIO9.

    Here is the code:

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

    // Configure the period for the timer
    #define PWM5_TIMER_TBPRD 0x0024 // 1Mhz

    void InitEPwmTimer(void);

    void main(void)
    {
    // Enable Peripheral Clocks
    InitSysCtrl();

    // Step 2. Initalize GPIO:
    EALLOW;
    // For this case just init GPIO pins for ePWM1, ePWM2, ePWM3
    // These functions are in the F28M35x_EPwm.c file
    InitEPwm5Gpio();
    EDIS;

    // 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).
    InitPieVectTable();

    // Step 4. Initialize all the Device Peripherals:
    InitEPwmTimer(); // For this example, only initialize the ePWM Timer

    // Step 6. IDLE loop. Just sit and loop forever (optional):
    for(;;)
    {
    asm (" NOP");
    }
    }

    void InitEPwmTimer()
    {
    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
    EDIS;

    // Disable Sync
    EPwm5Regs.TBCTL.bit.SYNCOSEL = 11; // Pass through

    // Initally disable Free/Soft Bits
    EPwm5Regs.TBCTL.bit.FREE_SOFT = 0;
    EPwm5Regs.TBPRD = PWM5_TIMER_TBPRD; // Set up PWM1 Period
    EPwm5Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up mode
    EPwm5Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
    EPwm5Regs.ETSEL.bit.INTEN = 0; // Enable INT
    EPwm5Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event
    EPwm5Regs.TBCTR = 0x0000; // Clear timer counter
    EPwm5Regs.CMPA.half.CMPA = PWM5_TIMER_TBPRD/2; //CompareA event at half of period
    EPwm5Regs.CMPBM.half.CMPB = PWM5_TIMER_TBPRD/2; // Set Compare B value
    EPwm5Regs.AQCTLA.all = 0x0024; // Action-qualifiers, Set on
    // CMPA, Clear on PRD
    EPwm5Regs.AQCTLB.all = 0x0024; // Action-qualifiers, Set on
    // CMPA, Clear on PRD

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
    EDIS;
    }

     Thanks,

    Yoel