6 * \mainpage EB-ebb code sample
8 * \section Introduction
9 * This codes are designed for use with ebBoard developed in DCE CVUT.
10 * There are two purpose of this program:
12 * 1) library named ebb, it contains function for handling engines,
13 * servos, ADC (median or avery filtered) and power switch.
15 * 2) in main.c file is simply HOW-TO use this libraries
17 * Short description of ebb library:
19 * ADC – This library use 4 ADC channels which parameters I defined
20 * in adc.h or adc_filtr.h. There is two implementation of ADC output
21 * filter. First is simply averaging ((last value + actual value)/2),
22 * for this filter you have to include adc.h. The Second filter is
23 * median filter in adc_filtr.h . The size of this filter is defined
26 * PowerSwitch – ebboard have one 6A power switch which can be used for
27 * switching small loads (capacity or resistant recommended). In powswitch.h is defined initialization, on and off function.
29 * Servos – ebboard have three servo connectors. In servo.h is defined
30 * functions for setting them. The servo range is divided into 256 (0~255)
33 * Engines – this part can controls up two DC motors (5A each) or in
34 * special cases one motor (up to 10A). In engines.h is defined several
35 * controls function. Read carefully description in this section. Is
36 * important to understanding the way how to stop engines.
43 * @brief Demo application demonstrating use of eb_ebb library.
44 * This file provides simply how-to use eb_ebb library.
45 * From main function is called init_perip function
46 * where is initialized servos, engines, power switch,
47 * CAN,ADC and serial port. After this initialization is shown
48 * how to control each devices. This sample also include simply
49 * sample of sending and receiving CAN message.
54 #include <lpc21xx.h> /* LPC21xx definitions */
56 #include <periph/can.h>
61 #include "powswitch.h"
63 //#include "adc.h" // header ADC with averaging filter
64 #include "adc_filtr.h" // header ADC with mean filter
69 #define CAN_SPEED 1000000 ///< CAN speed
71 #define CAN_SERVO 0x32 ///< CAN ID for servo message
74 * Variables ISR values
83 #define SPEED 30 ///< Motor speed
87 * Dummy wait (busy wait)
88 * This function shoul be removed in future
98 * This function is called when we recieve CAN message.
99 * Its called from CAN ISR
101 * @param *msg structure of can message (can_msg_t)
104 void can_rx(can_msg_t
*msg
) {
107 memcpy(&rx_msg
, msg
, sizeof(can_msg_t
));
109 switch (rx_msg
.id
) { // demo sample parsing recieved message by ID
112 set_servo(0, rx_msg
.data
[0]);
113 set_servo(1, rx_msg
.data
[1]);
114 set_servo(2, rx_msg
.data
[2]);
124 * Inicializes pepherials used in ebb library - sample use
127 void init_perip(void)
129 init_servo(SERVO_ISR
);
135 init_uart0((int)9600 ,UART_BITS_8
, UART_STOP_BIT_1
, UART_PARIT_OFF
, 0 );
136 //init_adc(ADC_ISR); // inicialization ADC with averaging filter
137 init_adc_filter(ADC_ISR
); // inicialization ADC with mean filter
138 can_init_baudrate(CAN_SPEED
, CAN_ISR
, can_rx
);
143 * Main function contains a small sample how to use ebb library.
148 init_perip(); // sys init MCU
150 set_servo(0, 0x80); // set servo 1 to center position
151 set_servo(1, 0x80); // set servo 2 to center position
152 set_servo(2, 0x80); // set servo 3 to center position
154 engine_A_dir(ENGINE_DIR_FW
); // set engine A to direction forward
155 engine_B_dir(ENGINE_DIR_BW
); // set engine B to direction backward
156 engine_A_en(ENGINE_EN_ON
); // enables engine A
157 engine_B_en(ENGINE_EN_ON
); // enables engine B
158 engine_A_pwm(SPEED
); // sets speed on Engine A
159 engine_B_pwm(SPEED
); // sets speed on Engine B
162 can_msg_t msg
; // This part is sending CAN messge
163 msg
.id
= 0xAA; // CAN message ID
165 msg
.dlc
= 1; // number of transmited data bytes
166 msg
.data
[0] = 0x55; // data byte
167 while(can_tx_msg(&msg
)); // sending function
170 while(1) // this will blink for ever