dear.. All. I wish to create Stepper project, with command line controlled, i modified Traffic example on keil c51 sample, with like this:
#include <reg52.h> #include <stdio.h> #include <rtx51tny.h> /* RTX-51 tiny functions & defines */ #include <ctype.h> /* character functions */ #include <string.h> /* string and memory functions */ char code menu[] = "\n" "+***** STEPPER MOTOR CONTROLLER ******+\n" "+ S : Set Waktu Mulai +\n" "+ D : Tampilkan Waktu +\n" "+ E : Set Waktu Berakhir +\n" "+ T : Set Waktu +\n" "+ L : Ubah Arah Menjadi Ke Kiri +\n" "+ R : Ubah Arah Menjadi Ke Kanan +\n" "+ F : Mode FULL STEP +\n" "+ H : Mode HALF STEP +\n" "+-------+-----------------------------+\n"; unsigned char code ful_seq_pat[4] = {10,9,5,6};//{1,4,2,8}; //{1,2,4,8}; unsigned char code half_seq_pat[8] = {0xfa,0xf8,0xf9,0xf1,0xf5,0xf4,0xf6,0xf2}; // Half Step Pattern // 11111010,11111000,11111001,11110001,11110101,11110100,11110110,11110010 extern getline (char idata *, char); /* external function: input line */ extern serial_init (); /* external function: init serial UART */ #define INIT 0 /* task number of task: init */ #define COMMAND 1 /* task number of task: command */ #define CLOCK 2 /* task number of task: clock */ #define BLINKING 3 /* task number of task: blinking */ #define LIGHTS 4 /* task number of task: signal */ //#define KEYREAD 4 /* task number of task: keyread */ #define GET_ESC 5 /* task number of task: get_escape */ //#define COUNTER_TM 6 sfr dataport = 0x80;//0x90; bit direction; bit step_mode; bit timed_out; struct time { /* structure of the time record */ unsigned char hour; /* hour */ unsigned char min; /* minute */ unsigned char sec; /* second */ }; struct time ctime = { 12, 0, 0 }; /* storage for clock time values */ struct time start = { 7, 30, 0 }; /* storage for start time values */ struct time end = { 18, 30, 0 }; /* storage for end time values */ char idata inline[16]; /* storage for command input line */ unsigned char idata sequencer; //unsigned int idata timer_like,buf_timer_like; /******************************************************************************/ /* Task 0 'init': Initialize */ /******************************************************************************/ void init (void) _task_ INIT { /* program execution starts here */ serial_init (); /* initialize the serial interface */ sequencer = 0; direction = 0; step_mode = 0; //timed_out = 0; //buf_timer_like = 1; //timer_like = buf_timer_like; os_create_task (CLOCK); os_create_task (COMMAND); /* start command task */ os_create_task (LIGHTS); /* start lights task */ //os_create_task (COUNTER_TM); //os_create_task (KEYREAD); /* start keyread task */ os_delete_task (INIT); /* stop init task (no longer needed) */ } bit display_time = 0;
Eric, I do not tend to agree. RTX51 Tiny is a very powerful RTOS for an 8051 and using it on an Infineon XC8xx device (that is designed for Motor control) makes perfectly sense. Important is a clean software architecture and several times an RTOS simplifies a software architecture a lot. Reinhard
I assume from the title that you need the stepper motor to spin at higher RPM? The limiting factor on speed will be how many instructions you have to execute before you can update the motor controller again. As nice as an RTOS can be, the task switching overhead might be getting in the way. As a test, you might create a single task waiting on its timeout event, and use a hardware timer to measure the latency. That would be your best-case step rate. How about a interrupt service routine that advances the stepper motor, driven by one of the hardware timers? The timer value would be calculated by the command task when it parses the command to set the motor speed, and picked up on the next reload of the timer by the ISR, or just set by the command task if you have an auto-reload timer to spare.
using it on an Infineon XC8xx device (that is designed for Motor control) makes perfectly sense. It MAY, but when the question is "more speed" it hardly does. Adding overhead will, by definition reduce speed and, convesely, removing it will increase speed. If the product is very complex and not time critical nature there may, even for the '51 (which is singularily unsuited), be an argument for using a RTOS. I have no problem whatsoever with using a RTOS on a suitable processor Erik