Kinetis and PWM

General discussion on mikroPascal PRO for ARM.
Post Reply
Author
Message
Dan_Rig
Posts: 15
Joined: 28 Oct 2013 16:36

Kinetis and PWM

#1 Post by Dan_Rig » 04 Sep 2016 10:51

I am porting and application from mikroPascal PRO for Pic to
mikroPascal PRO for Arm.
In the original application I used the PWM library to generate
a frequency of 250KHz using a PIC P18F25K22.
I try to make the same thing on a Clicker for Kinetis board
that uses the MK22FN512XXX12 processor,
so I use the instruction:

Code: Select all

PWM_FTM0_Init(250000,_PWM_EDGE_ALIGNED_PWM, _PWM_CHANNEL_0, @_GPIO_Module_PWM0_PTC1);
but the compiler gives the error
339 305 Argument is out of range "250000" to "word" clicker for Kinetis.mpas
339 327 Incompatible types ("dword" to "word") clicker for Kinetis.mpas
Indeed, the declaration of PWM_Init in mikroPascal for PIC is

Code: Select all

procedure PWMx_Init(const freq : longint);
and in mikroPascal for ARM is

Code: Select all

function PWM_FTMx_Init(freq_hz : word; config : word; channel : word, module : ^Module_Struct) : word;
So we have word vs longint.
It would be strange that and ARM is so less powerful than a PIC.
Is it a problem in the library?
How can I circumvent this?

Thank you,
Dan

User avatar
biljana.nedeljkovic
mikroElektronika team
Posts: 1043
Joined: 30 Jun 2015 15:15

Re: Kinetis and PWM

#2 Post by biljana.nedeljkovic » 05 Sep 2016 16:38

Hello,

We have modified the PWM library for the Kinetis clicker.
In the attachment you will find the new emcl file for this library.

Replace it with the existing one.
We have made this modification for your needs, so consider this as a unofficial beta version that will be added to the next update of the compiler once we retest it.

I would appreciate your feedback, to find out if this have solved your issue.

Kind regards,
Biljana
Attachments
__Lib_PWM_MK22_0123.rar
(17.95 KiB) Downloaded 162 times

Dan_Rig
Posts: 15
Joined: 28 Oct 2013 16:36

Re: Kinetis and PWM

#3 Post by Dan_Rig » 05 Sep 2016 19:31

Thank you very much!
Now the compiler accept the longword, but there is still a little problem.
There is a limit in frequency beyond which the PWM does not work anymore.
With some tests I have found that:

If I use the frequency until 245901 Hz everything works well:

Code: Select all

 PWM_FTM0_Init(245901,_PWM_EDGE_ALIGNED_PWM, _PWM_CHANNEL_0, @_GPIO_Module_PWM0_PTC1);
 PWM_FTM0_Set_Duty(50,_PWM_NON_INVERTED,_PWM_CHANNEL_0);
 PWM_FTM0_Start(_PWM_CHANNEL_0);
While if I use a frequency beyond 245901

Code: Select all

 PWM_FTM0_Init(245902,_PWM_EDGE_ALIGNED_PWM, _PWM_CHANNEL_0, @_GPIO_Module_PWM0_PTC1);
 PWM_FTM0_Set_Duty(50,_PWM_NON_INVERTED,_PWM_CHANNEL_0);
 PWM_FTM0_Start(_PWM_CHANNEL_0);
I get only sparse negative impulses, see images.
However the maximum frequency is really close to what I need of 250000 Hz, so I am not
stuck in my development.

Thank you again,
Dan

P.S. I am available to test other betas if you are pleased.
Attachments
PWM at 245902 Hz
PWM at 245902 Hz
245902.jpg (40.06 KiB) Viewed 3689 times
PWM at 245901 Hz
PWM at 245901 Hz
245901.jpg (35.64 KiB) Viewed 3689 times

User avatar
biljana.nedeljkovic
mikroElektronika team
Posts: 1043
Joined: 30 Jun 2015 15:15

Re: Kinetis and PWM

#4 Post by biljana.nedeljkovic » 06 Sep 2016 16:17

Hi,

We will test this to check if the problem is present only in the Kinetis library or a general problem.

Once we make some modification I will send you another emcl.

Thank you for reporting this.

Kind regards,
Biljana

Post Reply

Return to “mikroPascal PRO for ARM General”