1 Microcontrollers you should know about Thomas Edwards .
-
Upload
gavin-norman -
Category
Documents
-
view
215 -
download
0
Transcript of 1 Microcontrollers you should know about Thomas Edwards .
1
Microcontrollers you should know about
Thomas Edwards
http://www.t11s.com
2
What is a Microcontroller (uC)?
• A “computer-on-a-chip”
• Simple but reliable way to control electromechanical systems
• No boot-up / no hard drives
• Smaller than a PC
• Less power/heat than a PC
• Cheaper than a PC
3
What can you do with a uC?
• Flash LEDs in a particular way
• Move a motor in a pre-programmed fashion
• Have LEDs, motors, servos respond to switch or sensor inputs
• Connect devices to the Internet
• Much more!
4
What does a uC need?
• Power Supply – the right voltage
• Support circuitry – different needs for different uCs– Voltage regulators– Crystals or resonators– Serial, USB, or Ethernet interfaces
• Programmer (usually PC based)
• Proto-board to assemble circuitry on
5
Basic Stamps
• Very popular!• Runs PBASIC interpreter• No Analog inputs…
• BS2 ($49)– 4,000 instructions per sec.– 16 Digital I/O pins– 32 bytes RAM– ~500 instructions
• http://www.parallax.com
6
Other Types of Stamp• BS Rev. Dx ($34)
– BS1 w. proto area– 16 bytes ram– 80 instructions– ~2,000 instructions./s
• BS1 USB ($39)– $39.95
• BS2px ($79)– 38 bytes RAM– ~4,000 instructions– ~19,000 instructions/s
7
Programming BS in PBASIC
For b2= 0 to 5
high 1
pause 100
low 1
pause 100
next b2
N VAR BYTE
TOP: FOR N = 0 TO 100
SEROUT 16, 84, 10, ["N = ", DEC N, CR]
PAUSE 500
NEXT
GOTO TOP
8
Parallax Sensors
• Sensors made with the BS in mind
• But you could use them with other uCs
9
Basic Stamp Pros/Cons
Cons:
• Expensive
• Small memories
• No A/D inputs
Pros:
• Popular
• Easy to use
• Tons of online documentation
• Many sensors available
10
“Fish Pain” Maquette
• Basic Stamp reads button, drives fish animation
• Winbond Chipcoder voice board
11
Microchip PIC
• Array of cheap but powerful microcontrollers
• $1-$10• Natively programmed in assembly
language• Lots of functionality (A/D, PWM, timers,
counters)
12
Some (of the hundreds) of PICs• PIC12C508/509 (Small 8-pin package, internal oscillator, popular in small
designs such as the iPod remote) • PIC12F629/675/683 • PIC16F84 (generally considered obsolete, but still popular) • PIC16F84A (upgrade to above, some versions do 20 MHz, 1:1 compatible
with PIC16F84) • PIC16F628 (replaces the PIC16F84. The 16F628A has more program
memory and fully compatible) • PIC16F88 (an excellent all-round 18-pin PICmicro) • The PIC16F87X family (The PIC16F84's "big brothers", with lots of built in
hardware similar to the 16F88. Quite common in hobby projects.) • PIC16F877 (RS232, Parallel Port Interface, PWM and much more) • PIC18F452 • PIC18F4550 and relatives (Full-speed USB support, all sorts of inbuilt
hardware. Very powerful and versatile)
13
PIC Assembly Language
• Harvard Architecture– Separate instructions and data
• Memory “Banks”
• Many, many special registers for config
14
PIC Cvoid serTxIsr(void){
if (idxTxbufPut != idxTxbufGet) { TXREG = txBuf[idxTxbufGet]; idxTxbufGet = (++idxTxbufGet) &
SER_TXBUF_MASK; } else { PIE1_TXIE = 0; //Disable USART Transmit
interrupt when nothing more to TX }}
15
PICs – Pin “Overloading”
• Pins can serve four or more different functions
• Flexibility to meet project needs with minimal pins
• Often difficult to properly configure
16
“Sycophant”
• Head mounted on R/C car chassis
• Follows viewers as they move down hall
• Sharp active IR sensors• PIC 16F648A controller• L293 Motor controller• Windbond Chipcorder
audio chip
17
Atmel AVR
• Family of microcontrollers– ATmega– ATtiny
• $1-$15
• Similar to PIC, but slightly easier to program in assembly language
• “Religious discussions” about PIC versus AVR
18
Training Boards
• PIC18F458 training board ($44.90 http://www.futurlec.com/PIC18F458Training.shtml)
• ATMega163 training board ($44.90 http://www.futurlec.com/ATMegaTraining.shtml )
19
PIC/AVR Pros/ConsCons:• Tough to program in
assembler/C• Programmer board
required (sometimes ~$50)
• Many different types of PIC, programs don’t port between them
Pros:• Very cheap• Many interfaces and
functions (A/D, PWM, timers, counters, I2C)
• Lots of online documentation & support
20
CUBLOC CB220• Basic Stamp “pin compatible”• But much more powerful…
– 80 KB flash instruction memory– 4 KB EEPROM– 2 KB Data RAM– 36,000 instructions per second– A/D (up to 5V)
• Built-in 5V regulator• Based on AVR
• CB220 $34, Proto board $5• http://www.comfiletech.com
21
CUBLOC BASICDim f_pos_1 As ByteDim f_pres_1 As Byte
Input 5 'P0 / Pin 5 as InputOpencom 0,9600,3,32,32 'open RS-232 channel to XportOpencom 1,9600,3,32,32 'open serial channel to Servo ControllerBclr 1,1 'clear channel 1 tx buffer
On timer(10) Gosub a2d 'every 100 msOn Recv0 Gosub servo_move 'on UDP in from Xport
DoLoop
a2d:f_pres_1=Adin(0)>>2 'scale 0-1023 to 0-255Put 0,f_pres_1,1 'send finger pressure to XportReturn
22
Lantronix Xport
• Ethernet-to-serial converter• Can operate in TCP or
UDP modes• Web-based configuration
• Comfile “dongle” allows easy DB9 attachement
• Xport ($54), dongle ($8)• http://www.comfiletech.com
23
CUBLOC Pros/Cons
Cons:
• More expensive than PIC/AVR, but less than BS
• Not very popular yet
Pros:
• Easy to program/use
• Many interfaces (A/D, PWM, I2C)
• Great vendor documentaton
24
“Touch” Maquette
• To “touch someone” over the Internet
• R/C servo driving plastic finger
• Force-sensitive resistor on tip
• CUBLOC 220, Xport, Pololu Serial Servo controller
25
MAKE Magazine Controller• Just came out ($149 for board)• 30 I/O lines• 8 A/D (up to 3.3V)• 8 “high current” motor driver outs• Ethernet/USB/I2C• Atmel AT91SAM7X256 based / 48
MIPS • C programmed• Connect to Max/MSP via Open
Sound Control (OSC)
• http://www.makingthings.com/makecontrollerkit/
26
The Alternative: PC Parallel Ports
• 12 digital outputs
• 5 digital inputs
• 8 grounds
• Data pins (Dx) may also be inputs in bi-directional ports, giving 13 inputs
data = _inp(atoi(888)); /* read port 0x378 data pins */
_outp(atoi(888),atoi(data)); /* write port 0x378 data pins */
http://www.logix4u.net/parallelport1.htm
27
PC w. Serial/USB Interfaces
• The Serializer ($139.95)• 16 Digital I/Os• 5 Analog inputs• 2 x 4A DC motor drivers• 2 RC Servo controllers• I2C Interface• .NET/C# programmable
• http://www.roboticsconnection.com/catalog/item/1767486/2337356.htm
28
Microcontrollers you should know about
Thomas Edwards
http://www.t11s.com