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

#define DIR   0

PORTC.0, PORTC.4 X/Y dir.

Definition at line 69 of file motori.c.

#define MENABLE   0

PORTB.0 is motor enable (global).

Definition at line 67 of file motori.c.

#define MRESET   2

PORTB.2 is motor reset (global).

Definition at line 65 of file motori.c.

#define MS1   2

PORTC.2, PORTC.6 X/Y microstep select 1.

Definition at line 71 of file motori.c.

#define MS2   3

PORTC.3, PORTC.7 X/Y microstep select 2.

Definition at line 72 of file motori.c.

#define MSLEEP   1

PORTB.1 is motor sleep (global).

Definition at line 66 of file motori.c.

#define PENPCM   6

PORTD.6 pen servo control (1.5ms zero).

PORTA

Definition at line 74 of file motori.c.

#define SEEK0_DONE   0x80

Definition at line 104 of file motori.c.

#define SEEK0_NULL   0

Definition at line 102 of file motori.c.

#define SEEK0_SEEK   1

Definition at line 103 of file motori.c.

#define sgn (  )     ((x)==0?0:((x)<1)?-1:1)

Definition at line 93 of file motori.c.

#define STEP   1

PORTC.1, PORTC.5 X/Y step.

Definition at line 70 of file motori.c.

#define XINF   1

Definition at line 78 of file motori.c.

#define XSUP   0

Definition at line 77 of file motori.c.

#define YINF   3

Definition at line 80 of file motori.c.

#define YSUP   2

Definition at line 79 of file motori.c.

#define ZINF   5

Definition at line 82 of file motori.c.

#define ZSUP   4

Definition at line 81 of file motori.c.


Function Documentation

double calc_angle ( int16_t  x2,
int16_t  y2 
)

Definition at line 197 of file motori.c.

void do_stuff (  ) 

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.

void init_io (  ) 

Only initialize port directions and pullups.

Definition at line 108 of file motori.c.

int main (  ) 

Definition at line 355 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.

void motori_init (  ) 

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.

void plotter_init (  ) 

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.

void timer0_init (  ) 

Initialize Timer 0. Timer0 is used for stepper control and speed ramping.

See also:
SIG_OUTPUT_COMPARE0A

Definition at line 122 of file motori.c.

void timer2_init (  ) 

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

volatile int16_t accel_decelthresh

at this step start slowing down

Definition at line 91 of file motori.c.

volatile int16_t accel_strokesteps

length of current line in motor steps

Definition at line 90 of file motori.c.

double alpha

Definition at line 100 of file motori.c.

double alpha_delta

may be used if SLOW_QUALITY

Definition at line 100 of file motori.c.

double last_alpha

Definition at line 100 of file motori.c.

volatile int8_t motor_accel = 0

signed, speed ramp direction -1 -> speed up, 1 -> slow down

Definition at line 88 of file motori.c.

volatile uint8_t motor_accel_ctr = 0

step counter for ramping

Definition at line 87 of file motori.c.

volatile int16_t motor_pace = MOTOR_PACE_SLOW

current motor pace, to be loaded to OCR0A

Definition at line 85 of file motori.c.

volatile int16_t motor_pace_goal

end speed ramp when motor_pace reaches this

Definition at line 86 of file motori.c.

volatile uint8_t pen_pulse_counter = 0

used for servo control

Definition at line 98 of file motori.c.

volatile uint8_t pen_relax = 255

Definition at line 96 of file motori.c.

volatile uint8_t pen_status = 255

pen status: 0 = up

Definition at line 95 of file motori.c.

volatile uint8_t seeking0

state of seeking home position

Definition at line 105 of file motori.c.


Generated on Sat Jul 4 05:27:39 2009 for motori by  doxygen 1.5.9