Clear Filters
Clear Filters

Reset eCAP value when the input signal off

4 views (last 30 days)
I am using the C2000 extension on MATLAB 2018b.
I've configured the eCAP block to read the duty cycle of a PWM.
To do so, i divide the 2 outputs generated by the block. For example, with a duty cycle of 0.2 the outputs are 200 and 1000.
The problem is that when you turn off the signal generator, the value obtained by this is the same as the last one.
In the attached image, it can be seen the next cycle: Off --> 0.2 --> 0.5 --> 0.8 --> Off --> 0.8 --> 50
Whenever the generator is working there is noise in the signal, but when it is off, the signal holds the last value and has no noise.
How can I reset the value when it is off?
Thank you!

Accepted Answer

Antonin
Antonin on 1 Mar 2019
Hi Eduard,
It's surprising that the memory copy block returns the same value. Please double check the settings like data types and eCAP module. For eCAP module 2 you have to use &ECap2Regs.TSCTR instead of &ECap1Regs.TSCTR.
I use this exact technique in the following example: c28035pmsmfoc_ert
Under:
FOC Alogrithm/Torque Control Algorithm/Input Scaling/Speed and direction are valid/Extract Position from Halls/Direction 1/Hall B falling/ECap1Regs.TSCTR'
You can copy/paste the block from there.
It should work, good luck.
Antonin.
  1 Comment
Antonin
Antonin on 1 Mar 2019
Sample time is important as well, make sure that it's not "Inf" on the memory copy block, in which case Simulink may optimize the block out of the step function and only rely on the init value.

Sign in to comment.

More Answers (3)

Antonin
Antonin on 1 Mar 2019
Hi Eduard,
Interesting question. The capture module can only give you time that elapsed between edges. If your PWM reaches 0% or 100%, the eCAP module will not update.
I would read the eCAP counter and detect when it goes beyond the maximum PWM period, in which case I would invalidate the readings from the eCAP registers. You can do this with the Memory Copy block (cf snapshot attached), the address of the register you need to access is: &ECap1Regs.TSCTR to read the time value.
To make the difference between 0 and 100%, you could enable the status flag on the eCAP block and keep track of which of the 2 events came last. Alternatively, you could also use the Memory Copy block and read the GPIO data register to detect whether the eCAP pin is high or low.
The eCAP block is always best used in an interrupt like in the c28069pmsmfoc_ert example to make sure that you are not missing events. I would also react on the overflow of the eCAP counter to make sure that you don't get bogus results if the signal stays flat for too much time.
I hope it helps,
Good luckeCAP_MemCopy.JPG
Antonin.
  1 Comment
Eduard Monlleo
Eduard Monlleo on 1 Mar 2019
Hi Antonin,
Thanks for your response.
I don't get at all this paragraph:
I would read the eCAP counter and detect when it goes beyond the maximum PWM period, in which case I would invalidate the readings from the eCAP registers. You can do this with the Memory Copy block (cf snapshot attached), the address of the register you need to access is: &ECap1Regs.TSCTR to read the time value.
I have tried using the Memory Copy block but it shows a constant value of 1865, even when the PWM is 0.
Also, I have tried to use a comparator of the signal that contains the period with a value slightly higher than the period itself, but half of the times the value goes higher and the others stays the same (both with no noise), so it is not reliable.
model.PNG
Another thought was to compare the real signal with the same with some delay, since when the Function Generator is off the signal stays steady.
The output was the next
delayed.PNG
Thanks once again!

Sign in to comment.


Mohsin Ejaz Ahmad
Mohsin Ejaz Ahmad on 23 May 2019
Hello all,
I am also trying to use eCAP module to read the PWM signal but in my case the eCAP is not giving any output. Please help me in this regard. May be I have some issue in the "model configuration parameters" but I am extending the simulink block of one of the LIN example present in the libarary for F28035 controller. I have uploaded the whole figure.
Regards,
Mohsin Ejaz AhmadeCap.PNG

Venkatesh Chilapur
Venkatesh Chilapur on 23 May 2019
Hi,
Please refer this example 'c28035pmsmfoc_ert' we have eCAP block implemention under 'c28035pmsmfoc_ert/Hall Sensor A'.
Regards,
Venkatesh C

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!