Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/samd21: added peripheral PWM driver #3127

Merged
merged 2 commits into from
Jun 5, 2015

Conversation

haukepetersen
Copy link
Contributor

This PR is based on the work of @PeterKietzmann, thanks for your prior work! Great job!

I started a new PR which supersedes #2473 as it is easier to handle for me and so I can offload some work from @PeterKietzmann...

@kaspar030: have a look at the parameter notation in the periph_conf.h, what do you think about this? When we would now allow the CPU to define the pwm_t type to typedef pwm_conf_t pwm_t, we could even simplify the code a little further...

@haukepetersen haukepetersen added Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 30, 2015
@haukepetersen haukepetersen added this to the Release 2015.06 milestone May 30, 2015
#if PWM_0_EN
{TCC1, {
{(PortGroup *)0x41004400, 6, 4, 0}, /* port 0, pin 6, af E, chan 0 */
{(PortGroup *)0x41004400, 7, 4, 1} /* port 0, pin 7, af E, chan 1 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is maybe a stupid question but where do I find these pins?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok really stupid. Forget about it :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't forget that we also need some pins for the ADC #2063. (Currently I'm not thinking about the "new-peripheral" design)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. I actually needed the 4 PWM pins to be on the same connector for my car project, but I can remap them for this PR and create my project-specific mapping on the side.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dammit! Sorry for the confusion, look downwards!

@PeterKietzmann
Copy link
Member

@haukepetersen I successfully tested the pwm on all channels with different cycles and left/right aligned mode. With my cheap logic analyzer I saw some short dropouts (i.e. not longer than one cycle) of the signal. These appeared really sporadic so maybe it's caused by my setup. I don't know if we should merge this PR now, as #3095 seems to be ongoing and this approach would introduce a somehow different driver-design, comparing to others.

@haukepetersen
Copy link
Contributor Author

Actually this PR is completely independent from #3095. Also it is not a different design, just a mere more efficient implementation (with more room for improvement when changing the interface very slightly). The main idea about the driver model was always, that each CPU is free to implement the peripheral drivers as it sees fit (aka the most efficient way possible) while keeping to the API. So this is what this PWM implementation makes use of.

Regarding the dropouts: I was not able to see them at my (cheap) logic analyzer, so my guess would be a measurement problem. I was also running the PWM for a while to control a motor and a server which both worked without trouble, thus strengthen that idea. Further there is nothing in the driver explaining this behavior, right?!

@PeterKietzmann
Copy link
Member

Well, basically you are right so I won't block this improvement. Also nobody else cares about this "different" approach which is a good sign. I agree that there is nothing in the driver explaining this behaviour but as you know, sometimes things happen that you don't have expected! Anyway, I'm convinced that these dropouts were caused by a measurement problem

@haukepetersen
Copy link
Contributor Author

Alright, so shoud I squash? I would suggest then to merge this and take the pinout discussion somewhere else.

@OlegHahm OlegHahm added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Jun 3, 2015
@PeterKietzmann
Copy link
Member

Öhm, can we at least solve to conflict of GPIO_3 and PWM_1_CH_2? E.g. by moving one of them to another pin. As far as I've seen it, PA14 and PB03 are still unused. Just want to avoid potential conflicts with this PR. We can start working on an optimized mapping in another PR and in the list you sent.

@haukepetersen
Copy link
Contributor Author

of course (just forgot to do so before my last comment). Moved GPIO_3 to PB03.

@PeterKietzmann
Copy link
Member

ACK when squashed and happy Travis. @kaspar030 do you want to comment on the parameter notation in the "periph_conf.h`?

@kaspar030
Copy link
Contributor

@kaspar030 do you want to comment on the parameter notation in the "periph_conf.h`?

Looks good, but now that you're asking, I would take the values out of the comments. I'll PR to show.
edit haukepetersen#13

Parameter notation looks good to me. port + pin maybe can be one variable once hauke's new gpio implementation is merged.

@haukepetersen
Copy link
Contributor Author

Parameter notation looks good to me. port + pin maybe can be one variable once hauke's new gpio implementation is merged.

Yes, that is the plan.

@haukepetersen haukepetersen removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 5, 2015
@haukepetersen haukepetersen added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Jun 5, 2015
@haukepetersen
Copy link
Contributor Author

added @kaspar030's fix and squashed

@haukepetersen
Copy link
Contributor Author

And regarding the configuration in the periph_conf.h: Those structs that are defined there should of course also be moved into the cpus periph_cpu.h header once the gpio-remodelling PR is merged...

@PeterKietzmann
Copy link
Member

Then let's ACK and go!

PeterKietzmann added a commit that referenced this pull request Jun 5, 2015
cpu/samd21: added peripheral PWM driver
@PeterKietzmann PeterKietzmann merged commit 0bdf2a2 into RIOT-OS:master Jun 5, 2015
@haukepetersen haukepetersen deleted the add_samd21_pwm branch June 5, 2015 14:08
@iseitani
Copy link

Hello,
I have a question, you acquired the expected frequencies when you used a logical analyzer?
I just cloned the master rep and when I measured the frequency using an oscilloscope instead of the expected, as its mentioned in the readme file 1kHz, I received a frequency of 47-76kHz with period 19-24 μs.
Any idea what went wrong? (I have already validated that the oscilloscope works correctly)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants