Reset eCAP value when the input signal off
6 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?
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
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.
More Answers (3)
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,
Mohsin Ejaz Ahmad on 23 May 2019
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.
Mohsin Ejaz Ahmad