Greetings from Newbie and a question


Results 1 to 10 of 10

Threaded View

  1. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    94


    Did you find this post helpful? Yes | No

    Default Pretty good

    Hi and welcome,

    that's pretty good code for a newbie but can I make a couple of suggestions to make life easier for yourself (not that I'm a pro by a long shot!):

    1). At the start of your program set up some variables so that you don't need to keep referring to which pin does what. By this I mean:

    'INPUTS
    Pressure_sw var portb.4 'Pressure_sw could be anything really so it could be smaller, say prsuresw instead or whatever you want that's easy to remember!
    Wlevel_sw var portb.5
    vaccum_sw var portb.6
    'etc,etc

    'OUTPUTS
    Airpump_relay var portc.0
    'etc,etc

    now in your program you can write:

    while Pressure_sw = 1 'Turn air pump on while pressure switch hi
    Airpump_relay = 1 'Keep it on until pressure is high enough
    wend
    Airpump_relay = 0 'Turn off air pump now that it is ready

    This is just a suggestion but it makes things a lot easier to read (especially when you come back to a program several months later!)

    2). Using the 'else' command I noticed you had problems so I thought I would re-write the code you posted with the proposed variables added and also showing how to use 'else'. You need to add a new line for the else and then add an endif after your instruction(s) also with their own lines:

    Code:
    '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 Pressure_sw = 1 'Turn air pump on while pressure switch hi
    Airpump_relay = 1 'Keep it on until pressure is high enough
    wend
    Airpump_relay = 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
    WATER_LOW = 1 'Pulse the LED while in this loop
    PAUSEus 500
    WATER_LOW = 0
    PAUSEus 500 
    Until Vac_sw = 1 and Temp_sw = 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 Pressure_sw = 1 then 
    Airpump_relay=1 
    else
    Airpump_relay=0
    endif
    'CheckWater Level
    If Wlevel_sw = 1 Then 
    Water_low=1
    else
    Water_low=0
    endif
    'Send pulse to injector while there is vacuum present.
    If Vac_sw = 1 Then PULSOUT Injector,50 
    'Check Temperature and restart if too low (wait for temp to come up) 
    If Temp_sw = 0 then AllOff: 
    Goto SensorCheck: 'Loop the sensor check unless temp goes low
    End
    I can't see where your problem is with the pump turning off but you could try commenting out this line:
    If portB.7 = 0 then AllOff
    or if you use the code I posted above, then it would be this line:
    If Temp_sw = 0 then AllOff

    I could be barking up the wrong tree but from a quick glance at your code I'm thinking the temperature switch might not be high?

    I hope this helps and your project sounds quite interesting

    Regards

    Rob
    Last edited by Rob; - 22nd July 2006 at 10:41.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts