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.
I generated a square pulse signal 1 KhZ 50% duty cycle from the function generator and applied at port GPIO24(Ecap1) using Ecap module. The signal is shown on the watch window and passed to GPIO25 (Ecap 2) which is visible at the oscilloscope. Two Problems :
1- When I turn off the generator signal, the signal remains in the buffer and it doesn't clear. Please see the pictures after turning off the generator signal and oscilloscope retain the signal having peaks neither stable high nor low.
2- Once I change the frequency from 1KHz to 120Khz at 50% or a different duty cycle from the generator, the signal doesn't remain stable at that specific freq / duty cycle. Both frequency and duty cycle vary. Please see the results pictures below.
Please suggest in the code. Santosh Jha
Hi Arsalan,
I realized instead of writing to CAP1/CAP2, we should write to the CAP3/4 registers to perform a shadow to active load. This might help with the instability that you're seeing.
ECap2Regs.CAP3 = PWM_Period;
ECap2Regs.CAP4 = PWM_Duty;
Then instead of setting the TSCTR = 0, we should re arm the ECAP module by writing to this register/bit.
ECap1Regs.ECCTL2.REARM = 1;
Try this and let me know if it fixes the instability.
Best,
Ryan Ma
Hi Ryan,
Thanks for your help after adding the lines. The signal is stable now but with delays and it doesn't move either high or low after turning off the generator ( which shows peaks).
Note: At 1Khz this delay is quite minimum. In previous posts, this delay was removed by TSCTR = 0
Here are the updates below for 120Khz signal:
120 Khz & 50% duty cycle Signal from Generator ==>
Firstly no output is seen on the scope and the register values are given below:
After some delay (nearly 5-10sec), I got the stabilized output. Registers values & Output signal are shown ==>
When turning off the generator signal, the signal remains in the buffer(registers) ==>
Another thing, I introduced one more GPIO26 for ECap3 for the 2nd APWM signal which is an inversion of GPIO25(Ecap2-APWM). For this, I added one thing i.e- ECap3Regs.ECCTL2.all = 0x0496; for the inverted signal of APWM-Ecap2 at line 190(setting polarity APWMPOL = 1). Also two more variables are introduced here: PWM2_Period & PWM2_Duty. Please review the code accordingly.
Looking forward to your feedback
Thanks
Regards
Arsalan
Hi Arsalan,
When you turn off the generator, do the ECAP registers like CAP2/CAP1 not go to zero? Could you show me what you're seeing from these registers once you turn off the generator?
Could you ask some logic to say if the Period is below a certain threshold, set your duty to zero or disarm the capture?
Let me know if that is able to fix your first problem.
Best,
Ryan Ma
Hi Ryan,
Yes Cap1/Cap2 registers don't go to zero. The register output is given in last image. This is the case right now:
At 120Khz, registers values and signals outputs are:
Channel 1 output: APWM1_GPIO25
Channel 2 output : APWM2_GPIO26
After turning off the generator signal: the signal and the output of the registers are shown below:
Looking forward for your reply.
Thanks
Arsalan
Hi Arslan,
The reason why the signal is kept high and not going low is because when your counter reaches your CMP value which is very close to the period. It will clear the output signal and then be set again once the period occurs. That's why you see that toggle near the end.
The signal will be set when the period is reached, and only toggle low when a CMP event occurs. So in order to turn off your ecap, you need to set your CMP value to the period. That way whenever a period event or cmp event occurs it will be off. This is up to your implementation on when this occurs.
Ok Thanks for your help Ryan. I am closing this thread as resolved. There is one more thing which is the deadband implementation for PWM signal. For this, I will make new thread with some explanation.Thanks Ryan