Anda di halaman 1dari 10

All of Mechatronics-- abridged

Transistors

BJT

current controlled
cheap
require careful resistor sizing
PIC current = (1/10) load current required
5V = (PIC current)*(Resistor size)

MOSFET

voltage controlled
slightly less cheap
easy, just hook straight to pin

Two NPN BJTs with built in snubbers


just connect pic to one side and output to other side

Darlington
H-Bridge

for two directional motor driving


snubs, decoups, hs
Snubber diodes
prevent damage due to current spikes when turning
off motor
put around motor, bar pointing towards +V
decoupling capacitors
same concept as snubbers, removes noise
put next to load side of motor and connect to
ground
H-Bridges
Two inside chip
can get hot

Motors

DC brush

electromagnet moves, permanent magnet stays put


speed controlled via PWM
bi-directional

permanent magnet spins


only 1 step per signal
wiring sucks, see notes
step pattern:

3 wires: ground, power,

Stepper

Servo

signal

PWM controls position.


standard freq is 50Hz
General C
dont be bad at c
Number Systems
Binary (base 2)
2s compliment (swap 0
and 1 for negative #)
negative if most sig fig =
1
Decimal (base 10)
Hexadecimal (base 16)

watch for overflow


Numeric Variable Types
integer
storage: 16 bits
unsigned: min = 0, max = 65535
signed: min = -32768, max = 32767
special math
float
storage: about 6 sig figs worth
avoid ==, approximated
dont use if you dont have to
long
storage: 32 bits
unsigned: min = 0, max = 4,294,967,295
signed: min = -2,147,483,648 max = 2,147,483,647
Arrays
store and define things
ASCII
use chart. Im not putting it here
be careful of things like 8 and such.
char
storage: 8 bits
unsigned: min = 0, max = 255
signed: min = -128, max = 127
operators?
see last page.
Special Function Registers
Analog vs Digital

use chart with ADCON1

clock speed, default to 1 MHz

OSCCON

instruction cycle clock speed / 4


TRIS and PORT
TRIS: 8 bits, 0 = output, 1 = input

TRISA = 0b0100 0000, RB1 is input,

rest are output


PORT: 8 bits, 0 = on, 1 = off
follows same ordering as TRIS

Delay Library

LCD

Delays can only have up to 255 in them


Delay1TCY(); only delays one tick
each delay is one tick or 1/((clock speed)/4)
includes

LCDModule.h
LCDModule.c

start with XLCDInit();


use XLCDClear();
use XLCDL1home() or XLCDL2home() depending

print things

how to use

on line

XLCDPut(letter)
sprintf(words, string to print on line

%d , lineNumber);
XLCDPutRamString(words);

functions

Timers

really?

openTimerx
ReadTimerx
WriteTimerx
Timer calculations:
Instruction cycle frequency = (clock frequency) / 4
Timer frequency = (instruction cycle frequency) /
pre-scaler
Timer period = 1 / (Timer frequency)
rollover every 65536 ticks
1 tick = 1 Timer Period
see chart for how to set up
Push Button Interrupts
RB0, RB1, RB2
make sure to debounce
see chart for how to setup
ADC
use default values for OpenADC(config1, config2, portconfig)
portconfig is # of analog pins, up to 12. See previous chart
use 0x00 or 0b0000 0000
SetChanADC(ADC_CH#); # is pin#
ConvertADC()
while(BusyADC());
result = ReadADC();
0 - 1024
7-seg displays

Datasheet for TI SN74LS47N:

Light Sensors

Light hitting detector: 0V signal


No Light: 5V signal
Adjust detector resistor so
Emitters appear Clear, Detectors appear Black

Emitter Max Current: 60mA, 1.6V

In the words of Dr. Fisher consult the datasheet, and do trial and
error. You dont want the fluorescent room lights to set it off, so adjust the resistor
so it doesnt.

PWM

Frequency = Cycles/second
duty cycle = % of time signal is high
first, OpenTimer2(TIMER_INT_OFF & T2_PS_1_#), # = 1, 4, 16
then OpenPWM1(period) or OpenPWM2(period)
period is frequency
SetDCPWM1(duty cycle) or SETDCPWM2(duty cycle)
use two pwm pins
frequency math:
PWM period = [(timer ticks) + 1] * 4 * Tosc * (TMR2
prescaler)
timer ticks is the period you put into OpenPWM1 (0255)
frequency = 1/(PWM period)

UART

OpenUSART(stuff & more stuff, #)


# is used to calculate baud rate.
baud rate high speed: Fosc / (16 * (# + 1))
baud rate low speed: Fosc / (64 * (# + 1))
uses printf
sends 10 bits (start bit, least significant-most significant, stop bit)
low at 0, then go to 8 then high again
remember, least significant digit (ie last) first
is 1/(baud rate) in seconds (or microseconds)

PLC and FSM


look at notes (its easy)

Anda mungkin juga menyukai