Hello!
This is my first ChibiOS HAL driver, so I would really appreciate any and all feedback. It's not complete (no pwm/channel interrupt support) but PWM output does work.
I just wanted to share what I've done so far just in case anyone else finds it useful.
I don't have a logic analyzer or scope here at home so I can't verify that the timing is proper, but I went over the datasheet a million and a half times and the code looks correct.
The demo is for the Freedom KL25Z board. It activates the accelerometer and modulates the RGB LED depending on board orientation.
After completing the driver with channel interrupt support, I'll be looking at the ICU driver next since the same TPM block is used.
Have fun!
KL25Z PWM Driver and Demo
Moderator: utzig
-
- Posts: 359
- Joined: Sat Jan 07, 2012 6:22 pm
- Location: Brazil
- Has thanked: 1 time
- Been thanked: 20 times
- Contact:
Re: KL25Z PWM Driver and Demo
I have both equipment and will test this tomorrow or in the weekend.
Cheers,
Fabio Utzig
Cheers,
Fabio Utzig
Re: KL25Z PWM Driver and Demo
utzig wrote:I have both equipment and will test this tomorrow or in the weekend.
Cheers,
Fabio Utzig
You rock! I'll try to grab my Saleae from work for this weekend... working blind is a pain.
I appreciate you testing this and I especially appreciate the work you did for the Kinetis port!
Re: KL25Z PWM Driver and Demo
Okay, so I hooked up my Saleae at work and here's what I got:
Frequency: 12000000
Period: 65535
Measured PWM frequency: 183.1 Hz
Frequency: 12000000
Period: 20000
Measured PWM frequency: 599.97 (sometimes 600 even) Hz
Frequency: 6000000
Period: 30000
Measured PWM frequency: 199.99 Hz
I set duty cycle to 20% using
At 200Hz I measured 1ms low to 4ms high on for the 5ms period (my configuration is PWM_OUTPUT_ACTIVE_LOW).
Everything looks right!
Frequency: 12000000
Period: 65535
Measured PWM frequency: 183.1 Hz
Frequency: 12000000
Period: 20000
Measured PWM frequency: 599.97 (sometimes 600 even) Hz
Frequency: 6000000
Period: 30000
Measured PWM frequency: 199.99 Hz
I set duty cycle to 20% using
Code: Select all
pwmEnableChannel(&PWMD3, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, 2000));
At 200Hz I measured 1ms low to 4ms high on for the 5ms period (my configuration is PWM_OUTPUT_ACTIVE_LOW).
Everything looks right!
Re: KL25Z PWM Driver and Demo
I finished the support for periodic and channel notifications via interrupts... it's way past my bedtime so I'll work up a new patch set tomorrow.
I've been fighting with the kl25z.h CMSIS header... a lot of TPM references are typed TMP. I also made a change to the TPM_TypeDef structure to ease access to channel SC and V registers.
I've been fighting with the kl25z.h CMSIS header... a lot of TPM references are typed TMP. I also made a change to the TPM_TypeDef structure to ease access to channel SC and V registers.
Re: KL25Z PWM Driver and Demo
Fabio,
Thank you! I've attached the finished PWM driver and demo.
The stuff in kinetis_tpm.h might belong in kl25z.h... I wasn't sure. If you would prefer the defines in the CMSIS header, let me know and I'll move them and resubmit.
Thank you for helping me with this, I really appreciate it!
Regards,
Adam
Thank you! I've attached the finished PWM driver and demo.
The stuff in kinetis_tpm.h might belong in kl25z.h... I wasn't sure. If you would prefer the defines in the CMSIS header, let me know and I'll move them and resubmit.
Thank you for helping me with this, I really appreciate it!
Regards,
Adam
- Attachments
-
- kinetis-pwm.patch.zip
- PWM Driver version 2
- (12.1 KiB) Downloaded 393 times
-
- Posts: 359
- Joined: Sat Jan 07, 2012 6:22 pm
- Location: Brazil
- Has thanked: 1 time
- Been thanked: 20 times
- Contact:
Re: KL25Z PWM Driver and Demo
Adam,
I commited the HAL driver. I also changed the TPM typedef to enable channel access with C[channel_number].SC, etc. I have not commited the demo yet because I want to merge it with the current main demo.
Please update your SVN repo and review that everything is ok, I tested it here but always good having a second opinion.
Would also be cool if you could implement:
Ah, the other Kinetis MCUs (not KL) use a slightly different subsystem called Flexible Timer Module, or something like that, which is a superset of the TPM.
Cheers,
Fabio Utzig
I commited the HAL driver. I also changed the TPM typedef to enable channel access with C[channel_number].SC, etc. I have not commited the demo yet because I want to merge it with the current main demo.
Please update your SVN repo and review that everything is ok, I tested it here but always good having a second opinion.
Would also be cool if you could implement:
Code: Select all
void pwm_lld_enable_periodic_notification(PWMDriver *pwmp);
void pwm_lld_disable_periodic_notification(PWMDriver *pwmp);
void pwm_lld_enable_channel_notification(PWMDriver *pwmp,
pwmchannel_t channel);
void pwm_lld_disable_channel_notification(PWMDriver *pwmp,
pwmchannel_t channel);
Ah, the other Kinetis MCUs (not KL) use a slightly different subsystem called Flexible Timer Module, or something like that, which is a superset of the TPM.
Cheers,
Fabio Utzig
Re: KL25Z PWM Driver and Demo
Hi Fabio,
The second version of the patch, attached to my last post, has interrupt and periodic/channel notification support.
What I'll do is update my repository, and make a new incremental patch against what you've checked in.
Edit: Attached
The main HAL pwm.c does channel bounds checking, so I'm not sure if we need it in the lld as well. But I've followed your examples and added them to the channel notification functions.
Thank you,
Adam
The second version of the patch, attached to my last post, has interrupt and periodic/channel notification support.
What I'll do is update my repository, and make a new incremental patch against what you've checked in.
Edit: Attached
The main HAL pwm.c does channel bounds checking, so I'm not sure if we need it in the lld as well. But I've followed your examples and added them to the channel notification functions.
Thank you,
Adam
- Attachments
-
- kinetis-pwm-interrupt.patch.zip
- (1.52 KiB) Downloaded 430 times
-
- Posts: 359
- Joined: Sat Jan 07, 2012 6:22 pm
- Location: Brazil
- Has thanked: 1 time
- Been thanked: 20 times
- Contact:
Re: KL25Z PWM Driver and Demo
The main HAL pwm.c does channel bounds checking, so I'm not sure if we need it in the lld as well. But I've followed your examples and added them to the channel notification functions.
Totally right. I removed the extra checking.
Sorry for the previous mess up and thanks for everything!
Cheers,
Fabio Utzig
Who is online
Users browsing this forum: No registered users and 22 guests