NXP LPC176x: Customizing - Paciente8159/uCNC GitHub Wiki

µCNC for LPC176x can be configured/customized to fit different LPC176x powered boards other than Panucatt Re-Arm board

Jump to section

Customizing boardmap

µCNC for LPC176x 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/LPC176x/ directory and then the respective board file.

µCNC for LPC176x is like for AVR but takes an extra step if you are using a board with a different LPC176x flavor other then the LPC1768 used in the Panucatt Re-Arm board. It's necessary to create the boiler-plate project to fit your particular MCU. The Re-Arm source code is a good example on how to implement this. It's mostly written in plain C and it's a mix of bare-metal and HAL middleware. The only stack used is the tinyUSB library for the USB VCP port that works on a wide range of MCU's. The pinout configuration follows (almost all of) the Re-Arm for RAMPS pinout.

Configure IO pin

An HAL pin need to be mapped to a physical IO pin. The way this is done is by defining the IO PORT and BIT. This must be performed for every used pin This is similar to the general customization instructions

//set pin 2.1 as STEP0 (output pin) 
#define STEP0_BIT 1	 // assigns STEP0 pin
#define STEP0_PORT 2 // assigns STEP0 port
//set pin 1.24 as LIMIT_X (input pin) 
#define LIMIT_X_BIT 24 // assigns LIMIT_X pin
#define LIMIT_X_PORT 1 // assigns LIMIT_X port
//set pin 2.4 as PWM0 (pwm output pin) 
#define PWM1_BIT 4	// assigns PWM1 pin
#define PWM1_PORT 2 // assigns PWM1 pin

Input pin options

Weak input pull-ups

All input pins can have a weak pull-up activated to drive them high if unconnected. This is similar to the general customization instructions

External interrupt feature

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. LPC176x has 2 Interrupt on change Ports (0 and 2) that can enabled. For Re-Arm the pin mapping can be checked here.

Re-Arm pin mapping

This is similar to the general customization instructions

Configure communications

This is similar to the general customization instructions

Configure pwm output

To configure the pwm ouput, the used channel be supplied (besides the normal pin definition). To find the used channel register and timer we must check the MCU datasheet. Looking at the pin mapping for Re-Arm and the datasheet and knowing that we are going to use pin 2.5 has the spindle pwm control we can see that the pwm on that pin uses Channel 6 of the PWM generator.

/Setup PWM 
#define PWM0_BIT 5	//assigns PWM0 pin 
#define PWM0_PORT 2 //assigns PWM0 pin 
#define PWM0_CHANNEL 6 

Configure analog channel

Not implemented yet.

Configure step generator timer

This is similar to the general customization instructions

Configure servo pins

This is similar to the general customization instructions