| BLDC control on ATAVRMC303 with ATxMega128A1

DB101_IF.c
Go to the documentation of this file.
1
2 #include "DB101_IF.h"
3
4
5
6
7
13 void SendCommand(U8 * data_ptr, U8 length)
14 {
15 U8 i = 0;
16 while (i < length) {
17 uart_putcharD101(data_ptr[i++]);
18 }
19 }
20
21
22 void UpdateScreen(void){
23 static U8 Line0[21] = {"Motor Control Demo\n\n\r"};
24 static U8 Line1[17] = {"Speed: 0000 RPM\n\r"};
25 static U8 Line2[16] = {"Dir: Forwards \n\r"};
26 static U8 Line3[16] = {"Dir: Backwards\n\r"};
27 static U8 Line4[17] = {"Status: Running\n\r"};
28 static U8 Line5[17] = {"Status: Stopped\n\r"};
29 static U8 Line6[21] = {"Speed Ref: 0000 RPM\n\r"};
30 U32 SpeedCalc = mci_get_measured_speed()*27;
31 U32 SpeedRef = mc_get_potentiometer_value();
32 /* Convert numbers to ASCII */
33 BCD_Convert(&Line1[7], (U32) SpeedCalc, 4);
34 BCD_Convert(&Line6[11], (U32) SpeedRef, 4);
35
36 /* Send commands.*/
37 SendCommand(&clearScreen[0], 4);
38 SendCommand(&cursorHome[0], 3);
39 SendCommand(&Line0[0], 21);
40 SendCommand(&Line1[0], 17);
41 if (mci_direction == CW){
42 SendCommand(&Line2[0], 16);
43 }else{
44 SendCommand(&Line3[0], 16);
45 }
46 if (mci_run_stop == TRUE){
47 SendCommand(&Line4[0], 17);
48 }else{
49 SendCommand(&Line5[0], 17);
50 }
51 SendCommand(&Line6[0], 21);
52 SendCommand(&cursorEnd[0], 7);
53
54 }
55
62 void BCD_Convert(U8 * data_ptr, U32 number, U8 size){
63 if (size > 7) {
64 data_ptr[size-8] = 48;
65 while (number >= 10000000){
66 number -= 10000000;
67 data_ptr[size-8]++;
68 }
69 }
70 if (size > 6) {
71 data_ptr[size-7] = 48;
72 while (number >= 1000000){
73 number -= 1000000;
74 data_ptr[size-7]++;
75 }
76 }
77 if (size > 5) {
78 data_ptr[size-6] = 48;
79 while (number >= 100000){
80 number -= 100000;
81 data_ptr[size-6]++;
82 }
83 }
84 if (size > 4) {
85 data_ptr[size-5] = 48;
86 while (number >= 10000){
87 number -= 10000;
88 data_ptr[size-5]++;
89 }
90 }
91 if (size > 3) {
92 data_ptr[size-4] = 48;
93 while (number >= 1000){
94 number -= 1000;
95 data_ptr[size-4]++;
96 }
97 }
98 if (size > 2) {
99 data_ptr[size-3] = 48;
100 while (number >= 100){
101 number -= 100;
102 data_ptr[size-3]++;
103 }
104 }
105 if (size > 1) {
106 data_ptr[size-2] = 48;
107 while (number >= 10){
108 number -= 10;
109 data_ptr[size-2]++;
110 }
111 }
112 if (size > 0) {
113 data_ptr[size-1] = 48;
114 while (number >= 1){
115 number -= 1;
116 data_ptr[size-1]++;
117 }
118 }
119 }
cursorEnd
static U8 cursorEnd[7]
Definition: DB101_IF.h:20
cursorHome
static U8 cursorHome[3]
Definition: DB101_IF.h:19
UpdateScreen
void UpdateScreen(void)
Definition: DB101_IF.c:22
mci_direction
Bool mci_direction
User Input parameter to set motor direction.
Definition: mc_interface.c:20
mci_run_stop
Bool mci_run_stop
User Input parameter to launch or stop the motor.
Definition: mc_interface.c:21
SendCommand
void SendCommand(U8 *data_ptr, U8 length)
Definition: DB101_IF.c:13
DB101_IF.h
CW
Definition: config_motor.h:34
BCD_Convert
void BCD_Convert(U8 *data_ptr, U32 number, U8 size)
Definition: DB101_IF.c:62
clearScreen
static U8 clearScreen[4]
Definition: DB101_IF.h:17
mci_get_measured_speed
U8 mci_get_measured_speed(void)
Measured of speed.
Definition: mc_interface.c:169
mc_get_potentiometer_value
U8 mc_get_potentiometer_value(void)
Get the potentiometer value.
Definition: mc_interface.c:199