What you need to know about Sensors

Download Report

Transcript What you need to know about Sensors

Microcontrollers you should
know about
Thomas Edwards
http://www.t11s.com
1
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
2
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!
3
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
4
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
5
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
6
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
7
Parallax Sensors
• Sensors made with the BS in mind
• But you could use them with other uCs
8
Basic Stamp Pros/Cons
Pros:
• Popular
• Easy to use
• Tons of online
documentation
• Many sensors
available
Cons:
• Expensive
• Small memories
• No A/D inputs
9
“Fish Pain” Maquette
• Basic Stamp reads button,
drives fish animation
• Winbond Chipcoder voice board
10
Microchip PIC
• Array of cheap but powerful
microcontrollers
• $1-$10
• Natively programmed in assembly
language
• Lots of functionality (A/D, PWM, timers,
counters)
11
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)
12
PIC Assembly Language
• Harvard Architecture
– Separate instructions and data
• Memory “Banks”
• Many, many special registers for config
13
PIC C
void 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
}
}
14
PICs – Pin “Overloading”
• Pins can serve four or more different
functions
• Flexibility to meet project needs with
minimal pins
• Often difficult to properly configure
15
“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
16
Atmel AVR
• Family of microcontrollers
– ATmega
– ATtiny
• $1-$15
• Similar to PIC, but slightly easier to
program in assembly language
• “Religious discussions” about PIC
17
versus AVR
Training Boards
• PIC18F458 training
board ($44.90
http://www.futurlec.co
m/PIC18F458Training.
shtml)
• ATMega163 training
board ($44.90
http://www.futurlec.co
m/ATMegaTraining.sht
ml )
18
PIC/AVR Pros/Cons
Pros:
• Very cheap
• Many interfaces and
functions (A/D,
PWM, timers,
counters, I2C)
• Lots of online
documentation &
support
Cons:
• Tough to program in
assembler/C
• Programmer board
required (sometimes
~$50)
• Many different types
of PIC, programs
don’t port between
them
19
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
20
CUBLOC BASIC
Dim f_pos_1 As Byte
Dim f_pres_1 As Byte
Input 5
Opencom 0,9600,3,32,32
Opencom 1,9600,3,32,32
Bclr 1,1
'P0 / Pin 5 as Input
'open RS-232 channel to Xport
'open serial channel to Servo Controller
'clear channel 1 tx buffer
On timer(10) Gosub a2d
'every 100 ms
On Recv0 Gosub servo_move 'on UDP in from Xport
Do
Loop
a2d:
f_pres_1=Adin(0)>>2
Put 0,f_pres_1,1
Return
'scale 0-1023 to 0-255
'send finger pressure to Xport
21
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
22
CUBLOC Pros/Cons
Pros:
• Easy to
program/use
• Many interfaces
(A/D, PWM, I2C)
• Great vendor
documentaton
Cons:
• More expensive
than PIC/AVR,
but less than BS
• Not very popular
yet
23
“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
24
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/
25
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
26
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/17
67486/2337356.htm
27
Microcontrollers you should
know about
Thomas Edwards
http://www.t11s.com
28