Advanced PWM for Arduino Zero or any Atmel SAMD21 Based Arduino Board

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Really nice video and well explained. About the only thing you could have emphasised a bit more was how cool these Atmel functions are in that you can run PWM completely independent of the code in loop(). You touched on it but it is so powerful- like having two separate processors for the price of one.

jslonisch
Автор

Great tutorial! Thanks! BTW I can't figure out why the PMUXE and PMUXO pin numbers are different from the enabling PMUXEN (here 7 and 3 for PMUXEN) but 2 and 4 for PMUXE and PMUXO... Any hints?

// Enable the port multiplexer for the digital pin. Note commented out line is pin D7, other is D3

// 7 7 ].ulPin].bit.PMUXEN = 1;

3 3 ].ulPin].bit.PMUXEN = 1;



//Connect the TCC0 timer to digital output - port pins are paired odd PMUO and even PMUXE (note D7 is commented out and D3 is not)

// 2 2 ].ulPin >> 1].reg = PORT_PMUX_PMUXO_F | PORT_PMUX_PMUXE_F;

4 4 ].ulPin >> 1].reg = PORT_PMUX_PMUXO_F | PORT_PMUX_PMUXE_F;

PARAMETATRONIC
Автор

Hello again :-)

So, splashed out on a new Zero board and loaded the script. It works, but what I found was that the length of time that the signal is present varies enormously. In the main, the PWM square wave is running for a couple of seconds, then switches off again. The length of time when it's running is completely random; a second or a few seconds up and it dies again, though frequency and duty cycle are adjustable as described.

I wondered if it was something to do with the USB power supply, but running it off my Rigol PSU made no difference.

I thought maybe I just had a dodgy board, but I'm trying this on a new board, fresh out of the box from Italy, and its behaviour is exactly the same.

So, working through the setup you had on your breadboard in the video... identical, barring I was using a different ground pin on the board I was using muti-turn pots! I'm cooking the PWM at about 100kHz, so maybe I've got some odd mag-coil thing going on? Have I made a funky inductor with my wire wound pot?

Swapped out the multi-turn pots with standard single turn trimmers and hey-presto! Rock solid output, around the 65kHz anyway. Too high; above about 80kHz and things get a bit flaky.

Many thanks again for your time developing the code, and getting this vid' together for the rest of us newbies to learn.

captiveimage
Автор

Thank you for this awesome tutorial! Unfortunately i've been facing a problems with your code: At 13:13 you are pointing out the muxing, but this configuration does not work for me. If you want to use D3 as output both lines should contain the identical Pin Number: g_APinDescription[3]. (Maybe this was an issue in 2016 and was fixed later in the Arduino IDE(?)).
It works also directly, if you put in the Group and the pinnumber from the Datasheet. E.g. PA04 -> Group[0] and PINCFG[4].
And i think once the comment contains TCC0 which should be TCC1 (14:01) and in the last line the reset interrupt should also be _TCC1 instead of _TCC0? Please correct me, if i got sth wrong.
The last thing what i am wondering about is, what does >> 1 mean in the PMUX argument? As far as i know >> 1 does mean divide by 2, or? Which relevant function has it in this context?

microelectronics
Автор

Thanks for the well made and very useful tutorial. Is possible to get two outputs shifted each other 90°?

tizianogiacomoni
Автор

Stupid question but will this work on the Mega 2560 R3?

thecriticalpoint
Автор

Nice tutorial, but unfortunately the code doesn't seem to work on the MKR1000.  Any suggestions?

captiveimage
Автор

I have a question ... can I use PWM on PB22 and PB23?
I'm planning a custom board and I'm wondering if these could do PWM.

BenjaminEsposti
welcome to shbcf.ru