Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

main.c File Reference


Detailed Description

Demo of Linear speed ramp controller.

Demo of linear speed ramp controller. Control of stepper motor by the serial port. A menu gives the user status and shows the avaliable commands.

Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Name
RELEASE_1_0
Revision
1.2
RCSfile
main.c,v
Date
2006/05/08 12:25:58

Definition in file main.c.

#include <ioavr.h>
#include <inavr.h>
#include <stdlib.h>
#include "global.h"
#include "uart.h"
#include "sm_driver.h"
#include "speed_cntr.h"

Include dependency graph for main.c:

Include dependency graph

Go to the source code of this file.

Functions

void Init (void)
 Init of peripheral devices.

void main (void)
 Demo of linear speed controller.

void ShowData (int position, int acceleration, int deceleration, int speed, int steps)
 Sends out data.

void ShowHelp (void)
 Sends help message.


Variables

__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"}
 Help message.

GLOBAL_FLAGS status = {FALSE, FALSE, 0}
 Global status flags.


Function Documentation

void Init void   ) 
 

Init of peripheral devices.

Setup IO, uart, stepper, timer and interrupt.

Definition at line 42 of file main.c.

References InitUART(), sm_driver_Init_IO(), sm_driver_StepOutput(), and speed_cntr_Init_Timer1().

Referenced by main().

00043 { 00044 // Init of IO pins 00045 sm_driver_Init_IO(); 00046 // Init of uart 00047 InitUART(); 00048 00049 // Set stepper motor driver output 00050 sm_driver_StepOutput(0); 00051 00052 // Init of Timer/Counter1 00053 speed_cntr_Init_Timer1(); 00054 00055 __enable_interrupt(); 00056 }

Here is the call graph for this function:

void main void   ) 
 

Demo of linear speed controller.

Serial interface frontend to test linear speed controller.

Definition at line 62 of file main.c.

References GLOBAL_FLAGS::cmd, FALSE, Init(), GLOBAL_FLAGS::running, ShowData(), ShowHelp(), speed_cntr_Move(), status, stepPosition, TRUE, uart_FlushRxBuffer(), UART_RxBuffer, and uart_SendString().

00063 { 00064 // Number of steps to move. 00065 int steps = 1000; 00066 // Accelration to use. 00067 int acceleration = 100; 00068 // Deceleration to use. 00069 int deceleration = 100; 00070 // Speed to use. 00071 int speed = 800; 00072 // Tells if the received string was a valid command. 00073 char okCmd = FALSE; 00074 00075 Init(); 00076 00077 // Outputs help screen. 00078 uart_SendString("\n\r"); 00079 ShowHelp(); 00080 ShowData(stepPosition, acceleration, deceleration, speed, steps); 00081 00082 while(1) { 00083 // If a command is received, check the command and act on it. 00084 if(status.cmd == TRUE){ 00085 if(UART_RxBuffer[0] == 'm'){ 00086 // Move with... 00087 if(UART_RxBuffer[1] == ' '){ 00088 // ...number of steps given. 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 // ...all parameters given 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 // Set acceleration. 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 // Set deceleration. 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 // Send help if invalid command is received. 00148 if(okCmd != TRUE) 00149 ShowHelp(); 00150 00151 // Clear RXbuffer. 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 }//end if(cmd) 00163 }//end while(1) 00164 }

Here is the call graph for this function:

void ShowData int  position,
int  acceleration,
int  deceleration,
int  speed,
int  steps
 

Sends out data.

Outputs the values of the data you can control by serial interface and the current position of the stepper motor.

Parameters:
acceleration Accelration setting.
deceleration Deceleration setting.
speed Speed setting.
steps Position of the stepper motor.

Definition at line 190 of file main.c.

References uart_SendInt(), and uart_SendString().

Referenced by main().

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 }

Here is the call graph for this function:

void ShowHelp void   ) 
 

Sends help message.

Outputs help message.

Definition at line 173 of file main.c.

References Help, and uart_SendByte().

Referenced by main().

00174 { 00175 unsigned int i = 0; 00176 while(Help[i] != 0) 00177 uart_SendByte(Help[i++]); 00178 }

Here is the call graph for this function:


Variable Documentation

__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"}
 

Help message.

Definition at line 167 of file main.c.

Referenced by ShowHelp().

struct GLOBAL_FLAGS status = {FALSE, FALSE, 0}
 

Global status flags.

Definition at line 33 of file main.c.

Referenced by main(), speed_cntr_Move(), speed_cntr_TIMER1_COMPA_interrupt(), and UART_RX_interrupt().


Generated on Mon May 8 15:05:03 2006 for AVR446 - Linear speed control of stepper motor by doxygen 1.3.7