MECH 400 - University of Victoria

Download Report

Transcript MECH 400 - University of Victoria

MECH 400
Adam Schuetze: [email protected]
Outline for today

Motor control with a Pololu MD03A

Solenoid control with a MOSFET

Digital input hardware

Pressure sensor acquisition with a SenSym ASDX

Sequential versus event driven controller
Motor control with a Pololu MD03A

Encapsulate with oUserClass object:
oUserClass Motor = New oUserClass(“MD03A.osc”);

Create an interface to access motor functions
Motor.cw(127);
Motor.ccw(127);
Motor.stop;

Hide technical details inside the object

oPWM and oDio1 objects
Motor control with a Pololu MD03A
MD03A.osc
oPWM pwm = New oPWM;
oDIO1 inA = New oDIO1;
oDIO1 inB = New oDIO1;
sub void Config(bit motor_num){
ooPIC.PullUP = cvTrue;
pwm.Operate = cvOff;
pwm.IOLine = motor_num;
pwm.DutyCycle = 0;
pwm.PreScale = 2;
pwm.Period = 255;
if (motor_num == 0){
inA.IOLine = 26;
inB.IOLine = 27;
}
else {
inA.IOLine = 24;
inA.IOLine = 25;
}
inA.Direction = cvOutput;
inA.State = cvOff;
inB.Direction = cvOutput;
inB.State = cvOff;
pwm.Operate = cvOn;
}
sub void stop(void){
inA.State = cvOff;
inB.State = cvOff;
pwm.DutyCycle = 0;
}
sub void cw(byte speed){
inA.State = cvOn;
inB.State = cvOff;
pwm.DutyCycle = speed;
}
sub void ccw(byte speed){
inA.State = cvOff;
inB.State = cvOn;
pwm.DutyCycle = speed;
}
Motor control with a Pololu MD03A
Motor control with a Pololu MD03A
oUserClass Motor = New oUserClass("MD03A.osc");
const FWD_SPEED = 127;
const REV_SPEED = 127;
const FWD_BUTTON = 5;
const REV_BUTTON = 6;
const STOP_BUTTON = 7;
const MOTOR_PORT = 0;
oButton ForwardButton = New oButton;
oButton ReverseButton = New oButton;
oButton StopButton = New oButton;
oWire ForwardWire = New oWire;
oWire ReverseWire = New oWire;
oWire StopWire = New oWire;
oEvent Forward = New oEvent;
oEvent Reverse = New oEvent;
oEvent Stop = New oEvent;
Sub void Forward_CODE(void){
Motor.cw(FWD_SPEED);
}
sub void main(void){
Sub void Reverse_CODE(void){
Motor.ccw(REV_SPEED);
}
Motor.Config(MOTOR_PORT);
Sub void Stop_CODE(void){
Motor.stop;
}
OOPIc.Delay = 1000;
ForwardButton.IOLine = FWD_BUTTON;
ReverseButton.IOLine = REV_BUTTON;
StopButton.IOLine = STOP_BUTTON;
ForwardWire.Input.Link(ForwardButton);
ForwardWire.Output.Link(Forward.Operate);
ReverseWire.Input.Link(ReverseButton);
ReverseWire.Output.Link(Reverse.Operate);
StopWire.Input.Link(StopButton);
StopWire.Output.Link(Stop.Operate);
ForwardWire.Operate = cvTrue;
ReverseWire.Operate = cvTrue;
StopWire.Operate = cvTrue;
}
Solenoid control with a MOSFET

To drive a solenoid with logic-level power, you can use
an n-channel logic level MOSFET

When digital output pin is high,
gate is saturated
Solenoid control with a MOSFET

Encapsulate with oUserClass object:
oUserClass Valve = New oUserClass(“Solenoid.osc”);

Create an interface to access solenoid functions
Valve.Open;
Valve.Closed;
Valve.Invert;

Hide technical details inside the object

oDio1 object
Solenoid control with a MOSFET
Solenoid.osc
oDio1 Coil = New oDio1;
sub void main(void){
}
sub void Config(Byte IOPort){
Coil.IOLine = IOPort;
Coil.Value = 0;
Coil.Direction = cvOutput;
}
sub void Open(void){
Coil.Set;
}
sub void Closed(void){
Coil.Clear;
}
sub void Invert(void){
Coil.Invert;
}
Digital input hardware

Pull-up resistor circuit

Size resistor to limit
current into signal pin to
~1 mA

When circuit is open,
signal reads 5V

When circuit is closed,
signal reads 0V
Digital input hardware

Encapsulate with oUserClass object:
oUserClass LimitSwitch = New oUserClass(“DigIn.osc”);

Create an interface to access functions
LimitSwitch.Config();
oByte State = New oByte;
State = LimitSwitch.State;

Hide technical details inside the object

oDio1 object
Digital Input Hardware
DigIn.osc
oDio1 Hardware_Object = New oDio1;
sub void main(void){
}
sub void Config(Byte IOPort){
Hardware_Object.IOLine = IOPort;
Hardware_Object.Value = 0;
Hardware_Objectl.Direction = cvInput;
}
function Bit State(void){
State=Hardware_Object.Value;
}
Pressure sensor acquisition with a SenSym ASDX

Analog device with three conductors:



+Vs (power to the device)
Vout (signal from the device)
GND

Manufacturer specifies V/psi

Calibration is useful to confirm response

Use oA2D10 object

Other analog input devices can be treated the same
Pressure sensor acquisition with a SenSym ASDX

Encapsulate with oUserClass object:
oUserClass Depth_Sensor = New oUserClass(“SenSym.osc”);

Create an interface to access solenoid functions
oWord TheDepth = New oWord;
TheDepth = DepthSensor.Depth

Hide technical details inside the object

oA2D10 object
Pressure sensor acquisition with a SenSym ASDX
SenSym.osc
oA2D10 PressureSensor = New oA2D10;
sub void Config(Byte IOPort){
PressureSensor.IOLine = IOPort;
PressureSensor.Operate = cvTrue;
}
//Returns depth in centimeters
function Word DepthCM(void){
Word Signal;
Signal = PressureSensor.Value;
if (Signal < 102) {Signal = 102;};
DepthCM = ((Signal*20 - 2040)*10)/153;
}
function Word Voltage(void){
Voltage = PressureSensor.Value;
}
Pressure sensor acquisition with a SenSym ASDX
oUserClass DepthSensor = New oUserClass("SenSym.osc");
oWord TheDepth = New oWord;
oWord TheSignal = New oWord;
sub void main(void){
DepthSensor.Config(4);
while (1){
TheDepth.Value = DepthSensor.DepthCM;
TheSignal.Value = DepthSensor.Voltage;
}
}
Sequential versus event driven controller

sequential control scheme


if and while loops
state machines
VERSUS

Event driven virtual circuits

oWire, oEvent, oCompare
Summary of today

Motor control with a Pololu MD03A

Solenoid control with a MOSFET

Digital input hardware

Pressure sensor acquisition with a SenSym ASDX

Sequential versus event driven controller