Porting µCNC and adding custom HAL - Paciente8159/uCNC GitHub Wiki
Jump to section
UPDATED VERSION
To make it easier to maintain the relevant information about some parts of the system are kept inside the source code, in several README files across the project. The latest version of this information is located here.
The information bellow might not be up to date:
µCNC HAL (Hardware Abstraction Layer)
µCNC has several HAL dimensions. The first is the microcontroller HAL. It provides the abstraction layer needed to use all the core functionalities in any microcontroller/PC board. The second one is the kinematics HAL that translates how the machine converts linear actuators/steps in to cartesian space coordinates and the mechanical motions of the machines. Version 1.3.0 came with a tool HAL were you can add and configure multiple tools used in your CNC. Apart from these 3 HAL there are a couple of modules that allow to configure encoders, PID and custom link all systems together. In this page we will be looking at the different possibilities and configurations for all the HAL's and modules.
The microcontroller HAL
For the updated microcontroller HAL go here
The kinematics HAL
For the updated kinematics HAL go here
The tool HAL
For the updated tool HAL go here
If you want to know more about the available tools read this
The new HAL config file
This new HAL config file that was introduced in version 1.2.0 is manages the way the generic (and in some particular cases the special pins too) connect to the desired functions or modules. For example:
- It's possible to assign the spindle PWM and dir pins any PWM and DOUT pins
- It's possible add a close loop PID feedback from an ANALOG input to a PWM output (for example spindle closed loop speed control)
- It's possible to assign any encoder module to any DIN pins
- It's possible to assign any PID module to any PWM pins
Some examples exist inside the cnc_hal_config.h file of possible configurations. These may change in a near future since this is still a feature in development:
/**
* To use the PID controller 2 definitions are needed
* PIDx_DELTA() -> sets the function that gets the error between the setpoint and the current value for x PID controller
* PIDx_OUTPUT(X) -> sets the output after calculating the PID corrected value for x PID controller
*
* For example
*
* #define PID0_DELTA() (my_setpoint - mcu_get_analog(ANA0))
* #define PID0_OUTPUT(X) (mcu_set_pwm(PWM0, X))
*
* An optional configuration is the sampling rate of the PID update. By default the sampling rate is 125Hz.
* To reduce the sampling rate a 125/PIDx_FREQ_DIV can be defined between 1 (125Hz) and 250 (0.5Hz)
*
* */
//here is an example on how to add an PID controller to the spindle
//this exemple assumes that the spindle speed is feedback via an analog pin
//reference to io_get_spindle defined in io_control
// extern uint8_t io_get_spindle(void);
// #define SPINDLE_SPEED ANALOG0
// #define PID0_DELTA() (io_get_spindle() - mcu_get_analog(SPINDLE_SPEED))
// #define PID0_OUTPUT(X) (mcu_set_pwm(SPINDLE_PWM, X))
// //optional
// #define PID0_FREQ_DIV 50
/**
* To use the encoder counter 2 definitions are needed
* ENC0_PULSE -> must be set to an input PIN with interrupt on change enabled capabilities
* ENC0_DIR -> a regular input PIN that detects the direction of the encoding step
* */
//#define ENC0_PULSE DIN0
//#define ENC0_DIR DIN8