-
Notifications
You must be signed in to change notification settings - Fork 65
SAMD21: Customizing
µCNC for SAMD21 can be configured/customized to fit different SAMD21 powered boards other than Arduino Zero and M0
Jump to section
µCNC for SAMD21 can be customized either using the Web Config Tool or by manually modifing the source code files. For the latest method most configurations and pin assigning should be done in the corresponding boardmap file inside the uCNC/src/hal/boards/samd21/ directory and then the respective board file.
This is similar to the general customization instructions
All input pins can have a weak pull-up activated to drive them high if unconnected. This is similar to the general customization instructions
All pins all repeatedly read by a soft polling routine. But for special function pins an interrupt driven event to force a reading and respective action can be also activated. This causes the response to be immediate and not depend on the pin reading routine cycle. SAMD21 has 16 External Interrupts that can be assign to one input of a single port. For example External Interrupt 0 can only be assigned to pin 0 of one of the Ports (A or B or C or ...). For Arduino M0 the pin mapping can be checked here.
This is similar to the general customization instructions
This is similar to the general customization instructions
To configure the pwm clock, the used channel, alternative functions mux and timer must be supplied. To find the used channel register, mux and timer we must check the MCU datasheet. Looking at the pin mapping shown above for SAMD21 and knowing that we are going to use pin A16 has the spindle pwm control we can see that the pwm on that pin is generated via Timer2 - Channel 0.
/Setup PWM
#define PWM0_BIT 16 //assigns PWM0 pin
#define PWM0_PORT A //assigns PWM0 port
#define PWM0_CHANNEL 0 //assigns PWM0 channel
#define PWM0_TIMER 2 //assigns PWM0 timer
#define PWM0_MUX E //assigns PWM0 mux
Although not used anywhere inside µCNC reading analog pins is possible. Beside configuring the pin like an input pin, two more definitions are needed to configure the SAMD21 analog reading. These are setting the channel and the desired prescaller for the conversion. For example on SAMD21 AIN5 (Analog channel 5) is on pin A5. To configure it as µCNC's ANALOG0 input add the following code to the boardmap file:
#define ANALOG0_BIT 5
#define ANALOG0_PORT A
#define ANALOG0_CHANNEL 5 //SAMD21 channel 0
To make a read just do
uint8_t value = mcu_get_analog(ANALOG0);
This is similar to the general customization instructions
Systick is used as the RTC Timer so the RTC_Timer configuration as not effect.
This is similar to the general customization instructions
µCNC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. µCNC is distributed WITHOUT ANY WARRANTY.
Also without the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
µCNC Wiki
- Home
- Basic user guide
- Porting µCNC and adding custom HAL
- Customizing the HAL file
- Adding custom Tools and Modules to µCNC
- FAQ
µCNC for ALL MCU
µCNC for AVR
µCNC for STM32F1 and STM32F4
µCNC for SAMD21
µCNC for ESP8266
µCNC for ESP32
µCNC for NXP LPC176x
µCNC for NXP RP2040