http://hk.myblog.yahoo.com/robot-builder/article?mid=79
網誌日期:2008-05-29 00:29
In this part, I would like to describe the structure of the M-Blocks, both hardware and software, via the Motor Module.
1. Hardware side
Motor module consists of following common interfaces and it's specific interfaces:
see large picture
a. Common interfaces ( yellow blocks )
1. ISP Programming port
2. ON/OFF Switch
3. UART Serial port
4. M-Blocks Bus which have the following standard.
------------------------------------------
Vin - Input Voltage from battery
Vcc - Regulated 5V
3.3V - Regulated 3.3V
SCL - I2C Clock Bus
SDA - I2C Data Bus
S3, S2, S1 - Slave select for SPI bus
MOSI, MISO, SCK - for SPI bus only
( SPI bus is left for further use, I have not develop any sensors or devices through SPI communication )
TX - Transmitter for UART - connected to PC for debug only
RX - Receiver for UART - connected to PC for debug only
-------------------------------------------
b. Specific interfaces for Motor Module
1. SN754410 H-Bridge
2. External Power Input
3. Motor Connectors 1-4
2. Software side
Except the Controller Module which is a master I2C device, all other modules are slave I2C devices. The design of the program is divided into three parts:
--------------------------
| I2C |
--------------------------
| UART |
--------------------------
| Functional Logic |
--------------------------
1) I2C communication among the modules,
2) UART serial communication for debug only ,
3) The functional logic for controlling devices such as motors or servos.
I developed the program in WinAVR and built the hex file using avrdude. If you are interesting in the program, please download here. motor-module.zip
Schematics and board layouts for Eagle
see large picture.
I use atmega8 to make all the communication and controlling. Atmega8 have three timers providing three PWM Channels. It is able to control the width of the PWM to the SN754410 H-Bridge IC by controlling the values of OCR1A ( motor 1 PWM) ,OCR1B (motor 2 PWM) and OCR2 (motor 3 PWM).
For the detailed information of Atmega8, please refer to the data sheet.
The protocol is very simple.
[ch][dir][low-power][h-power] , 1 byte each
[ch] set the motor channel , value = 0,1,2
[dir] set the forward direction or backward direction of the motor, value = 0,1
[low-power] and [high-power] set the speed of the motor, value = 0-255
Example: 00FF -> set ch 0 (left motor), dir 0 (forward), power = FF = 256.
The routetime set_power(uint8_t ch , uint8_t dir,uint8_t power) control the motor, direction and speed of the motor.
As I am not a master in programming micocontroller, many of the coding, especially the hardware configuration, or library are "borrowed" from other's projects.
The I2C library is borrowed from http://tuxgraphics.org/electronics/200705/article07051.shtml
and the PWM control is borrowed from another website but I forgot the author's website.
So far, the Motor Module is working. It received commands from Controller Module and run set_power() routine to generate the PWM for the H-Bridge and control the speed of the Motors. My final version is to make the device which provide feedback parameters to the Controller Module. To make it as a close-loop control. I will borrow the design from the controller board of the openservo project. The controller board is a I2C slave device and it have feedback parameters to the controller board. All the parameters are saved in the registers ( flash memory ) of the micro-controller ( atmega8 or atmega168 ) and permanently in the EEROM as in the following diagram.
--------------------------
| EEROM |
--------------------------
| I2C |
--------------------------
| UART |
--------------------------
| Functional Logic |
--------------------------
Reference websites:
1. Dr. Pascal Stang have contributed to the programming and design of the hardware. It is worthly to study his design if you want to learn avr-gcc programming and hardware design. I have implement the I2C master device from his design.
http://hubbard.engr.scu.edu/embedded/
2. Openservo project, the opensource servo controller is based on atmega8 or atmega168 and avr-gcc. The design is very good.
http://www.openservo.org
3. Paparazzi UAV project
Paparazzi is a free and open-source hardware and software project intended to create an exceptionally powerful and versatile autopilot system by allowing and encouraging input from the community. I implement the PPM decoding for my 6 channels Radio Transmitter by referring to the UAV project.
No comments:
Post a Comment