S32K3 measuring PWM duty cycle (eMIOS ICU IPWM) without blocking

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K3 measuring PWM duty cycle (eMIOS ICU IPWM) without blocking

469 Views
Hareesh_S
Contributor II

Hello,

For context -
I am using an eMIOS ICU channel to measure a varying PWM duty cycle in IPWM mode. I am currently able to successfully measure duty cycle in a "blocking" manner.

My input transitions from 100% duty cycle (effectively no PWM) to a PWM signal of a given duty cycle which I need to measure.

My .mex configuration is as follows - 

Hareesh_S_0-1778951748752.png

Hareesh_S_1-1778951764813.png

My sample code is as follows -

Hareesh_S_2-1778952311888.png

While this works, I would prefer to start signal measurement once and periodically call Emios_Icu_Ip_GetDutyCycleValues(), without having to call Emios_Icu_Ip_StopSignalMeasurement(), to avoid being blocked before the measurement is complete. Alternatively, if there is a interrupt fired whenever a measurement has completed, that would work for me too.

I have tried only calling Emios_Icu_Ip_StartSignalMeasurement() initially and calling Emios_Icu_Ip_GetDutyCycleValues() periodically (every 1 second, while the PWM frequency is 1kHz), but the data is inaccurate.

From my understanding, SAIC is better suited for varying PWM signals (which I believe fits my usecase), but I assume I could also use IPWM, with a delayed measurement reading. I do not mind if the returned result is slightly delayed or stale by few milliseconds as I am not expecting rapid changes in duty cycle, and the frequency will be constant.

If someone can clarify how I can achieve this using IPWM, or if I can only implement this via SAIC, that would be great.

Thanks 

 

0 Kudos
Reply
1 Reply

370 Views
petervlna
NXP TechSupport
NXP TechSupport

Hello,

The issue you’re hitting is a known limitation of the eMIOS ICU IPWM mode on S32K3:
IPWM is inherently “measurement-window based”, not continuous, so reading it periodically without restarting/closing the measurement leads to stale or partially updated values.

IPWM is not designed for unsynchronized periodic polling
You must either:

  • use interrupt notification, or
  • restart measurement before reading, or
  • switch to SAIC for true non-blocking continuous measurement

Best regards,

Peter

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2366505%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K3%20measuring%20PWM%20duty%20cycle%20(eMIOS%20ICU%20IPWM)%20without%20blocking%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2366505%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20context%20-%3CBR%20%2F%3EI%20am%20using%20an%20eMIOS%20ICU%20channel%20to%20measure%20a%20varying%20PWM%20duty%20cycle%20in%20IPWM%20mode.%20I%20am%20currently%20able%20to%20successfully%20measure%20duty%20cycle%20in%20a%20%22blocking%22%20manner.%3CBR%20%2F%3E%3CBR%20%2F%3EMy%20input%20transitions%20from%20100%25%20duty%20cycle%20(effectively%20no%20PWM)%20to%20a%20PWM%20signal%20of%20a%20given%20duty%20cycle%20which%20I%20need%20to%20measure.%3C%2FP%3E%3CP%3EMy%20.mex%20configuration%20is%20as%20follows%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Hareesh_S_0-1778951748752.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Hareesh_S_0-1778951748752.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Hareesh_S_0-1778951748752.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F385658i9281C78FFB88E39D%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Hareesh_S_0-1778951748752.png%22%20alt%3D%22Hareesh_S_0-1778951748752.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Hareesh_S_1-1778951764813.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Hareesh_S_1-1778951764813.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Hareesh_S_1-1778951764813.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F385659i355841AE2F0E388C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Hareesh_S_1-1778951764813.png%22%20alt%3D%22Hareesh_S_1-1778951764813.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EMy%20sample%20code%20is%20as%20follows%20-%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Hareesh_S_2-1778952311888.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Hareesh_S_2-1778952311888.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Hareesh_S_2-1778952311888.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F385660iB49D07A980A1AC36%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Hareesh_S_2-1778952311888.png%22%20alt%3D%22Hareesh_S_2-1778952311888.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EWhile%20this%20works%2C%20I%20would%20prefer%20to%20start%20signal%20measurement%20once%20and%20periodically%20call%26nbsp%3B%3CSPAN%3EEmios_Icu_Ip_GetDutyCycleValues()%2C%20without%20having%20to%20call%20Emios_Icu_Ip_StopSignalMeasurement()%2C%20to%20avoid%20being%20blocked%20before%20the%20measurement%20is%20complete.%20Alternatively%2C%20if%20there%20is%20a%20interrupt%20fired%20whenever%20a%20measurement%20has%20completed%2C%20that%20would%20work%20for%20me%20too.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FSPAN%3EI%20have%20tried%20only%20calling%26nbsp%3B%3CSPAN%3EEmios_Icu_Ip_StartSignalMeasurement()%20initially%20and%20calling%26nbsp%3BEmios_Icu_Ip_GetDutyCycleValues()%20periodically%20(every%201%20second%2C%20while%20the%20PWM%20frequency%20is%201kHz)%2C%20but%20the%20data%20is%20inaccurate.%3CBR%20%2F%3E%3CBR%20%2F%3EFrom%20my%20understanding%2C%20SAIC%20is%20better%20suited%20for%20varying%20PWM%20signals%20(which%20I%20believe%20fits%20my%20usecase)%2C%20but%20I%20assume%20I%20could%20also%20use%20IPWM%2C%20with%20a%20delayed%20measurement%20reading.%20I%20do%20not%20mind%20if%20the%20returned%20result%20is%20slightly%20delayed%20or%20stale%20by%20few%20milliseconds%20as%20I%20am%20not%20expecting%20rapid%20changes%20in%20duty%20cycle%2C%20and%20the%20frequency%20will%20be%20constant.%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20someone%20can%20clarify%20how%20I%20can%20achieve%20this%20using%20IPWM%2C%20or%20if%20I%20can%20only%20implement%20this%20via%20SAIC%2C%20that%20would%20be%20great.%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%26nbsp%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2366709%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K3%20measuring%20PWM%20duty%20cycle%20(eMIOS%20ICU%20IPWM)%20without%20blocking%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2366709%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3EThe%20issue%20you%E2%80%99re%20hitting%20is%20a%20known%20limitation%20of%20the%20eMIOS%20ICU%20IPWM%20mode%20on%20S32K3%3A%3CBR%20%2F%3EIPWM%20is%20inherently%20%E2%80%9Cmeasurement-window%20based%E2%80%9D%2C%20not%20continuous%2C%20so%20reading%20it%20periodically%20without%20restarting%2Fclosing%20the%20measurement%20leads%20to%20stale%20or%20partially%20updated%20values.%3C%2FP%3E%0A%3CP%3EIPWM%20is%20not%20designed%20for%20unsynchronized%20periodic%20polling%3CBR%20%2F%3EYou%20must%20either%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Euse%20interrupt%20notification%2C%20or%3C%2FLI%3E%0A%3CLI%3Erestart%20measurement%20before%20reading%2C%20or%3C%2FLI%3E%0A%3CLI%3Eswitch%20to%20SAIC%20for%20true%20non-blocking%20continuous%20measurement%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EBest%20regards%2C%3C%2FP%3E%0A%3CP%3EPeter%3C%2FP%3E%3C%2FLINGO-BODY%3E