BLDC control on ATAVRMC303 with ATxMega128A1
DB101_IF.h File Reference
#include <ioavr.h>
#include <inavr.h>
#include <stdint.h>
#include "compiler.h"
#include "config.h"
#include "ushell_task.h"
#include "ascii.h"
#include "lib_mcu/uart/uart_lib.h"
#include "mc_interface.h"
Include dependency graph for DB101_IF.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void BCD_Convert (U8 *data_ptr, U32 number, U8 size)
 
void SendCommand (U8 *data_ptr, U8 length)
 
void UpdateScreen (void)
 

Variables

static U8 clearScreen [4] = {27, '[', '2', 'J'}
 
static U8 Color_b [6] = {27, '[', '3','1','5', 'm'}
 
static U8 Color_black [6] = {27, '[', '4','0','m'}
 
static U8 Color_blue [6] = {27, '[', '4','4','m'}
 
static U8 Color_cyan [6] = {27, '[', '4','6','m'}
 
static U8 Color_g [6] = {27, '[', '2','1','5', 'm'}
 
static U8 Color_gb [6] = {27, '[', '6','1','5', 'm'}
 
static U8 Color_green [6] = {27, '[', '4','2','m'}
 
static U8 Color_magenta [6] = {27, '[', '4','5','m'}
 
static U8 Color_r [6] = {27, '[', '1','1','5', 'm'}
 
static U8 Color_rb [6] = {27, '[', '5','1','5', 'm'}
 
static U8 Color_red [6] = {27, '[', '4','1','m'}
 
static U8 Color_rg [6] = {27, '[', '4','1','5', 'm'}
 
static U8 Color_rgb [6] = {27, '[', '7','1','5', 'm'}
 
static U8 Color_white [6] = {27, '[', '4','7','m'}
 
static U8 Color_yellow [6] = {27, '[', '4','3','m'}
 
static U8 cursorEnd [7] = {27, '[', '8', ';', '2', '1', 'H'}
 
static U8 cursorHome [3] = {27, '[', 'H'}
 
static U8 cursorLine [6] = {27, '[', '0', ';', '0', 'H'}
 
static U8 showPic [6] = {27, '[', '5','0','m'}
 

Function Documentation

◆ BCD_Convert()

void BCD_Convert ( U8 *  data_ptr,
U32  number,
U8  size 
)

Function to convert a hexadecimal number to a string.

Parameters
dataPointer to a string to put the digits in,
numberA number to convert.
sizeMax size of the string of numbers.

Definition at line 62 of file DB101_IF.c.

Referenced by UpdateScreen().

62  {
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 }

◆ SendCommand()

void SendCommand ( U8 *  data_ptr,
U8  length 
)

Send a string over USART. Polled version.

Parameters
dataData to send.
lengthLength of string to send.

Definition at line 13 of file DB101_IF.c.

Referenced by UpdateScreen().

14 {
15  U8 i = 0;
16  while (i < length) {
17  uart_putcharD101(data_ptr[i++]);
18  }
19 }

◆ UpdateScreen()

void UpdateScreen ( void  )

Definition at line 22 of file DB101_IF.c.

References BCD_Convert(), clearScreen, cursorEnd, cursorHome, CW, mc_get_potentiometer_value(), mci_direction, mci_get_measured_speed(), mci_run_stop, and SendCommand().

Referenced by main().

22  {
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 }
static U8 cursorEnd[7]
Definition: DB101_IF.h:20
static U8 cursorHome[3]
Definition: DB101_IF.h:19
Bool mci_direction
User Input parameter to set motor direction.
Definition: mc_interface.c:20
Bool mci_run_stop
User Input parameter to launch or stop the motor.
Definition: mc_interface.c:21
void SendCommand(U8 *data_ptr, U8 length)
Definition: DB101_IF.c:13
void BCD_Convert(U8 *data_ptr, U32 number, U8 size)
Definition: DB101_IF.c:62
static U8 clearScreen[4]
Definition: DB101_IF.h:17
U8 mci_get_measured_speed(void)
Measured of speed.
Definition: mc_interface.c:169
U8 mc_get_potentiometer_value(void)
Get the potentiometer value.
Definition: mc_interface.c:199
Here is the call graph for this function:

Variable Documentation

◆ clearScreen

U8 clearScreen[4] = {27, '[', '2', 'J'}
static

Definition at line 17 of file DB101_IF.h.

Referenced by UpdateScreen().

◆ Color_b

U8 Color_b[6] = {27, '[', '3','1','5', 'm'}
static

Definition at line 34 of file DB101_IF.h.

◆ Color_black

U8 Color_black[6] = {27, '[', '4','0','m'}
static

Definition at line 23 of file DB101_IF.h.

◆ Color_blue

U8 Color_blue[6] = {27, '[', '4','4','m'}
static

Definition at line 27 of file DB101_IF.h.

◆ Color_cyan

U8 Color_cyan[6] = {27, '[', '4','6','m'}
static

Definition at line 29 of file DB101_IF.h.

◆ Color_g

U8 Color_g[6] = {27, '[', '2','1','5', 'm'}
static

Definition at line 33 of file DB101_IF.h.

◆ Color_gb

U8 Color_gb[6] = {27, '[', '6','1','5', 'm'}
static

Definition at line 37 of file DB101_IF.h.

◆ Color_green

U8 Color_green[6] = {27, '[', '4','2','m'}
static

Definition at line 25 of file DB101_IF.h.

◆ Color_magenta

U8 Color_magenta[6] = {27, '[', '4','5','m'}
static

Definition at line 28 of file DB101_IF.h.

◆ Color_r

U8 Color_r[6] = {27, '[', '1','1','5', 'm'}
static

Definition at line 32 of file DB101_IF.h.

◆ Color_rb

U8 Color_rb[6] = {27, '[', '5','1','5', 'm'}
static

Definition at line 36 of file DB101_IF.h.

◆ Color_red

U8 Color_red[6] = {27, '[', '4','1','m'}
static

Definition at line 24 of file DB101_IF.h.

◆ Color_rg

U8 Color_rg[6] = {27, '[', '4','1','5', 'm'}
static

Definition at line 35 of file DB101_IF.h.

◆ Color_rgb

U8 Color_rgb[6] = {27, '[', '7','1','5', 'm'}
static

Definition at line 38 of file DB101_IF.h.

◆ Color_white

U8 Color_white[6] = {27, '[', '4','7','m'}
static

Definition at line 30 of file DB101_IF.h.

◆ Color_yellow

U8 Color_yellow[6] = {27, '[', '4','3','m'}
static

Definition at line 26 of file DB101_IF.h.

◆ cursorEnd

U8 cursorEnd[7] = {27, '[', '8', ';', '2', '1', 'H'}
static

Definition at line 20 of file DB101_IF.h.

Referenced by UpdateScreen().

◆ cursorHome

U8 cursorHome[3] = {27, '[', 'H'}
static

Definition at line 19 of file DB101_IF.h.

Referenced by UpdateScreen().

◆ cursorLine

U8 cursorLine[6] = {27, '[', '0', ';', '0', 'H'}
static

Definition at line 18 of file DB101_IF.h.

◆ showPic

U8 showPic[6] = {27, '[', '5','0','m'}
static

Definition at line 21 of file DB101_IF.h.