add an output device to a microcontroller board you've designed and program it to do something
download the eagle files and .png
software: python, Tcl, PySerial, eagle, FabModules;
tools: SRM-20 (for the operation go to week_06)
location: Green FabLab Valldaura (BCN)
how to:
in week 11 i took on the task to add more to the board. for keeping the empty pins on the microcontroller available, i added a pin header which is connected to the empty pins through vias and cables on the bottom.
the board i chose is the DC-motor controller. again i used eagle to design the board but also in photoshop i personalized it a little bit with my signature... the traces going to the motor are thicker than the rest, so they can easily deal with the electricity going through.
the edge is not straight for a change, which gives the board a nice feeling.
when everything has been assembled i put a piece of tape on the axis of the motor to see the movement. after programming the board with the FabIsp it should have been turning but it didn't. i had a look at Théo's page, since he made the same board. it turned out that it was the delay in the code which needed to be changed.
// // // hello.H-bridge.44.DC.c // // H-bridge DC motor hello-world // // Neil Gershenfeld // 11/18/12 // // (c) Massachusetts Institute of Technology 2012 // This work may be reproduced, modified, distributed, // performed, and displayed for any purpose. Copyright is // retained and must be preserved. The work is provided // as is; no warranty is provided, and users accept all // liability. // #include <avr/io.h> #include <util/delay.h> #define output(directions,pin) (directions |= pin) // set port direction for output #define set(port,pin) (port |= pin) // set port pin #define clear(port,pin) (port &= (~pin)) // clear port pin #define pin_test(pins,pin) (pins & pin) // test for port pin #define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set #define on_delay() _delay_us(500) // PWM on time #define fast_off_delay() _delay_us(100) // PWM fast off time #define medium_off_delay() _delay_us(100) // PWM medium off time #define slow_off_delay() _delay_us(100) // PWM slow off time #define PWM_count 20000 // number of PWM cycles #define cycle_count 5 // number of speed cycles #define bridge_port PORTA // H-bridge port #define bridge_direction DDRA // H-bridge direction #define IN1 (1 << PA3) // IN1 #define IN2 (1 << PA2) // IN2 int main(void) { // // main // static uint16_t count; static uint8_t cycle; // // set clock divider to /1 // CLKPR = (1 << CLKPCE); CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0); // // initialize H-bridge pins // clear(bridge_port, IN1); output(bridge_direction, IN1); clear(bridge_port, IN2); output(bridge_direction, IN2); // // main loop // while (1) { for (cycle = 0; cycle < cycle_count; ++cycle) { // // turn forward slow // clear(bridge_port, IN1); set(bridge_port, IN2); for (count = 0; count < PWM_count; ++count) { set(bridge_port, IN2); on_delay(); clear(bridge_port, IN2); slow_off_delay(); } // // turn reverse slow // clear(bridge_port, IN2); set(bridge_port, IN1); for (count = 0; count < PWM_count; ++count) { set(bridge_port, IN1); on_delay(); clear(bridge_port, IN1); slow_off_delay(); } } for (cycle = 0; cycle < cycle_count; ++cycle) { // // turn forward medium // clear(bridge_port, IN1); set(bridge_port, IN2); for (count = 0; count < PWM_count; ++count) { set(bridge_port, IN2); on_delay(); clear(bridge_port, IN2); medium_off_delay(); } // // turn reverse medium // clear(bridge_port, IN2); set(bridge_port, IN1); for (count = 0; count < PWM_count; ++count) { set(bridge_port, IN1); on_delay(); clear(bridge_port, IN1); medium_off_delay(); } } for (cycle = 0; cycle < cycle_count; ++cycle) { // // turn forward fast // clear(bridge_port, IN1); set(bridge_port, IN2); for (count = 0; count < PWM_count; ++count) { set(bridge_port, IN2); on_delay(); clear(bridge_port, IN2); fast_off_delay(); } // // turn reverse fast // clear(bridge_port, IN2); set(bridge_port, IN1); for (count = 0; count < PWM_count; ++count) { set(bridge_port, IN1); on_delay(); clear(bridge_port, IN1); fast_off_delay(); } } } } Ads by RespectSaleAd Options
and then - finally!