Compare commits
1 Commits
master
...
33af2cfb49
| Author | SHA1 | Date | |
|---|---|---|---|
| 33af2cfb49 |
@@ -1,6 +0,0 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void adress_selector_init_gpio();
|
||||
uint8_t read_address();
|
||||
|
||||
extern uint8_t dmx_address;
|
||||
19
Inc/mapping_table.h
Normal file
19
Inc/mapping_table.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "uart_dmx.h"
|
||||
|
||||
typedef struct{
|
||||
uint16_t tilt;
|
||||
uint8_t endless_rot;
|
||||
} motor_mapping_T;
|
||||
|
||||
typedef struct{
|
||||
motor_mapping_T channels[12];
|
||||
uint8_t automode;
|
||||
} fixture_mapping_T;
|
||||
|
||||
#define AUTOMODE_NO_FUNC_L 0
|
||||
#define AUTOMODE_NO_FUNC_H 4
|
||||
#define AUTOMODE_GOTO_REF_L 5
|
||||
#define AUTOMODE_GOTO_REF_H 9
|
||||
#define AUTOMODE_CLASSIC_L 10
|
||||
#define AUTOMODE_CLASSIC_H 14
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "stm32g0b1xx.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
GPIO_TypeDef* en_port;
|
||||
@@ -12,17 +11,13 @@ typedef struct {
|
||||
uint8_t home_pin;
|
||||
uint8_t homed:1;
|
||||
uint8_t trigger_step:1;
|
||||
int32_t home_position;
|
||||
int32_t pos;
|
||||
int32_t endless_rot_integrator;
|
||||
int16_t pos;
|
||||
int32_t speed;
|
||||
int32_t ramp_to_speed;
|
||||
uint32_t next_step;
|
||||
} stepper_T;
|
||||
|
||||
#define STEPPER_MAX_SPEED 400
|
||||
|
||||
#define STEPPER_STEPS_PER_ROTATION 3200*4
|
||||
#define STEPPER_SPEED_LIMIT 300
|
||||
|
||||
void Timer1_Init(void);
|
||||
void stepper_gpio_init();
|
||||
|
||||
7
Makefile
7
Makefile
@@ -38,7 +38,6 @@ BUILD_DIR = build
|
||||
C_SOURCES = \
|
||||
Src/main.c \
|
||||
Src/uart_dmx.c \
|
||||
Src/address_selector.c \
|
||||
Src/stepper.c \
|
||||
Src/stm32g0xx_it.c \
|
||||
Src/stm32g0xx_hal_msp.c \
|
||||
@@ -115,11 +114,7 @@ AS_DEFS =
|
||||
# C defines
|
||||
C_DEFS = \
|
||||
-DUSE_HAL_DRIVER \
|
||||
-DSTM32G0B1xx \
|
||||
|
||||
ifneq ($(DMX_ADDRESS),)
|
||||
C_DEFS += -DDMX_ADDRESS=$(DMX_ADDRESS)
|
||||
endif
|
||||
-DSTM32G0B1xx
|
||||
|
||||
|
||||
# AS includes
|
||||
|
||||
92
README.md
92
README.md
@@ -1,89 +1,25 @@
|
||||
# Parafraktor
|
||||
## Hardware Connections
|
||||
- Motor1: P30 (M1)
|
||||
- Motor2: P53 (M2)
|
||||
- Motor3: P46 (M3A)
|
||||
- Motor4: P70 (M4)
|
||||
- Motor5: P31 (M5)
|
||||
- Motor6: P71 (M7)
|
||||
- 24V: Power + -
|
||||
- TTL-level DMX: FWS
|
||||
- Limit switches: EXP2 (optional)
|
||||
- Address selector: EXP1 (optional)
|
||||
- VM/VBB(?) Jumper must be set on every motor driver
|
||||
# Parrafraktor
|
||||
|
||||
## DMX Registers
|
||||
|
||||
Control Motors 1 - 6
|
||||
|
||||
| Offset | Motor | Function | Values | |
|
||||
| ------- | ----- | ------------ | --------- | ------------------------------ |
|
||||
| 1 | 1 | Tilt | 000 - 255 | 8bit Position values can be combined to 16bit value |
|
||||
| 2 | 1 | Tilt fine | 000 - 255 | |
|
||||
| 3 | 1 | Endless Tilt | 000 - 004 | No function |
|
||||
| | | | 005 - 121 | Forward Rotation fast -> slow |
|
||||
| | | | 122 - 132 | Stop |
|
||||
| | | | 133 - 250 | Backward Rotation slow -> fast |
|
||||
| | | | 251 - 255 | No function |
|
||||
| ... | ... | ... | ... | ... |
|
||||
| 16 | 6 | Tilt | | |
|
||||
| 17 | 6 | Tilt fine | | |
|
||||
| 18 | 6 | Endless Tilt | | |
|
||||
|
||||
## Compile, Flash & Debug
|
||||
|
||||
requirements:
|
||||
- for compiling: arm-none-eabi-toolchain, gnu-make, git
|
||||
- for flashing: SEGGER J-Link, JLinkGDBServer (other Debug Probes can be used, see Makefile)
|
||||
|
||||
run gdb-server<br />
|
||||
`./gdb.sh`
|
||||
|
||||
build and flash firmware with static DMX-Address<br />
|
||||
`make program DMX_ADDRESS=99`
|
||||
|
||||
build and flash firmware with address selector on EXP1<br />
|
||||
`make program`
|
||||
|
||||
open serial RTT prints:<br />
|
||||
`telnet localhost 9000`
|
||||
|
||||
open cgdb debugger:<br />
|
||||
`./debug.sh`
|
||||
|
||||
## non-obvious PinOuts
|
||||
|
||||
### DMX/UART/FWS
|
||||
| Pin # | connect to RS485 Transceiver
|
||||
| - | ----------|
|
||||
| 1 | NC |
|
||||
| 2 | DATA-in |
|
||||
| 3 | GND |
|
||||
| 4 | 5V (only connect if not powered by other board) |
|
||||

