|
| 1 | + |
| 2 | +# SAMD Support |
| 3 | + |
| 4 | +SimpleFOC supports many SAMD21 MCUs, really any SAMD21 supported by Arduino core should work. |
| 5 | + |
| 6 | +## Pin assignments |
| 7 | + |
| 8 | +The SAMD chips have some very powerful PWM features, but do not have flexible pin assignments. |
| 9 | + |
| 10 | +You should be able to use *most* (but not all!), pin combinations for attaching your motor's PWM pins. Please ignore the board descriptions and pinout diagrammes regarding PWM-pins on SAMD boards. They are pretty much all incorrect to varying degrees of awfulness. |
| 11 | + |
| 12 | +On SAMD we use TCC and TC timer peripherals (built into the SAMD chip) to control the PWM. Depending on the chip there are various timer units, whose PWM outputs are attached to various different pins, and it is all very complicated. Luckily SimpleFOC sets it all up automatically *if* there is a compatible configuration for those pins. |
| 13 | + |
| 14 | +Not all timers are created equal. The TCC timers are pretty awesome for PWM motor control, while the TC timers are just ok for the job. So to get best performance, you want to use just TCC timer pins if you can. |
| 15 | + |
| 16 | +By enabling |
| 17 | + |
| 18 | +``` |
| 19 | + #define SIMPLEFOC_SAMD_DEBUG |
| 20 | +``` |
| 21 | + |
| 22 | +in drivers/hardware_specific/samd_mcu.cpp<br> |
| 23 | +you will see a table of pin assignments printed on the serial console, as well as the timers SimpleFOC was able to find and configure on the pins you specified. You can use this to optimize your choice of pins if you want. |
| 24 | + |
| 25 | +You can configure up to 12 pins for PWM motor control, i.e. 6x 2-PWM motors, 4x 3-PWM motors, 3x 4-PWM motors or 2x 6-PWM motors. |
| 26 | + |
| 27 | +## PWM control modes |
| 28 | + |
| 29 | +All modes (3-PWM, 6-PWM, Stepper 2-PWM and Stepper 4-PWM) are supported. |
| 30 | + |
| 31 | +For 2-, 3- amd 4- PWM, any valid pin-combinations can be used. If you stick to TCC timers rather than using TC timers, then you'll get getter PWM waveforms. If you use pins which are all on the same TCC unit, you'll get the best result, with the PWM signals all perfectly aligned as well. |
| 32 | + |
| 33 | +For 6-PWM, the situation is much more complicated:<br> |
| 34 | +TC timers cannot be used for 6-PWM, only TCC timers. |
| 35 | + |
| 36 | +For Hardware Dead-Time insertion, you must use H and L pins for one phase from the same TCC unit, and on the same channel, but using complementary WOs (Waveform Outputs, i.e. PWM output pins). Check the table to find pins on the same channel (like TCC0-0) but complementary WOs (like TCC0-0[0] and TCC0-0[4] or TCC1-0[0] and TCC1-0[2]). |
| 37 | + |
| 38 | +For Software Dead-Time insertion, you must use the same TCC and different channels for the H and L pins of the same phase. |
| 39 | + |
| 40 | +Note: in all of the above note that you *cannot* set the timers or WOs used - they are fixed, and determined by the pins you selected. SimpleFOC will find the best combination of timers given the pins, trying to use TCC timers before TC, and trying to keep things on the same timers as much as possible. If you configure multiple motors, it will take into account the pins already assigned to other motors. |
| 41 | +So it is matter of choosing the right pins, nothing else. |
| 42 | + |
| 43 | +Note also: Unfortunately you can't set the PWM frequency. It is currently fixed at 24KHz. This is a tradeoff between limiting PWM resolution vs |
| 44 | +increasing frequency, and also due to keeping the pin assignemts flexible, which would not be possible if we ran the timers at different rates. |
| 45 | + |
| 46 | +## Status |
| 47 | + |
| 48 | +Currently, SAMD21 is supported, and SAMD51 is unsupported. SAMD51 support is in progress. |
| 49 | + |
| 50 | +Boards tested: |
| 51 | + |
| 52 | + * Arduino Nano 33 IoT |
| 53 | + * Arduino MKR1000 |
| 54 | + * Arduino MKR1010 Wifi |
| 55 | + * Seeduino XIAO |
| 56 | + * Feather M0 Basic |
| 57 | + |
| 58 | +Environments tested: |
| 59 | + |
| 60 | + * Arduino IDE |
| 61 | + * Arduino Pro IDE |
| 62 | + * Sloeber |
0 commit comments