C:/usr/src/avr/plotter/motori.c File Reference
#include "configs.h"
#include <inttypes.h>
#include <avr/io.h>
#include <avr/delay.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "usrat.h"
#include "shvars.h"
#include "line.h"
#include "arc.h"
#include "htext.h"
#include "scale.h"
#include "hpgl.h"
#include "motori.h"
Go to the source code of this file.
|
Defines |
#define | MRESET 2 |
| PORTB.2 is motor reset (global).
|
#define | MSLEEP 1 |
| PORTB.1 is motor sleep (global).
|
#define | MENABLE 0 |
| PORTB.0 is motor enable (global).
|
#define | DIR 0 |
| PORTC.0, PORTC.4 X/Y dir.
|
#define | STEP 1 |
| PORTC.1, PORTC.5 X/Y step.
|
#define | MS1 2 |
| PORTC.2, PORTC.6 X/Y microstep select 1.
|
#define | MS2 3 |
| PORTC.3, PORTC.7 X/Y microstep select 2.
|
#define | PENPCM 6 |
| PORTD.6 pen servo control (1.5ms zero).
|
#define | XSUP 0 |
#define | XINF 1 |
#define | YSUP 2 |
#define | YINF 3 |
#define | ZSUP 4 |
#define | ZINF 5 |
#define | sgn(x) ((x)==0?0:((x)<1)?-1:1) |
#define | SEEK0_NULL 0 |
#define | SEEK0_SEEK 1 |
#define | SEEK0_DONE 0x80 |
Functions |
void | init_io () |
| Only initialize port directions and pullups.
|
void | timer0_init () |
void | timer2_init () |
void | motori_init () |
| Initialize motor controllers: wake up, enable, reset and wait 100ms.
|
void | motori_enable (uint8_t enable) |
void | step (int8_t xdir, int8_t ydir) |
void | set_acceleration (ACCEL_MODE accel_mode, uint8_t steep) |
double | calc_angle (int16_t x2, int16_t y2) |
void | pen_control (uint8_t down) |
void | plotter_init () |
void | do_stuff () |
int | main () |
void | SIG_OUTPUT_COMPARE0A (void) |
void | SIG_OVERFLOW2 (void) |
| Timer 2 Overflow Interrupt controls the pen-lifting servo.
|
Variables |
volatile int16_t | motor_pace = MOTOR_PACE_SLOW |
| current motor pace, to be loaded to OCR0A
|
volatile int16_t | motor_pace_goal |
| end speed ramp when motor_pace reaches this
|
volatile uint8_t | motor_accel_ctr = 0 |
| step counter for ramping
|
volatile int8_t | motor_accel = 0 |
| signed, speed ramp direction -1 -> speed up, 1 -> slow down
|
volatile int16_t | accel_strokesteps |
| length of current line in motor steps
|
volatile int16_t | accel_decelthresh |
| at this step start slowing down
|
volatile uint8_t | pen_status = 255 |
| pen status: 0 = up
|
volatile uint8_t | pen_relax = 255 |
volatile uint8_t | pen_pulse_counter = 0 |
| used for servo control
|
double | alpha |
double | last_alpha |
double | alpha_delta |
| may be used if SLOW_QUALITY
|
volatile uint8_t | seeking0 |
| state of seeking home position
|
Detailed Description
This is the main module of Motöri the Plotter firmware. Basic I/O, initialization, interrupt handlers and main program loop are here.
For the main loop see do_stuff()
- Author:
- Viacheslav Slavinsky
Definition in file motori.c.
Define Documentation
PORTC.0, PORTC.4 X/Y dir.
Definition at line 69 of file motori.c.
PORTB.0 is motor enable (global).
Definition at line 67 of file motori.c.
PORTB.2 is motor reset (global).
Definition at line 65 of file motori.c.
PORTC.2, PORTC.6 X/Y microstep select 1.
Definition at line 71 of file motori.c.
PORTC.3, PORTC.7 X/Y microstep select 2.
Definition at line 72 of file motori.c.
PORTB.1 is motor sleep (global).
Definition at line 66 of file motori.c.
PORTD.6 pen servo control (1.5ms zero).
PORTA
Definition at line 74 of file motori.c.
#define sgn |
( |
x |
|
) |
((x)==0?0:((x)<1)?-1:1) |
PORTC.1, PORTC.5 X/Y step.
Definition at line 70 of file motori.c.
Function Documentation
double calc_angle |
( |
int16_t |
x2, |
|
|
int16_t |
y2 | |
|
) |
| | |
Main loop routine.
Could be re-implemented as a state machine as complexity increases. So far there are only 3 states:
- Default: receive uart data, pass it to scanner and handle commands
- Arc tesselation: happens when an arc is being drawn
- Initialization: waits for the head to get home before doing a complete reset
Definition at line 250 of file motori.c.
Only initialize port directions and pullups.
Definition at line 108 of file motori.c.
void motori_enable |
( |
uint8_t |
enable |
) |
|
Enable motors
- Parameters:
-
| enable | true if motors should be enabled |
Definition at line 149 of file motori.c.
Initialize motor controllers: wake up, enable, reset and wait 100ms.
Definition at line 139 of file motori.c.
void pen_control |
( |
uint8_t |
down |
) |
|
Controls the pen position. Both servo and solenoid actuators. Causes immediate delay to allow for the pen to settle.
- Parameters:
-
| down | true if pen should be down, 0 if raised |
Definition at line 207 of file motori.c.
Initialize plotter state. Move to home position, then reset everything, including motors and timers. Reset user scale and translation, raise the pen.
Definition at line 225 of file motori.c.
void set_acceleration |
( |
ACCEL_MODE |
accel_mode, |
|
|
uint8_t |
steep | |
|
) |
| | |
Set motor acceleration profile.
Since the motors are not equal, speed values depend on the prevalent moving axis.
- Parameters:
-
| accel_mode | acceleration mode |
| steep | true if Y axis is the main axis. |
- See also:
- move_is_steep()
Definition at line 169 of file motori.c.
void SIG_OUTPUT_COMPARE0A |
( |
void |
|
) |
|
Timer 0 compare match handler. The motion is here.
Every time when TCNT0 matches the OCR0A, which corresponds to the currently set motor pace, this handler is invoked. movestep() calls step(), where the actual motor commanding impulses are formed.
Definition at line 389 of file motori.c.
void SIG_OVERFLOW2 |
( |
void |
|
) |
|
Timer 2 Overflow Interrupt controls the pen-lifting servo.
Definition at line 426 of file motori.c.
void step |
( |
int8_t |
xdir, |
|
|
int8_t |
ydir | |
|
) |
| | |
Issue the actual step commands to stepper controllers.
- Parameters:
-
| xdir,ydir | Direction +1/-1, 0 == stand still |
Definition at line 160 of file motori.c.
Initialize Timer 2. Timer2 is used to control the pen-lifting servo.
- See also:
- SIG_OVERFLOW2
Definition at line 132 of file motori.c.
Variable Documentation
at this step start slowing down
Definition at line 91 of file motori.c.
length of current line in motor steps
Definition at line 90 of file motori.c.
may be used if SLOW_QUALITY
Definition at line 100 of file motori.c.
signed, speed ramp direction -1 -> speed up, 1 -> slow down
Definition at line 88 of file motori.c.
step counter for ramping
Definition at line 87 of file motori.c.
current motor pace, to be loaded to OCR0A
Definition at line 85 of file motori.c.
end speed ramp when motor_pace reaches this
Definition at line 86 of file motori.c.
used for servo control
Definition at line 98 of file motori.c.
pen status: 0 = up
Definition at line 95 of file motori.c.
state of seeking home position
Definition at line 105 of file motori.c.