|
||||
|
||||
|
||||
### Limit Switches/EXP2
|
||||
|Pin #| Switch |Pin #| Switch |
|
||||
| --- | ----------| --- | ----------|
|
||||
| 1 | M1 (PB14) | 2 | M2 (PB13) |
|
||||
| 3 | M3 (PF7) | 4 | M4 (PB12) |
|
||||
| 5 | M5 (PE7) | 6 | M6 (PB11) |
|
||||
| 7 | | 8 | |
|
||||
| 9 | GND | 10 | |
|
||||
|
||||
### Address Selector/EXP1
|
||||
|Pin #| Switch |Pin #| Switch |
|
||||
| --- | ----------| --- | ----------|
|
||||
| 1 | | 2 | |
|
||||
| 3 | | 4 | |
|
||||
| 5 | | 6 | |
|
||||
| 7 | | 8 | |
|
||||
| 9 | GND | 10 | 5V |
|
||||
| Channel | Function | Values | |
|
||||
| ------- | ------------ | --------- | ------------------------------ |
|
||||
| 1 + i | Tilt | | |
|
||||
| 2 + i | Tilt fine | | |
|
||||
| 3 + i | Endless Tilt | 000 - 005 | No function |
|
||||
| | | 006 - 126 | Forward Rotation fast -> slow |
|
||||
| | | 127 - 128 | Stop |
|
||||
| | | 129 - 255 | Backward Rotation slow -> fast |
|
||||
| 36 | Auto Mode | 000 - 004 | No function |
|
||||
| | | 005 - 010 | Go to Reference |
|
||||
| | | 015 - 020 | Classic Mode |
|
||||
|
||||
|
||||
## Hardware
|
||||
|
||||
- BIGTREETECH Manta M8P v1.1
|
||||
- BIGTREETECH Manta M8P
|
||||
- https://github.com/bigtreetech/Manta-M8P/tree/master/V1.0_V1.1/Hardware
|
||||
- https://github.com/bigtreetech/Manta-M8P
|
||||
- https://bttwiki.com/M8P.html#product-profile
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
#include "stm32g0b1xx.h"
|
||||
#include <stdio.h>
|
||||
|
||||
uint8_t dmx_address;
|
||||
|
||||
void adress_selector_init_gpio(){
|
||||
RCC->IOPENR |= RCC_IOPENR_GPIOEEN;
|
||||
RCC->IOPENR |= RCC_IOPENR_GPIOBEN;
|
||||
|
||||
GPIOE->MODER &= ~(0x3 << (9 * 2));
|
||||
GPIOE->MODER &= ~(0x3 << (10 * 2));
|
||||
GPIOE->MODER &= ~(0x3 << (11 * 2));
|
||||
GPIOE->MODER &= ~(0x3 << (12 * 2));
|
||||
GPIOE->MODER &= ~(0x3 << (13 * 2));
|
||||
GPIOE->MODER &= ~(0x3 << (14 * 2));
|
||||
GPIOE->MODER &= ~(0x3 << (15 * 2));
|
||||
GPIOB->MODER &= ~(0x3 << (10 * 2)); // B10
|
||||
|
||||
GPIOE->PUPDR &= ~(0x3 << (9 * 2));
|
||||
GPIOE->PUPDR |= (0x1 << (9 * 2));
|
||||
|
||||
GPIOE->PUPDR &= ~(0x3 << (10 * 2));
|
||||
GPIOE->PUPDR |= (0x1 << (10 * 2));
|
||||
|
||||
GPIOE->PUPDR &= ~(0x3 << (11 * 2));
|
||||
GPIOE->PUPDR |= (0x1 << (11 * 2));
|
||||
|
||||
GPIOE->PUPDR &= ~(0x3 << (12 * 2));
|
||||
GPIOE->PUPDR |= (0x1 << (12 * 2));
|
||||
|
||||
GPIOE->PUPDR |= (0x1 << (13 * 2));
|
||||
GPIOE->PUPDR &= ~(0x3 << (13 * 2));
|
||||
|
||||
GPIOE->PUPDR |= (0x1 << (14 * 2));
|
||||
GPIOE->PUPDR &= ~(0x3 << (14 * 2));
|
||||
|
||||
GPIOE->PUPDR |= (0x1 << (15 * 2));
|
||||
GPIOE->PUPDR &= ~(0x3 << (15 * 2));
|
||||
|
||||
GPIOB->PUPDR &= ~(0x3 << (10 * 2)); // B10
|
||||
GPIOB->PUPDR |= (0x1 << (10 * 2));
|
||||
}
|
||||
|
||||
uint8_t read_address(){
|
||||
#ifndef DMX_ADDRESS
|
||||
uint16_t address = ((GPIOE->IDR >> 9)&0x7F) | (GPIOB->IDR & (1<<10))>>3;
|
||||
printf("read address: %d = 0x%x\n", address, address);
|
||||
#else
|
||||
uint16_t address = DMX_ADDRESS;
|
||||
printf("static address: %d\n", address);
|
||||
#endif
|
||||
return address;
|
||||
}
|
||||
@@ -30,7 +30,6 @@
|
||||
|
||||
#include "uart_dmx.h"
|
||||
#include "stepper.h"
|
||||
#include "address_selector.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -57,7 +56,6 @@
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
@@ -101,9 +99,6 @@ int main(void)
|
||||
/* USER CODE BEGIN 2 */
|
||||
init_UART1_dma();
|
||||
stepper_gpio_init();
|
||||
adress_selector_init_gpio();
|
||||
dmx_address = read_address();
|
||||
|
||||
Timer1_Init();
|
||||
/* USER CODE END 2 */
|
||||
|
||||
@@ -117,7 +112,6 @@ int main(void)
|
||||
// printf("0x%02X ", rxBuffer[i]);
|
||||
//printf("\n");
|
||||
SEGGER_SYSVIEW_OnIdle();
|
||||
//read_address();
|
||||
//if(cnt++ >= 256-rxBuffer[1]){
|
||||
// cnt = 0;
|
||||
// GPIOE->ODR ^= GPIO_ODR_OD2;
|
||||
|
||||
100
Src/stepper.c
100
Src/stepper.c
@@ -6,16 +6,11 @@
|
||||
|
||||
#include "SEGGER_SYSVIEW.h"
|
||||
#include "uart_dmx.h"
|
||||
#include "address_selector.h"
|
||||
#include "mapping_table.h"
|
||||
|
||||
stepper_T steppers[] = {
|
||||
{.en_port=GPIOC, .en_pin=11, .dir_port=GPIOB, .dir_pin=4, .step_port=GPIOE, .step_pin=2, .home_port=GPIOB, .home_pin=14, .home_position=0, .homed = 0},
|
||||
{.en_port=GPIOB, .en_pin=3, .dir_port=GPIOF, .dir_pin=11, .step_port=GPIOF, .step_pin=12, .home_port=GPIOB, .home_pin=13, .home_position=0, .homed = 0},
|
||||
{.en_port=GPIOF, .en_pin=10, .dir_port=GPIOD, .dir_pin=6, .step_port=GPIOD, .step_pin=7, .home_port=GPIOF, .home_pin=7, .home_position=0, .homed = 0},
|
||||
{.en_port=GPIOD, .en_pin=5, .dir_port=GPIOD, .dir_pin=2, .step_port=GPIOD, .step_pin=3, .home_port=GPIOB, .home_pin=12, .home_position=0, .homed = 0},
|
||||
{.en_port=GPIOD, .en_pin=1, .dir_port=GPIOC, .dir_pin=8, .step_port=GPIOC, .step_pin=9, .home_port=GPIOE, .home_pin=7, .home_position=0, .homed = 0},
|
||||
{.en_port=GPIOD, .en_pin=15, .dir_port=GPIOD, .dir_pin=9, .step_port=GPIOD, .step_pin=11, .home_port=GPIOB, .home_pin=11, .home_position=0, .homed = 0},
|
||||
//{.en_port=GPIOA, .en_pin=15, .dir_port=GPIOA, .dir_pin=14, .step_port=GPIOA, .step_pin=10, .home_port=GPIOB, .home_pin=11, .home_position=0, .homed = 1},
|
||||
{.en_port=GPIOC, .en_pin=11, .dir_port=GPIOB, .dir_pin=4, .step_port=GPIOE, .step_pin=2, .home_port=GPIOF, .home_pin=3},
|
||||
{.en_port=GPIOB, .en_pin=3, .dir_port=GPIOF, .dir_pin=11, .step_port=GPIOF, .step_pin=12, .home_port=GPIOF, .home_pin=4}
|
||||
};
|
||||
|
||||
void set_pins(stepper_T* stp){
|
||||
@@ -35,24 +30,23 @@ void set_pins(stepper_T* stp){
|
||||
|
||||
// home switch
|
||||
stp->home_port->MODER &= ~(0x3 << (stp->home_pin * 2));
|
||||
stp->home_port->PUPDR &= ~(0x3 << (stp->home_pin * 2));
|
||||
stp->home_port->PUPDR |= (0x1 << (stp->home_pin * 2));
|
||||
|
||||
// make shure stepper is enabled (active low)
|
||||
stp->en_port->BSRR |= (0x1 << (stp->en_pin + 16));
|
||||
}
|
||||
|
||||
void stepper_gpio_init(){
|
||||
RCC->IOPENR |= RCC_IOPENR_GPIOAEN;
|
||||
RCC->IOPENR |= RCC_IOPENR_GPIOBEN;
|
||||
RCC->IOPENR |= RCC_IOPENR_GPIOCEN;
|
||||
RCC->IOPENR |= RCC_IOPENR_GPIODEN;
|
||||
RCC->IOPENR |= RCC_IOPENR_GPIOEEN;
|
||||
RCC->IOPENR |= RCC_IOPENR_GPIOFEN;
|
||||
|
||||
for(uint8_t i=0; i<(sizeof(steppers)/sizeof(stepper_T)); i++){
|
||||
set_pins(&steppers[i]);
|
||||
}
|
||||
|
||||
steppers[0].homed = 1;
|
||||
steppers[1].homed = 1;
|
||||
}
|
||||
|
||||
void Timer1_Init(void) {
|
||||
@@ -85,7 +79,6 @@ void TIM1_BRK_UP_TRG_COM_IRQHandler(void) {
|
||||
|
||||
void do_steps(){
|
||||
static uint32_t timer = 0;
|
||||
int16_t rotation_speed = 0;
|
||||
timer++;
|
||||
|
||||
for(uint8_t i=0; i<(sizeof(steppers)/sizeof(stepper_T)); i++){
|
||||
@@ -100,10 +93,10 @@ void do_steps(){
|
||||
steppers[i].speed--;
|
||||
|
||||
/* limit max speed */
|
||||
if(steppers[i].speed >= STEPPER_MAX_SPEED)
|
||||
steppers[i].speed=STEPPER_MAX_SPEED;
|
||||
if(steppers[i].speed <= -STEPPER_MAX_SPEED)
|
||||
steppers[i].speed=-STEPPER_MAX_SPEED;
|
||||
if(steppers[i].speed >= STEPPER_SPEED_LIMIT)
|
||||
steppers[i].speed=STEPPER_SPEED_LIMIT;
|
||||
if(steppers[i].speed <= -STEPPER_SPEED_LIMIT)
|
||||
steppers[i].speed=-STEPPER_SPEED_LIMIT;
|
||||
|
||||
/* get direction from sign */
|
||||
if(steppers[i].speed>0)
|
||||
@@ -133,92 +126,29 @@ void do_steps(){
|
||||
steppers[i].next_step = timer + 1;
|
||||
}
|
||||
|
||||
//printf("motor[%d]: pos %ld\trot: %ld\tspeed %ld\n", i, steppers[i].pos, steppers[i].endless_rot_integrator, steppers[i].speed);
|
||||
//printf("rotation speed: %d\n", rotation_speed);
|
||||
printf("pos %d\tspeed %d\n", steppers[i].pos, steppers[i].speed);
|
||||
}
|
||||
|
||||
if(steppers[i].homed){
|
||||
static uint16_t old_ramp_to_speed;
|
||||
old_ramp_to_speed = steppers[i].ramp_to_speed;
|
||||
|
||||
uint8_t raw_endless = rxBuffer[3*i + dmx_address + 2];
|
||||
|
||||
/* deadzone on top and bottom */
|
||||
if(raw_endless >= 5 && raw_endless <= 250) {
|
||||
rotation_speed = raw_endless - 127;
|
||||
|
||||
/* dead zone in the middle */
|
||||
if(rotation_speed >= 5)
|
||||
rotation_speed -= 5;
|
||||
else if(rotation_speed <= -5)
|
||||
rotation_speed += 5;
|
||||
else
|
||||
rotation_speed = 0;
|
||||
}
|
||||
else{
|
||||
rotation_speed = 0;
|
||||
}
|
||||
|
||||
if(steppers[i].pos == STEPPER_STEPS_PER_ROTATION+1){
|
||||
steppers[i].pos = 1;
|
||||
}
|
||||
if(steppers[i].pos == -1){
|
||||
steppers[i].pos = STEPPER_STEPS_PER_ROTATION-1;
|
||||
}
|
||||
|
||||
///* handle endless rotation offset and wraparound */
|
||||
//if(rotation_speed){
|
||||
// steppers[i].endless_rot_integrator += rotation_speed;
|
||||
// if(steppers[i].endless_rot_integrator >= STEPPER_STEPS_PER_ROTATION)
|
||||
// {
|
||||
// steppers[i].endless_rot_integrator -= STEPPER_STEPS_PER_ROTATION;
|
||||
// steppers[i].pos -= STEPPER_STEPS_PER_ROTATION;
|
||||
// }
|
||||
// else if(steppers[i].endless_rot_integrator <= 0)
|
||||
// {
|
||||
// steppers[i].endless_rot_integrator += STEPPER_STEPS_PER_ROTATION;
|
||||
// steppers[i].pos += STEPPER_STEPS_PER_ROTATION;
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
// steppers[i].endless_rot_integrator = 0;
|
||||
|
||||
if(rotation_speed){
|
||||
steppers[i].ramp_to_speed = rotation_speed;
|
||||
}
|
||||
else{
|
||||
int32_t swapped_val = rxBuffer[3*i + dmx_address]<<8 | (rxBuffer[3*i+dmx_address+1]&0xFF);
|
||||
//swapped_val += steppers[i].endless_rot_integrator;
|
||||
int32_t scaled_steps = swapped_val * STEPPER_STEPS_PER_ROTATION / UINT16_MAX;
|
||||
steppers[i].ramp_to_speed = scaled_steps - steppers[i].pos;
|
||||
//static int cnt = 0;
|
||||
//if(i==5 && ++cnt==10000){
|
||||
// printf("swapped_val[%d]: %d\n", i, swapped_val);
|
||||
// cnt=0;
|
||||
//}
|
||||
}
|
||||
motor_mapping_T* tmp = &(((fixture_mapping_T*)&rxBuffer[1])->channels[i]);
|
||||
steppers[i].ramp_to_speed = tmp->tilt - steppers[i].pos;
|
||||
|
||||
if(old_ramp_to_speed == 0 && steppers[i].ramp_to_speed != 0)
|
||||
steppers[i].trigger_step = 1;
|
||||
}
|
||||
else{
|
||||
if(~(steppers[i].home_port->IDR) & (1 << steppers[i].home_pin)){
|
||||
steppers[i].pos = steppers[i].home_position;
|
||||
steppers[i].pos = 0;
|
||||
steppers[i].homed = 1;
|
||||
steppers[i].speed = 0;
|
||||
steppers[i].ramp_to_speed = 0;
|
||||
printf("homed %d\n", i);
|
||||
}
|
||||
else if(steppers[i].pos == 2*STEPPER_STEPS_PER_ROTATION){
|
||||
steppers[i].pos = 0;
|
||||
steppers[i].homed = 1;
|
||||
steppers[i].speed = 0;
|
||||
steppers[i].ramp_to_speed = 0;
|
||||
printf("cant home %d, setting 0 now\n", i);
|
||||
}
|
||||
else{
|
||||
if(steppers[i].ramp_to_speed == 0){
|
||||
steppers[i].ramp_to_speed=80;
|
||||
steppers[i].ramp_to_speed=10;
|
||||
steppers[i].trigger_step = 1; // trigger first step
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
-mthumb
|
||||
-DUSE_HAL_DRIVER
|
||||
-DSTM32G0B1xx
|
||||
-DDMX_ADDRESS=99
|
||||
-IInc
|
||||
-IDrivers/STM32G0xx_HAL_Driver/Inc
|
||||
-IDrivers/STM32G0xx_HAL_Driver/Inc/Legacy
|
||||
|
||||
Reference in New Issue
Block a user