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.

Drive LD3 via ePWM1 (F2837X controlCARD)

Hi folks,

I'd like to configure ePWM1 on the controlCARD processor to drive one of the user LEDs (LD3, GPIO34.) I've got the ePWM configured (it's counting ;) ) and the plan, of course, is to use one of the comparators to vary the duty cycle (by varying the comparator between 0 and the period.) The problem I'm facing is how to route the comparator output to a GPIO pin. I've read through the X-BAR section in the TRM (spruhm8e) and found it a bit dense. Or I am a bit dense. I've looked at a couple examples and it is not obvious to me how to configure ePWM, output X-BAR and GPIO to make this connection. Pointers to additional documentation or relevant examples are most welcome!

I did find this set of statements in GpioSetup.c that seems to be a hint:

   GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;  // GPIO0 = PWM1A
   GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;  // GPIO1 = PWM1B
   GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;  // GPIO2 = PWM2A
   GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;  // GPIO3 = PWM2B
   GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1;  // GPIO4 = PWM3A
   GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1;  // GPIO5 = PWM3B

I'm don't understand that and it is not obvious to me how to convert the first statement to route PWM1A to GPIO34 (LD3)

As an aside, I think a Blinky style example that uses a PWM output to drive one of the user LEDs would make a great addition to the resource explorer. :D

Thanks!

  • Edit: (But I see no capability to edit the previous post.)
    Somehow I have managed to get this far w/out the data sheet. I just found it. (sprs880g.pdf) The Table 4-4 (p40-43) shows the matrix for GPIO pin assignment. If I understand that, there is no direct connection from any PWM to the user LEDs on GPIO31 and GPIO34. The OUTPUTXBAR8 and OUTPUTXBAR1 entries sound mildly promising. Can I route the PWM output signal that way?

    Thanks!
  • Hi Hank,

     

    If I understand that, there is no direct connection from any PWM to the user LEDs on GPIO31 and GPIO34. The OUTPUTXBAR8 and OUTPUTXBAR1 entries sound mildly promising. Can I route the PWM output signal that way?

    PWM outputs are not directly connected to OUPUTXBAR (refer section  "8.2 ePWM and GPIO Output X-BAR" in device TRM for more detail on connection) but you could use the combination of INPUTXBAR and OUTPUTXBAR to re-route the PWM output on GPIO31 and GPIO34.

    Following are the step to be followed -

    • Configure GPIO mux to select OUTPUTXBAR1 and OUTPUTXBAR8 on GPIO31 and GPIO34 pins.
    • Configure INPUTXBAR to connect the PWM OUTPUTs to any of  INPUT1 to INPUT6 (which are connected to OUPUTXBAR).
    • Configure OUTPUTXBAR to connect the selected INPUT lines to OUTPUTXBAR 8 and OUTPUTXBAR1.

    Hope this helps.

    Regards,

    Vivek Singh

  • Hi Vivek,

    Thank you for your help. Here is what I have so far (for LD3, GPIO34)

    GpioCtrlRegs.GPBPUD.bit.GPIO34 = 0; // Enable pullup on GPIO5

    // Setup suggestions from e2e.ti.com/.../1875561 (34 only)

    // •Configure GPIO mux to select OUTPUTXBAR1 and OUTPUTXBAR8 on GPIO31 and GPIO34 pins

    GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 1; // OUTPUTXBAR1 (P40, sprs880g, datasheet)

    GpioCtrlRegs.GPBGMUX1.bit.GPIO34 = 1; // (same?)

    // •Configure INPUTXBAR to connect the PWM OUTPUTs to any of INPUT1 to INPUT6 (which are connected to OUPUTXBAR).

    InputXbarRegs.INPUT1SELECT = 1;

    // •Configure OUTPUTXBAR to connect the selected INPUT lines to OUTPUTXBAR 8 and OUTPUTXBAR1.

    OutputXbarRegs.OUTPUT1MUX0TO15CFG.bit.MUX0 = 0; // 00 : Select .0 input for Mux0

    OutputXbarRegs.OUTPUT8MUXENABLE.bit.MUX0 = 0; // enable, same connection

    I think I've got the first step done.

    The second step has me baffled. Table 8-5 (p1057 of the TRM) lists input selects which as near as I can tell, Select GPIO inputs for the INPUT_XBAR. I do not think that is what you are describing. Table 8-28 (p1098) describes routing to the various TRIPn inputs to the ePWM modules. Again, seems not like what you are describing. I took a stab at it but do not think what I have is correct.

    I think I have the last step correct (depending on what the second step does.)


    I appreciate any further suggestions or help you can provide.

    Thanks!

     

  • I'm taking a step back and having a go at driving the default GPIO with ePWM1A (GPIO-00) This is with the code for the adc_soc_epwm example. I have added what I thought was the requisite code to configure the PWM output. This includes the following lines added after InitGPIO():

    InitGpio(); // Skipped for this example

    GPIO_SetupPinOptions(LD2, 1, GPIO_OPENDRAIN | GPIO_PULLUP); // configure LD2 for output

    GpioCtrlRegs.GPAGMUX1.bit.GPIO0 = 0; // GPIO0 (P40, sprs880g, datasheet)

    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // GPIO0 (P40, sprs880g, datasheet)

     

    And the following to the ePWM setup in ConfigureEPWM()

    EPwm1Regs.TBCTL.bit.CTRMODE = 3; // freeze counter

    EPwm1Regs.AQCTLA.bit.CAU = 1; // set ePWM1A output high on counter/CMPA match

    EPwm1Regs.AQCTLA.bit.ZRO = 11; // toggle ePWM1A output counter == 0

    EDIS;

    GPIO-00 (pin 49 on the dock) remains at zero. I have tried driving it as a GPIO output and that works. Clearly I'm missing something.

    One piece of the puzzle is Table 4-4. GPIO Muxed Pins on p40 of the data sheet (SPRS880G) I don't think I'm interpreting the place holders 'y', 'n' and 'z' correctly and I don't know what is meant by GPIO Index.

    Thanks!

     

  • Hi Hank,

    One piece of the puzzle is Table 4-4. GPIO Muxed Pins on p40 of the data sheet (SPRS880G) I don't think I'm interpreting the place holders 'y', 'n' and 'z' correctly and I don't know what is meant by GPIO Index.

    You have correctly configured the GPIO mux setting in your code hence I think your understanding of this is correct. 'y' is GPIO group name (A/B/C..etc, each group has 32 GPIO) and since each GPIO mux select has 2 bit for regular mux select and 2 in global mux select, there are two mux configuration register and that's referred by 'n' (1 and 2) and 'z' represents the GPIO pin number (0,1,2,3...etc).

     I see you have EDIS statement in your code but do not see EALLOW. Hope EALLOW is also there but missing in this snapshot.

    On ePWM configuration -

    • You have set the CTRMODE = 3 which is reset value and it means counter is in freeze state. That would not generate any output pulse. I think you should change this to 0x2 (up-down count).
    • I do not see the value written into CMPA register. Reset value of this is 0x0 so counter will not increment. You need to configure this as well.

    Also have you checked in CCS register view (or memory watch view) to make sure the value you are writing into GPIO and EPWM registers are actually getting written correctly. If not please check the same.

    Please make these change and see if it helps. If not then I need to refer to our ePWM expert who can help you with ePWM configuration.

    Regards,

    Vivek Singh

  • Hi Vivek,

    Thank you for your reply. In reply to some comments,

    > Hope EALLOW is also there but missing in this snapshot

    Yes. It is there. (It is always a challenge to decide what to include in a code snippet. Perhaps the entire file and refer to specific lines. That way nothing gets left out and.)

    > You have set the CTRMODE = 3 which is reset value ...

    This is how the example was written. It resets the IP during configuration and starts it in another part of the code.

    Since I began working with this (Directing PWM to a specific GPIO bit) I have switched to another example which already drives a GPIO bit. That is epwm_up_aq_cpu0. I can see the signal on pin #49 on the controlCARD dock.

    The other part - routing the PWM signal to a different GPIO bit - may not be required for our application so I'm going to set that aside for now.

    thanks,

    hank