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.

RTOS/TMS320F28027: F28027

Part Number: TMS320F28027
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: TI-RTOS

I was trying to send a pulse to ultrasonic sensor using ePWM and listen for echo signal. I also use eCAP to measure the time it takes to echo back.

However, I don't see any values stored in eCAP.. I'm using 3-pin ultrasonic sensor (28015). how can i configure the input and output?

    GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1;     // 0=GPIO,  1=EPWM3B,  2=Resv,  3=ECAP1
    GpioCtrlRegs.GPADIR.bit.GPIO5 = 1;      // 1=OUTput,  0=INput
    GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 3;     // 0=GPIO,  1=EPWM3B,  2=Resv,  3=ECAP1
    GpioCtrlRegs.GPADIR.bit.GPIO5 = 0;      // 1=OUTput,  0=INput

    EALLOW;
    EPwm3Regs.TBCTL.bit.HSPCLKDIV = 5;
    EPwm3Regs.TBCTL.bit.CLKDIV = 3;
    EPwm3Regs.TBPRD = 48675;         // 100 ms period
    //EPwm3Regs.CMPA.half.CMPA = 8;    // generate 10 us pulse
    EPwm3Regs.CMPB = 8;    // generate 10 us pulse
    EPwm3Regs.TBPHS.half.TBPHS = 0;
    EPwm3Regs.TBCTR = 0;
    EPwm3Regs.TBCTL.bit.CTRMODE = 0;
    EPwm3Regs.TBCTL.bit.PHSEN = 0;
    EPwm3Regs.TBCTL.bit.PRDLD = 0;
    EPwm3Regs.TBCTL.bit.SYNCOSEL = 2;
    EPwm3Regs.CMPCTL.bit.SHDWBMODE = 1;
    EPwm3Regs.CMPCTL.bit.LOADBMODE = 0;
    EPwm3Regs.AQCTLB.bit.ZRO = 2;
    EPwm3Regs.AQCTLB.bit.CAU = 1;

    // Configure peripheral registers
    ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0;	   // continuous mode
    ECap1Regs.ECCTL2.bit.STOP_WRAP = 3;        // stop at 4 events
    ECap1Regs.ECCTL1.bit.CAP1POL = 0;          // Rising edge
    ECap1Regs.ECCTL1.bit.CAP2POL = 1;          // Falling edge
    ECap1Regs.ECCTL1.bit.CAP3POL = 0;          // Rising edge
    ECap1Regs.ECCTL1.bit.CAP4POL = 1;          // Falling edge
    ECap1Regs.ECCTL1.bit.CTRRST1 = 1;          // Difference operation
    ECap1Regs.ECCTL1.bit.CTRRST2 = 1;          // Difference operation
    ECap1Regs.ECCTL1.bit.CTRRST3 = 1;          // Difference operation
    ECap1Regs.ECCTL1.bit.CTRRST4 = 1;          // Difference operation
    //ECap1Regs.ECCTL2.bit.CAP_APWM = 0;         // Disable sync in
    ECap1Regs.ECCTL2.bit.SYNCI_EN = 0;         // Disable sync in
    ECap1Regs.ECCTL2.bit.SYNCO_SEL = 3;        // Disable
    ECap1Regs.ECCTL1.bit.PRESCALE = 0;         // Prescale = 1 /Disable
    ECap1Regs.ECCTL1.bit.CAPLDEN = 1;
    ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;        // Start Counter
    ECap1Regs.ECEINT.bit.CEVT4 = 1;            // 4 events = interrupt
    EDIS;

  • Jacky,

    ControlSuite will show you how to configure a pin to use the eCAP module, try running the example located in "<install root>\controlSUITE\device_support\f2833x\v142\DSP2833x_examples_ccsv5\ecap_capture_pwm". 

    Once you fully understand what this code is doing you can begin to modify it to suit your needs or combine it with your own existing code. Without modification this code will work to demonstrate the eCAP.

    If you are looking for information on how to use the sensor you should check the manufacturers website, it seem like it needs a fixed lenth 5V trigger pulse and has a set listen window.

    A word of caution, the sensor you are using appears to be a 5V device. This would mean you need a level shifter or other isolation barrier to protect the Launch Pad from damage(both on outputs and inputs). Additionally depending on the way that the sensor is designed the 3.3V PWM signal that you are providing may not cause the sensor to activate. This depends on the VIH level of the sensor.

    Note: Any pin you have connected to the sensor may be damaged due to EOS.

    Regards,
    Cody