We are using iMX7D running WEC7 and FreeRTOS on M4 side.
We plan to use PWM (PWM_D / SODIMM.67) to generate different frequencies.
To test it, we have successfuly tried Pwm_Demo sample code in WEC7, and could reach 10MHz frequency output.
But we don’t know which parameter range/value is able to be used in order to reach higher frequencies.
Pwm_SetPwm(pwm, 20000000/*Hz*/, 32768/*of 65536*/); // 20MHz, 50%
The application crashes.
We neither don’t know allowed values for ‘BaseFreq’ parameter in ‘Pwm_SetConfigInt()’ functon.
We looked at: How to use PWM Library
Where it is described how to calculate all other modules frequencies, but nothing about iMX7D.
- Could you give us iMX7D allowed values/ranges? (freq, prescale, min, max, etc.)
- Is there a better option to generate frequency output better than PWM?
Thanks in advance!
Hi @apanelli ,
The allowed values/ranges are documented in the Toradex_CE_Libraries.chm that comes with the Libraries package. Here an extract:
Base clock frequency for the PWM
generator in Hz.
This frequency defines the time
resolution of the PWM signal
(resolution = 1/baseFreq) Allowed base
• 100.0 Mhz/n, where n is 1 to 4096.
If baseFreq is not one of these
frequencies, the PwmLib will select
the next higher frequency.
• PWM output = Base freq / n + 2 ,
where n = 0 to 65534.
A PWM period can be configured to be 1
to 65536 cycles of the baseFreq.
Therefore the lowest achievable PWM
frequency is baseFreq/65536
So a 20 Mhz signal should be possible with baseFreq=100000000 (100Mhz). It will divide the baseFreq by 5 to obtain the 20 Mhz. but the duty cycle cannot be exactly 50% as we have 5 clocks, so it can be 2/5 or 3/5.
But i don’t understand why it crashes for you. It should only Do some asserts if the values are out of range,. Can you share your code so we can reproduce the issue?
Hi @germano.tx , thanks for your help.
I was looking at the wrong place, I’ve never seen the ‘.chm’ file (I was reading https://developer.toradex.com/knowledge-base/how-to-use-pwm-library ).
The crash was because as I didn’t know how parameters should be used, I was trying to set 20MHz calling ‘Pwm_SetPwm()’, with 20MHz as base frequency, so it is an invalid value.
I was geting:
Pwm Error: using minimum frequency (305Hz) instead of requested Frequency (20000000Hz)Unknown: DEBUGCHK failed in file .\src\pwm_imx7.c at line 714
Now I set ‘BaseFreq’ to 100MHz and it is working correctly.
You are welcome. Thanks for your feedback.