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.

TMS320F28335: TMS320F28333

Part Number: TMS320F28335

This code is used for the eCap module lab. I use my function generator signal (having specific freq and the duty cycle) to capture at port GPIO24. The freq is measured at the CCS watch window through variables PWM_Duty and PWM_Period. I need to pass the same signal that I measured (same freq & duty cycle) to any of the GPIO port A (Suppose GPIO06). It means that whatever digital signal you capture, will be passed to any pin /GPIO port A (Suppose GPIO06) that I assign. In this way, I can measure this signal at GPIO06 through an oscilloscope to verify the signal freq and duty cycle respectively that I see on the watch window. I tried this by adding two lines in the code (line 121 and line 122) but I guess it is not working. Community members, please suggest in the code so that I could perform the desired task.

Thanks

  • Hi Muhammed, 

    You're trying to output the 32 bit register to a single GPIO bit right now. The CAP is a 32 bit register so you will need 32 GPIO to be able to output what the register contents hold.

    Best,

    Ryan Ma

  • Hi Ryan,

    With respect to this below chart, all are registers that we use in eCap module.

    The eCap function uses three registers in the code. ECap1Regs.ECEINT.all, ECap1Regs.ECCTL1.all and ECap1Regs.ECCTL2.all. I copied the value of 

    ECap1Regs.ECCTL2.bit.CAP (single bit - capture value) to GpioDataRegs.GPADAT.bit.GPIO06 ( single bit - GPIO06) in line 121 and line 122.

    Do I need to write the below lines in the code at line 121?

    GpioDataRegs.GPADAT.bit.GPIO06 = ECap1Regs.ECCTL2.bit.CAP;

    GpioCtrlRegs.GPAMUX1.bit.GPIO06 = 0;

    GpioCtrlRegs.GPADIR.bit.GPIO06 = 1;

  • Hi Muhammad,

    Sorry I was incorrect and was looking at the wrong register. Yes you are correct, if the pin is configured as GPIO output. Make sure to setup the GPAMUX1 and GPADIR registers before setting the GPADAT register.

    GpioCtrlRegs.GPAMUX1.bit.GPIO06 = 0;

    GpioCtrlRegs.GPADIR.bit.GPIO06 = 1;

    GpioDataRegs.GPADAT.bit.GPIO06 = ECap1Regs.ECCTL2.bit.CAP;

  • Hi Ryan,

    While testing the board, the GPIO6 pin doesn't give any sign of desired signal/results on the oscilloscope. We need the same digital signal at the output having the same frequency and duty cycle that I captured from the function generator ( 1Khz & 50% duty cycle) through the Ecap/GPIO24 pin. The watch window (monitor) shows the desired results but the oscilloscope doesn't provide the desired signal. Can you please recheck the code again at lines 121-123? Am I sending the right bit signal (CAP_APWM) at pin GPIO6? Please find the pictures below. 

  • Hi Muhammed,

    You want to set a GPIO pin to output whatever is located at this register bit correct? ECCTL.CAP_APWM?

    This bit is telling you what operating mode you have selected. are you trying to output to see what mode you've selected from the GPIO based on this bit field?

  • Thanks for your reply.

    Q: This bit is telling you what operating mode you have selected. are you trying to output to see what mode you've selected from the GPIO based on this bit field?

    The answer is No,

    With your explanation, I think I am choosing the wrong bit for performing the desired task.

    The task is to measure the output signal at GPIO06 through the oscilloscope (the same signal which I captured from GPIO24 through the generator) so that I can verify the duty cycle and period as shown in the watch window.

    It means passing the same input to the output. or you can say whatever the digital square pulse of any frequency/duty cycle you provide from the generator, will be passed or measured at GPIO06.

     

  • Hi Muhammed, 

    What you are trying to do is output the signal of the function generator to another GPIO output on the board correct? Do you want to use the APWM function of the ECAP? APWM could generate what you're square wave is generating from the function generator.

    Sorry it is unclear to me what you're trying to accomplish. If you are trying to route the input (function generator) to an output pin on the board through ECAP you cannot do that. You can use the ECAP as APWM mode to generate a PWM signal.

    Best regards,

    Ryan Ma

  • Thanks for your reply Slight smile

    Q: What you are trying to do is output the signal of the function generator to another GPIO output on the board correct?

    Answer: yes

    If you are trying to route the input (function generator) to an output pin on the board through ECAP you cannot do that. You can use the ECAP as APWM mode to generate a PWM signal.

    Can I follow this procedure?

    - GPIO24 as the input CAPTURED signal from the function generator. (this is done in the code).

    - I can see the frequency & duty cycle of the CAPTURED signal at the CCS watch window. (this is also done in code through PWM _period/duty cycle).

    - Generate the PWM signal of the CAPTURED signal at another GPIO pin (like ECAP2 in APWM mode) not at GPIO24 because it is used for signal capture from the function generator.

  • Yes that does sound like a solution! As long as you set the ECAP module you want to be in APWM mode and use the captured information from the other ECAP to calculate the period / duty cycle you should be able to accomplish what you want to do.

    Best regards,

    Ryan Ma

  • Hi Ryan,

    Thanks for your reply.

    - GPIO24 as the input CAPTURED signal from the function generator. (this is done in the code).

    - I can see the frequency & duty cycle of the CAPTURED signal at the CCS watch window. (this is also done in code through PWM _period/duty cycle).

    - Generate the PWM signal of the CAPTURED signal at another GPIO pin (like ECAP2 in APWM mode) not at GPIO24 because it is used for signal capture from the function generator.

    With this procedure to follow, I set the code in this manner as shown below. Please check the code: lines: 112,153,154,155,157,158,174,189,202,203 for generating the APWM signal at GPIO25 of the CAPTURED signal (GPIO24) from the function generator.

    Regards

  • Hi Muhammed, 

    Is there anything unexpected occurring when you're following the code you sent above? 

    Best,

    Ryan Ma

  • Hi Ryan,

    Thanks for your reply. I executed the code in hardware today. there were no building errors. But at GPIO25 (Ecap2) I don't get the output on the oscilloscope. The output should be the APWM signal at GPIO25 of the CAPTURED signal (GPIO24) from the function generator. Please see the pictures below.

    Please review the code again and suggest accordingly. lines: 112,153,154,155,157,158,174,189,202,203

    Kind Regards

    Arsalan

  • Hi Arsalan,

    For your GPIO could you try and configure it this way?

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    EALLOW;
    //
    // Enable internal pull-up for the selected pins
    // Pull-ups can be enabled or disabled by the user.
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    //
    GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0; // Enable pull-up on GPIO25 (CAP2)
    //
    // Inputs are synchronized to SYSCLKOUT by default.
    // Comment out other unwanted lines.
    //
    GpioCtrlRegs.GPAQSEL2.bit.GPIO25 = 0; //Synch to SYSCLKOUT GPIO25 (CAP2)
    //
    // Configure eCAP-2 pins using GPIO regs
    // This specifies which of the possible GPIO pins will be eCAP2 functional
    // pins. Comment out other unwanted lines.
    //
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Also have you tried setting an initial period to first test your output of ECAP2?

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ECap2Regs.ECCTL2.bit.CAP_APWM = 1; // Enable APWM mode
    ECap2Regs.CAP1 = 0x01312D00; // Set Period value
    ECap2Regs.CAP2 = 0x00989680; // Set Compare value
    ECap2Regs.ECCLR.all = 0x0FF; // Clear pending interrupts
    //
    // Start counter
    //
    ECap2Regs.ECCTL2.bit.TSCTRSTOP = 1;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi Ryan,

    The above code is used for Ecap_APWM (example) and I already tested this code.  The lines you mentioned above are for 7.5Hz and 15Hz. But I guess Here the period is set by ourselves(0x1312D00). while I am generating a PWM from the signal captured from the function generator(GPIO24). If I set 1KhZ from the generator, the program should generate the PWM signal with respect to 1Khz at GPIO25. If I change the freq to 150Khz from the generator at GPIO24, the program should generate the PWM signal with respect to 150KhZ at GPIO25 without changing anything in the code.

    Looking forward to your feedback

    Regards

    Arsalan

  • Hi Muhammad,

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    interrupt void eCAP1_isr(void)
    {
    ECap1Regs.ECCLR.bit.INT = 1; // Clear the ECAP1 interrupt flag
    ECap1Regs.ECCLR.bit.CEVT3 = 1; // Clear the CEVT3 flag
    // Calculate the PWM duty period (rising edge to falling edge)
    PWM_Duty = (int32)ECap1Regs.CAP2 - (int32)ECap1Regs.CAP1;
    // Calculate the PWM period (rising edge to rising edge)
    PWM_Period = (int32)ECap1Regs.CAP3 - (int32)ECap1Regs.CAP1;
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP4; // Must acknowledge the PIE group 4
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    In regards to this interrupt you're updating PWM_duty and PWM_period which seems to be fine. However I do not see where you are setting the ecap2.CAP register to be these values. Thus I assume if you show what your ecap2 CAP register is in the register's debug tab is zero? could you provide a what your ecap2.CAP1 register is?

    Fullscreen
    1
    2
    ECap2Regs.CAP1 = PWM_Duty; // Set Period value
    ECap2Regs.CAP2 = PWM_Period; // Set Compare value
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    In APWM mode, writing to CAP1/CAP2 active registers will also write the same value to the corresponding shadow registers CAP3/CAP4. This emulates immediate mode. Writing to the shadow registers CAP3/CAP4 will invoke the shadow mode. Depending on how you want the loading to occur you may need to write either directly to the CAP1 register or to ecap3/4 CAP1 registers.

  • Hi Ryan,

    1- Regarding GPIO settings, there was no difference found by adding these three lines

    GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0;    // Enable pull-up on GPIO25 (CAP2)

    GpioCtrlRegs.GPAQSEL2.bit.GPIO25 = 0;  //Synch to SYSCLKOUT GPIO25 (CAP2)

    GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 1;   // Configure GPIO25 as CAP2

    2- After running the code, registers ecap2.cap 1/cap2 shows 0 values. Please see the picture below

    3-Then adding these two lines in interrupt routines in the code:

    ECap2Regs.CAP1 = PWM_Duty; // Set Period value
    ECap2Regs.CAP2 = PWM_Period; // Set Compare value

    This starts showing continuous values in ecap2.cap1/cap2 registers. and these values change continuously. But it doesn't generate any PWM output at the oscilloscope from GPIO25. Please see the pictures below.

      

    The updated code is attached here.

    Looking forward for you reply

    Regards

    Arsalan

  • Hi Arsalan,

    It seems that your CAP1 which is the period has a decimal value of 74953 (x124C9) and your CAP2 which is equivalent to a CMPA event has a value of 149977 (x249D9) which means that your CMPA event is never reached. 149977 is past your period that you set it to.

    Try switching these lines of code. I think I wrote this in the opposite way in my previous response, sorry about that.

    ECap2Regs.CAP1 = PWM_Period;
    ECap2Regs.CAP2 = PWM_Duty;

  • Hi Ryan,

    Now I am getting the results PWM signal at 1Khz at 50%duty cycle. Thanks for this step. Another thing is that the signal has a delay and It generates output after around 4-5 seconds and sometimes longer as I increase the freq in step. Please see the picture below for 1KHz PWM at the oscilloscope.

       

    But once I changed the frequency from 1KHz to 120Khz  at 50% or a different duty cycle from the generator and waited for some time or longer period. Again the output doesn't come up and it shows garbage values in the oscilloscope. Please see the results pictures below.

    Looking forward to your feedback

    Regards

    Arsalan

  • Hi Arsalan,

    Could you create a separate thread? The answer provided previously seemed to resolve your original question with getting some output, so we should mark this thread as resolved.

    However this new question is regarding higher frequency APWM. Opening another thread would be helpful for future customers that also are going through this same issue. I will be able to help you out on that other thread.

    Best regards,

    Ryan Ma

  • Sure.

    Thanks for resolving this thread Slight smile