HI,
I'm trying to use EMIOS input capture SDK functions to measure both the period and duty of a PWM waveform.
The SDK driver seems to have three modes, 'Single capture mode', 'Period measurement mode' and 'Pulse width measurement mode'.
I'm probably missing something simple, but there doesn't seem to be a way to switch modes during runtime, i.e. there's no driver function available and there doesn't seem to be a way of assigning the same channel to another instance of the 'emios_ic' driver.
I would greatly appreciate any help with this matter.
Best regards
Rob
Hi,
you can try below sequence to deinit channel and init again with new config
EMIOS_DRV_ChannelDisableInterruptRequest
EMIOS_DRV_DeInitChannel
EMIOS_DRV_ClrFlagState
EMIOS_DRV_IC_InitInputCaptureMode
EMIOS_DRV_ChannelEnableInterruptRequest
BR, Petr
HI Petr,
Thanks for the instructions.
Not sure what I'm doing wrong....
The command 'EMIOS_DRV_IC_InitInputCaptureMode' requires a config to be specified as the last parameter.
If I try to specify a new config in processor expert, i.e. a config using the same channel but different sub-mode value, it comes up with 'This channel was used by other Input Capture mode configuration'.
Is there a way around this or to disable the error/warning?
Best regards
Rob
Hi,
do not specify new config in PE, try to modify existing one or define new in the code.
BR, Petr
Hi Petr,
Again, thanks for the info.
Have manage to get a period and pulse measurement being undertaken alternately using the methods you suggested. However, it's a little ungainly.
Have noticed that the Single Capture Mode can be used and triggered on both rising and falling edges. This in theory would allow me to calculate the PWM period and duty using a single configuration as long as I could tell if it was a rising or falling edge which triggered the interrupt.
Is there a way to do this, i.e. in the interrupt, via a flag for instance?
Best regards
Rob
Hi,
no flag is available for that, the only option is to read UCIN bit of the Status register after edge is detected.
But you can evaluate period/duty using IPM mode too. Just read/save two consecutive measurement, so for each flag/interrupt call EMIOS_DRV_IC_GetLastMeasurement
BR, Petr
Hi Petr, Sorry for being dense...
If I use Input Period Measurement mode, how can I tell what the duty is from two consecutive readings?
Cheers Rob
Hi,
yes, you are right, my fault, damn...
EMIOS_DRV_IC_GetLastMeasurement is returning single value. For IPM it calculates a difference from captured first and second count.
Well, maybe modify existing driver or create own function to have both values or first and difference?
BR, Petr
HI Petr.
Sorry for the late reply - xmas holidays.
Hope you had a good xmas.
Only low frequency (< 50Hz) - so will probably just read the pin value every millisecond.
Cheers
Rob