Hello forum members, I recently discovered using a PIC in place of discreet electronic components and purchased a MikroElektronica prototyping board. It's totally awesome hardware and worth every penny of it's price, although the Basic programming environment is a bit sparse compared to PicBasic Pro. So I downloaded the demo version and am trying it out.
I have created a program to accomplish some process control that I need and am posting it below. Please keep in mind that I am REALLY a newbie - pretty much my first programming since high school on an Apple2e (showing my age) so be gentle please.
There are lot's of comments so it's pretty self explanatory as to what I'm trying to do. I'm using "Virtual Breadboard" (which I also think is terrific) to test my results. So far, this works "OK" but I would like the air pump to stay on without turning off until the switch is opened again. My test environment shows me that when the "PulseOut" is happening AND the air pump switch is on, it toggles the air pump relay on and off. I didn't expect that.
Could someone more experienced look at it and tell me how I could do it better or more efficiently (without learning assembly?)
Thanks to all who take the time:
'************************************************* ***************
'* Name : WaterInjectioncontrol.BAS *
'* Author : [Chris Helvey] *
'* Notice : Copyright (c) 2006 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 7/20/2006 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
' Author: Chris Helvey
' Date: 07/19/06
' Water Injection Sensor Program used to check the presence of a signal from
' the various sensors. Turn the system on after a delay of detecting
' vacuum. Check pressure switch and the water level float switch. When the
' pressure is too low, it will turn on a relay to the air pump and when
' the water is low 'will turn on a LED/Buzzer as a reminder (or a relay for a
' pump.).
'Switches are a +5V HIGH on the input
'Inputs (on Port B) are as follows:
'Pin4 = Pressure switch
'Pin5 = Water Level Float Switch
'Pin6 = Vacuum switch
'Pin7 = Temperature switch (preset value on the switch)
' Outputs (on Port C) are as follows:
'Pin0 = Air Pump relay
'Pin1 = "Water Low" LED or water pump relay
'Pin2 = Injector Power relay (not currently used)
'Pin3 = Injector "open" pulse
TRISB = %11111111 ' Set all PORTB to inputs
TRISC = %00000000 ' Set all PortC to outputs
AllOff:
PortC = 0 ' Turn off all outputs
'Initial Air Pressure check to get pump going 1st if needed
while PortB.4 = 1 'Turn air pump on while pressure switch hi
PortC.0 = 1 'Keep it on until pressure is high enough
wend
PortC.0 = 0 'Turn off air pump now that it is ready
InitialOn: 'Wait for vacuum and temp to come up
'and blink LED while waiting '
'LED pulse
Repeat
PORTC.1 = 1 'Pulse the LED while in this loop
PAUSEus 500
PORTC.1 = 0
PAUSEus 500
Until PortB.6 = 1 and PortB.7 = 1 'Check Vacuum and Temp
'Turn on injector power only if Vacuum
'is detected and temp is High enough
'Loop until ready
pauseus 1000 'Pause to be sure engine running
SensorCheck:
'Check Air Pressure
If PortB.4 = 1 then portc.0=1
' else portc.0=0 "Else" doesn't work added to above line or here.
If PortB.4 = 0 Then portc.0=0
'CheckWater Level
If PortB.5 = 1 Then portc.1=1
If PortB.5 = 0 Then portc.1=0
'Send pulse to injector while there is vacuum present.
If PortB.6 = 1 Then PULSOUT PORTC.3,50
'Check Temperature and restart if too low (wait for temp to come up)
If portB.7 = 0 then AllOff:
Goto SensorCheck: 'Loop the sensor check unless temp goes low
End
Bookmarks