How To Build A Better Arduino

5,508 views

Published on

Published in: Self Improvement
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,508
On SlideShare
0
From Embeds
0
Number of Embeds
818
Actions
Shares
0
Downloads
64
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • Wiring is a simplified form of C++ - it provides a simple API and removes some of the requirements of C++ by using a preprocessor to do things such as automatic prototype declarations.
  • Currently have support for ATMEGA168, 328, 1280 & ATTINY2313. Adding new microcontrollers involves creating a new header file from the data sheet. Most of it can be cut and pasted from an existing header as Atmel have strived to be consistent between controllers.We try to keep the code lean by doing as little handholding as possible – we just get the job done, in as few instructions as possibleAvoid unnecessary memory allocations, use appropriate datatypesWe provide busy waiting and interrupt driven variants of most peripheral functions, allowing the microcontroller to get on with other work while the task progressesThe Arduino libraries make use of deprecated macros such as the old cbi & sbi macros, and also produces warnings when compiled
  • How To Build A Better Arduino

    1. 1. How to Build a Better Arduino – the Development of MHVlib<br />Alastair D’Silva<br />@EvilDeece<br />http://alastair.d-silva.org<br />http://www.makehackvoid.com<br />
    2. 2. What is an Arduino<br />A hardware and software platform for prototyping electronics<br />Low entry barrier allows programmers to interact with the real world<br />Built on top of Wiring<br />
    3. 3. Love Arduino<br />Cheap hardware<br />Simple to understand<br />Serial bootloader makes programming easy<br />
    4. 4. Hate Arduino<br />Slow<br />Memory inefficient<br />Caused by:<br />Excessing handholding<br />Backwards compatibility<br />
    5. 5. Fix Arduino<br />Keep the good parts<br />Hardware<br />Bootloader<br />Ditch the bad parts<br />Runtime libraries<br />
    6. 6. Design Philosophy<br />Portable (support all ATMEGA & ATTINY)<br />Lean<br />Memory efficient<br />Use interrupts if possible<br />No deprecated calls<br />No warnings<br />
    7. 7. HardwareSerial<br />Arduino<br />Uses fixed length, preallocated 128 byte RX buffers<br />Preinstanties 1 object for each serial port<br />Reinvents the wheel regarding string formatting<br />Interrupt driven RX, busy TX<br />MHVlib<br />User allocates buffers and passes them in<br />User instantiates only what is needed<br />Provides interrupt driven & busy variants of RX/TX<br />Provides PROGMEM TX support<br />
    8. 8. Digital IO<br />Arduino<br />Lots of handholding<br />Uses extensive tables in PROGMEM to look up pin ports & bits<br />~55 clocks<br />MHVlib<br />No handholding<br />Uses macros<br />Single instruction, 2 clocks<br />
    9. 9. MHVlib Digital IO<br />io.h:<br /> //Dir,Output,Input,Bit<br />#define MHV_PIN_B0 &DDRB,&PORTB, &PINB,0<br />#define mhv_pinOn(mhvParms) <br />do { <br /> _mhv_pinOn(mhvParms) <br />} while(0)<br />#define _mhv_pinOn(mhvDir,mhvOutput,mhvInput,mhvBit) <br />*mhvOutput |= _BV(mhvBit);<br />
    10. 10. Digital IO Usage<br />Arduino<br />pinMode(13, OUTPUT);<br />digitalWrite(13, 1);<br />MHVlib<br />mhv_setOutput(MHV_ARDUINO_PIN_13);<br />mhv_pinOn(MHV_ARDUINO_PIN_13);<br />
    11. 11. Servo Library<br />Arduino Servo<br />Consumes 1 16 bit timer per 12 servos<br />~10 bits of significance<br />Resolution of 16 clock cycles<br />ArduinoSoftwareServo<br />Uses a 16 bit int, valid values are 0 to 180<br />Refresh must be called periodically<br />Sorts the list of servo positions on each pass<br />Lots of busy waiting<br />MHVlib<br />Uses a uint16_t, 0-65535 (~14 bits significant)<br />Consumes 1 16 bit timer<br />Resolution of 2 clock cycles<br />No restrictions as to how many servos<br />Only sorts when positions change<br />
    12. 12. References<br />http://billgrundmann.wordpress.com/2009/03/03/to-use-or-not-use-writedigital/<br />http://www.arduino.cc<br />
    13. 13. First (Real) Project<br />Spindle controller for a CNC Mill<br />Generates a servo signal to a BLDC controller to drive an RC helicopter motor (up to 1.8kW)<br />Read from the serial port and set the speed<br />Monitor the spindle and adjust the speed<br />Report actual speed back to the PC<br />Arduino version<br />11,900 bytes of flash<br />500 bytes of RAM<br />MHVlib version<br />6930 bytes of flash<br />177 bytes of RAM<br />

    ×