00001
00024
#include <ioavr.h>
00025
#include <inavr.h>
00026
#include <stdlib.h>
00027
#include "global.h"
00028
#include "uart.h"
00029
#include "sm_driver.h"
00030
#include "speed_cntr.h"
00031
00033 struct GLOBAL_FLAGS status = {
FALSE,
FALSE, 0};
00034
00035
void ShowHelp(
void);
00036
void ShowData(
int position,
int acceleration,
int deceleration,
int speed,
int steps);
00037
00042 void Init(
void)
00043 {
00044
00045
sm_driver_Init_IO();
00046
00047
InitUART();
00048
00049
00050
sm_driver_StepOutput(0);
00051
00052
00053
speed_cntr_Init_Timer1();
00054
00055 __enable_interrupt();
00056 }
00057
00062 void main(
void)
00063 {
00064
00065
int steps = 1000;
00066
00067
int acceleration = 100;
00068
00069
int deceleration = 100;
00070
00071
int speed = 800;
00072
00073
char okCmd =
FALSE;
00074
00075
Init();
00076
00077
00078
uart_SendString(
"\n\r");
00079
ShowHelp();
00080
ShowData(
stepPosition, acceleration, deceleration, speed, steps);
00081
00082
while(1) {
00083
00084
if(
status.
cmd ==
TRUE){
00085
if(
UART_RxBuffer[0] ==
'm'){
00086
00087
if(
UART_RxBuffer[1] ==
' '){
00088
00089 steps = atoi((
char const *)
UART_RxBuffer+2);
00090
speed_cntr_Move(steps, acceleration, deceleration, speed);
00091 okCmd =
TRUE;
00092
uart_SendString(
"\n\r ");
00093 }
00094
else if(
UART_RxBuffer[1] ==
'o'){
00095
if(
UART_RxBuffer[2] ==
'v'){
00096
if(
UART_RxBuffer[3] ==
'e'){
00097
00098
if(
UART_RxBuffer[4] ==
' '){
00099
int i = 6;
00100 steps = atoi((
char const *)
UART_RxBuffer+5);
00101
while((
UART_RxBuffer[i] !=
' ') && (
UART_RxBuffer[i] != 13)) i++;
00102 i++;
00103 acceleration = atoi((
char const *)
UART_RxBuffer+i);
00104
while((
UART_RxBuffer[i] !=
' ') && (
UART_RxBuffer[i] != 13)) i++;
00105 i++;
00106 deceleration = atoi((
char const *)
UART_RxBuffer+i);
00107
while((
UART_RxBuffer[i] !=
' ') && (
UART_RxBuffer[i] != 13)) i++;
00108 i++;
00109 speed = atoi((
char const *)
UART_RxBuffer+i);
00110
speed_cntr_Move(steps, acceleration, deceleration, speed);
00111 okCmd =
TRUE;
00112
uart_SendString(
"\n\r ");
00113 }
00114 }
00115 }
00116 }
00117 }
00118
else if(
UART_RxBuffer[0] ==
'a'){
00119
00120
if(
UART_RxBuffer[1] ==
' '){
00121 acceleration = atoi((
char const *)
UART_RxBuffer+2);
00122 okCmd =
TRUE;
00123 }
00124 }
00125
else if(
UART_RxBuffer[0] ==
'd'){
00126
00127
if(
UART_RxBuffer[1] ==
' '){
00128 deceleration = atoi((
char const *)
UART_RxBuffer+2);
00129 okCmd =
TRUE;
00130 }
00131 }
00132
else if(
UART_RxBuffer[0] ==
's'){
00133
if(
UART_RxBuffer[1] ==
' '){
00134 speed = atoi((
char const *)
UART_RxBuffer+2);
00135 okCmd =
TRUE;
00136 }
00137 }
00138
else if(
UART_RxBuffer[0] == 13){
00139
speed_cntr_Move(steps, acceleration, deceleration, speed);
00140 okCmd =
TRUE;
00141 }
00142
else if(
UART_RxBuffer[0] ==
'?'){
00143
ShowHelp();
00144 okCmd =
TRUE;
00145 }
00146
00147
00148
if(okCmd !=
TRUE)
00149
ShowHelp();
00150
00151
00152
status.
cmd =
FALSE;
00153
uart_FlushRxBuffer();
00154
00155
if(
status.
running ==
TRUE){
00156
uart_SendString(
"Running...");
00157
while(
status.
running ==
TRUE);
00158
uart_SendString(
"OK\n\r");
00159 }
00160
00161
ShowData(
stepPosition, acceleration, deceleration, speed, steps);
00162 }
00163 }
00164 }
00165
00167 __flash
char Help[] = {
"\n\r--------------------------------------------------------------\n\rAtmel AVR446 - Linear speed control of stepper motor\n\r\n\r? - Show help\n\ra [data] - Set acceleration (range: 71 - 32000)\n\rd [data] - Set deceleration (range: 71 - 32000)\n\rs [data] - Set speed (range: 12 - motor limit)\n\rm [data] - Move [data] steps (range: -64000 - 64000)\n\rmove [steps] [accel] [decel] [speed]\n\r - Move with all parameters given\n\r<enter> - Repeat last move\n\r\n\r acc/dec data given in 0.01*rad/sec^2 (100 = 1 rad/sec^2)\n\r speed data given in 0.01*rad/sec (100 = 1 rad/sec)\n\r--------------------------------------------------------------\n\r"};
00168
00173 void ShowHelp(
void)
00174 {
00175
unsigned int i = 0;
00176
while(
Help[i] != 0)
00177
uart_SendByte(
Help[i++]);
00178 }
00179
00190 void ShowData(
int position,
int acceleration,
int deceleration,
int speed,
int steps)
00191 {
00192
uart_SendString(
"\n\r Motor pos: ");
00193
uart_SendInt(position);
00194
uart_SendString(
" a:");
00195
uart_SendInt(acceleration);
00196
uart_SendString(
" d:");
00197
uart_SendInt(deceleration);
00198
uart_SendString(
" s:");
00199
uart_SendInt(speed);
00200
uart_SendString(
" m:");
00201
uart_SendInt(steps);
00202
uart_SendString(
"\n\r> ");
00203 }
00204