May 17, 2024, 10:45:52 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Just starting - have questions

Started by suprvulcan, January 10, 2009, 01:24:43 AM

Previous topic - Next topic

suprvulcan

I have a few questions about the prop controllers. I have a project in mind and need more details. The prop board would be installed in a car and the inputs coming from a switched +12 Vdc source. I believe, if I read the documents right, the board needs +5Vdc or 0 for inputs. I haven't found a lot of information, yet, on setting up this type of input to be powered from an external source and not the board itself. I know there are a few ways of knocking down a voltage of this level to the levels mentioned but do you know of a preferred method to use if 5 vdc levels are not available?

The project would be acting as a keyless ignition controller, replacing the actual key switch only. Now on the vehicle I'm planning this for that means five outputs, three relay circuits (standard Bosch automotive relays) and two LED's. The inputs would be two switched safeties, a tachometer input, and the actual push to start button itself. Depending on the status of the safeties when you push the start button the controller either starts the car or turns on the accessory circuits so you can do something like listen to the radio. When your done another push on the button shuts off the car. Being new to this type of board and this type of programming language I am not sure if the prop-2 would do the job or if something more like the prop-sx would be needed. I'm not sure if I need multitasking yet. As I learn more about this hardware and how to program with this language I may have a better idea but right now the prop-2 seems like it may work. 

I'm curious to hear any thoughts or ideas you have on a project like this.

Thank you.

suprvulcan

I wanted to add a little more information. The logic would need to look at the inputs and the outputs to decide what to do on the next button push. There would be several different options to choose from depending on the I/O status. That is one reason I'm not sure if multitasking is neccessary yet. Also, if your curious, the power to the board would controlled by the starter enable/disable circuit on an rfid car security alarm. You have an rfid token in your pocket or wallet and as you walk up to the car the alarm disarms and enables the starter circuit which switches on power to the prop controller. You then simply get in push the button and go. When your done and you walk away from the car the security alarm disables the starter circuit shutting off the power to the prop controller and arming the alarm.

I know this isn't the usual project type special affect I see mentioned on this board, but I've looked around and this is the first controller board I've found that is fully self contained. I don't have to go and buy the chip, then build a board, then build the i/o ciruits, etc. Finally something I can use right out of the box.

JonnyMac

We do all kinds of projects with our products -- a lot of them don't get coverage in these forums.

You can probably handle the whole works with a Prop-2.  You didn't say what you want to do with the tach input so I reserve the right to change my mind later.  That said, the Prop-2 has a COUNT function that can be used with the tach, depending of course on how you want to use that input.

So long as the Prop-2 board is referenced to the same ground as the 12v input signals, you can use a simple divider to make the 12v inputs safe -- like this:



This is a very involved project so you'll want to make sure you have everything very well planned as you move forward designing the code.  Once you're sure about how the code should operate it should be a fairly straightforward project.
Jon McPhalen
EFX-TEK Hollywood Office

suprvulcan

The tach input would be used during the start cycle to help determine when the engine has started. When you have your foot on the brake and the car in park while pushing the start button the code would engage the "on" circuit relay and the "start" circuit relay. It would keep the start circuit relay on for a predetermined amount of time or until the tach input was above a certain level indicating the engine was running. After it turns off the start relay it would then turn on the Acc circuit relay. At this point the car is running just like you had turned the key to start the car.

JonnyMac

January 10, 2009, 11:56:11 AM #4 Last Edit: January 10, 2009, 11:59:39 AM by JonnyMac
No worries, then, other than conditioning the tach signal into the controller.  You can sample the tach input for a short duration, say 1/4 second, to determine if the engine is running.  The code might look something like this:

Start_Car:
  StartRelay = IsOn
  DO
    COUNT TachIn, 250, cycles
  LOOP UNTIL (cycles >= ENGINE_RUNNING)
  StartRelay = IsOff
  AccRelay = IsOn


My SUV idles at about 1100 rpm; this works out to 18 rps, which means in 1/4 second I should see 4 or so pulses on the tach input.  The ENGINE_RUNNING constant would be set to match what you expect to see from your engine.
Jon McPhalen
EFX-TEK Hollywood Office

suprvulcan

here is the first write of the code. My programming has mostly been on my employeers own language. I can read this code but my experience with writing this code from scratch is a little lacking. With that said this code may change a lot as I get more knowledge. Is there a better way of doing the logic then using the IF..Then..ElseIf statements? Would the Select..Case arguement be a better way?

' =========================================================================
'
'   File......Keyless_Control.BS2
'   Purpose...Keyless Ignition Controller
'   Author....Jeff E.
'   E-mail....suprvulcan@comcast.net
'   Started...1-07-2009
'   Updated...1-10-2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'This program is designed to run on a Prop-2 board. It is a keyless ignition
'controller. There are two switched safety inputs, One momentary "push to
'start" pushbutton and five outputs which are three standard Bosch automotive
'relay outputs(ACC, ON, & Start)and two LED outputs to indicate status. One for
'the system is on and ready, and another one for the on and running condition.


' -----[ Revision History ]------------------------------------------------
'1-10-2009 Initial program write-up.


' -----[ I/O Definitions ]-------------------------------------------------

AccRelay                   PIN           0       ' Accessory relay output
OnRelay      PIN   1       ' On relay output
StarterRelay   PIN   2       ' Starter relay output
ReadyLed    PIN   3       ' Blue Ready Led
RunningLed   PIN   4       ' Grenn Running Led
RPM      PIN          12     ' SETUP = UP - Tachometer input
Brake                       PIN          13     ' SETUP = UP - Brake Pedal input
Park                         PIN          14     ' SETUP = UP - Park/Neutral input
StartBtn                   PIN          15     ' SETUP = UP - Push to Start button input




' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1               ' for active-high in/out
IsOff           CON     0   

ENGINE_RUNNING   Con  4      ' 1/4 second sample time rpm reading

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T38K4       CON     45
  #CASE BS2PX
    T2400       CON     1646
    T38K4       CON     84
#ENDSELECT


' -----[ Variables ]-------------------------------------------------------

timer                        VAR          Byte
SafetiesGood   VAR   Bit   'Brake pedal depressed and gear in park
CarRunning   VAR   Bit   'true after start cycle completes
StartBtnCnt   Var   Nib   'used for emergency shutoff logic



' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTS = $0000                  ' clear all outputs
  DIRS = $07FF                    ' make P0-P10 outputs
  ReadyLed = IsOn              ' Indicates the system is ready

' -----[ Program Code ]----------------------------------------------------

Main:
    StartBtnCnt = 0
    Timer = 0
    Do
      If StartBtn = 1 then
        StartBtnCnt = StartBtnCnt + 1
      End if
    Loop While StartBtn = 1
 
  If Brake = IsOn and Park = IsOn then SafetiesGood = 1
      Else SafetiesGood = 0
    EndIf

  If StartBtnCnt >= 3 then    'emergency shutoff logic
      ShutOff_Car        
    EndIf              

  If SafetiesGood = 1 and CarRunning = 0 and StartBtn = IsOn then
   Start_Car            
    ElseIf SafetiesGood = 0 and CarRunning = 0 and StartBtn = IsOn then
   AccRelay_Only
    ElseIf SafetiesGood = 0 and CarRunning = 1 and Park = IsOn and StartBtn = IsOn then
   ShutOff_Car
    ElseIf SafetiesGood = 0 and CarRunning = 0 and AccRelay = IsOn and StartBtn = IsOn then
   ShutOff_Car
    ElseIf SafetiesGood = 1 and CarRunning = 1 and StartBtn = IsOn then
   ShutOff_Car
    EndIf

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


Start_Car:
  If AccRelay = IsOn then AccRelay = IsOff
    EndIf
  OnRelay = IsOn
  StartRelay = IsOn
  DO
    COUNT TachIn, 250, cycles
    Timer = Timer + 1000
  LOOP UNTIL (cycles >= ENGINE_RUNNING)(Timer = 4000)
  StartRelay = IsOff
  AccRelay = IsOn
  CarRunning = IsOn
  ReadyLed = IsOff
  RunningLed = IsOn


Shutoff_Car:
  OnRelay = IsOff
  AccRelay = IsOff
  CarRunning = IsOff
  Reset            'goto reset after car is shut off
 

AccRelay_Only:
  AccRelay = IsOn

' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

suprvulcan

An after thought, I don't think the Do..Loop I put into the Start_Car section will work the way I want. I wanted the starter to run for 4 seconds or until the engine rpm's was above the limit set up in logic. Which ever comes first.

JonnyMac

Here's how I would approach the start situation:

Start_Car:
  AccRelay = IsOff
  StartRelay = IsOn
  timer = 0
  DO
    COUNT RPM, 250, cycles
    timer = timer + 250
    IF (cycles >= ENGINE_RUNNING) THEN
      carRunning = IsOn
      RunningLed = IsOn
      ReadyLed = IsOff
      AccRelay = IsOn
      EXIT
    ENDIF
  LOOP WHILE (timer < 4000)
  StartRelay = IsOff
  RETURN


This will try to start the car for up to four seconds.  Notice the logic inside the DO-LOOP: when the tach input indicates the engine is running we set the "running" mode stuff and abort the DO-LOOP with EXIT.  The logic behind this version is that if the RPMs never come up the car won't be marked as started after four seconds -- the code returns to the caller where the flags can be checked to validate engine status.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

January 11, 2009, 11:00:01 AM #8 Last Edit: January 11, 2009, 11:24:53 AM by JonnyMac
Full disclosure: I'm exhausted from working a gajillion hours on a project that I'm disparately trying to finish -- I'm running on Starbucks and not much sleep.  In the short break I could take this morning I spent a little time with your code.

After looking through the program a couple times I think I found a way to simplify the logic.  One way is to move the bit flags into a single byte so they can be treated as one value; using BRANCH as I do below is a lot simpler than a multi-stage IF-THEN-ELSE construct.  I've also added a debouncing routine that validates the start, park, and brake inputs.

Look over the program and see if this helps.  Keep in mind that the PBASIC editor has helpful help: you can highlight a PBASIC keyword by double-clicking; then press the [F1] key and you'll be taken to that keyword in the help file.

' =========================================================================
'
'   File...... Keyless_Control.BS2
'   Purpose... Keyless Ignition Controller
'   Author.... Jeff E. (modified by J. Williams)
'   E-mail.... suprvulcan@comcast.net
'   Started... 01-07-2009
'   Updated... 01-11-2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program is designed to run on a Prop-2 board. It is a keyless
' ignition controller. There are two switched safety inputs, One momentary
' "push to start" pushbutton and five outputs which are three standard Bosch
' automotive relay outputs(ACC, ON, & Start)and two LED outputs to indicate
' status. One for the system is on and ready, and another one for the on
' and running condition.


' -----[ Revision History ]------------------------------------------------
'
' 1-10-2009 Initial program write-up.


' -----[ I/O Definitions ]-------------------------------------------------

StartBtn        PIN     15                      ' SETUP = DN
Park            PIN     14                      ' SETUP = DN
Brake           PIN     13                      ' SETUP = DN
RPM             PIN     12                      ' SETUP = DN

RunningLed      PIN     4                       ' Grenn Running Led
ReadyLed        PIN     3                       ' Blue Ready Led
StarterRelay    PIN     2                       ' Starter relay output
OnRelay         PIN     1                       ' On relay output
AccRelay        PIN     0                       ' Accessory relay output

' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0


ENG_RUNNING     CON     4                       ' 1/4 sec sample time


' -----[ Variables ]-------------------------------------------------------

flags           VAR     Byte
goodSafties    VAR     flags.BIT0
goodStart      VAR     flags.BIT1
carRunning     VAR     flags.BIT2

idx             VAR     Byte                    ' loop controller
check           VAR     Byte                    ' for input debouncing
cycles          VAR     Word                    ' for tach input

timer           VAR     Word


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00011111           ' P0 - P4 are outputs

  GOSUB Release_Start                           ' prevent cycling
  ReadyLed = IsOn


' -----[ Program Code ]----------------------------------------------------

Main:
  GOSUB Scan_Inputs                             ' validate inputs

  ' logic table for "flags"
  '  S = safties
  '  G = start (go)
  '  R = running
  '
  '  %RGS
  '  %000 - do nothing
  '  %001 - do nothing
  '  %010 - toggle acc relay status
  '  %011 - start car
  '  %100 - do nothing
  '  %101 - do nothing
  '  %110 - stop car if in park
  '  %111 - stop car

  BRANCH flags, [Main, Main, Acc, Start_Car,
                 Main, Main, Stop_Car, Reset]


Acc:                                            ' flags = %010
  AccRelay = ~AccRelay                          ' toggle Acc relay status
  GOSUB Release_Start
  GOTO Main

Start_Car:                                      ' flags = %011
  StarterRelay = IsOn
  timer = 0
  DO
    COUNT RPM, 250, cycles
    timer = timer + 250
    IF (cycles >= ENG_RUNNING) THEN
      carRunning = Yes
      OnRelay = IsOn
      AccRelay = IsOn
      RunningLed = IsOn
      ReadyLed = IsOff
      EXIT
    ENDIF
  LOOP WHILE (timer < 4000)
  StarterRelay = IsOff
  GOTO Main

Stop_Car:                                       ' flags = %110
  IF Park = IsOn THEN Reset
    GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

Scan_Inputs:
  goodSafties = No                              ' assume off
  goodStart = No
  check = %11100000                             ' mask start, park, brake
  FOR idx = 1 TO 10                             ' set up 0.1 sec scan
    check = check & INH                         ' scan inputs
    PAUSE 10
  NEXT
  goodStart = check.BIT7                        ' copy start bit
  check = check & %01100000                     ' isolate park & brake
  IF check = %01100000 THEN
    goodSafties = Yes
  ENDIF
  RETURN

' -------------------------------------------------------------------------

Release_Start:
  GOSUB Scan_Inputs
  IF goodStart THEN Release_Start
    RETURN


' -----[ User Data ]-------------------------------------------------------


Jon McPhalen
EFX-TEK Hollywood Office

suprvulcan

Thank you very much for your help. I definitely don't want to take you away from your own projects. I do have a question, you put in a subroutine called release_start. Is this the debounce you mentioned above? I see the statement "IF goodStart THEN Release_Start" in the release_start subroutine, does this cause the subroutine to call to itself when goodstart is true? You have goodstart tied to check.bit7 which is the start button input. I'm not sure I follow that logic yet. But I'll keep reading.

I do like the branch method more then the If..Then..Else.

I need to add a variable(emerg_stop) and some more code to the stop_car section to include the function of shutting off the car in an emergency if the start button is pushed in for more then 3 seconds even if its not in park. Probably something like this.

Stop_Car:                                       ' flags = %110
  IF Park = IsOn THEN Reset
  Timer = 0
  DO WHILE (StartBtn = IsOn)
    Timer = Timer + 250
    IF (Timer >= Emerg_Stop) THEN Reset
  LOOP
    GOTO Main

JonnyMac

It seems to me that you'll want to force the user to release the Start button in parts of the process -- that's the function  of Release_Start section; it will hold the program until the start button is released.

Here's how you could update the Stop_Car section to watch for a 3-second emergency stop condition.  Remember that the debounce routine (Scan_Inputs) takes 100ms so there is timing built in already.

Stop_Car:                                       ' flags = %110
  IF Park = IsOn THEN Reset

  timer = 0

E_Check:
  GOSUB Scan_Inputs
  IF goodStart = Yes THEN
    timer = timer + 100
    IF timer = 3000 THEN Reset
      GOTO E_Check
  ENDIF
  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

suprvulcan

I had not thought about making them release the start button. Just a push to start/stop option with anything more then 3 seconds automatically shutting off the car no matter what.  Does the new E_Check section need to be included in the branch options?

johnb

Hi there,
In general, it is a good idea to force the user to release a pushbutton especially when controlling machinery.  Consider the case of an falling object that lands and rests on the switch.  It would be better for the code to stall, waiting for the switch to be released,  rather that starting motors, etc. 
I haven't really read through the whole thread, this suggestion comes from a lot of experience and good practices learned the hard way (sometimes).

John B
EFX-TEK

JonnyMac

Quote from: suprvulcan on January 12, 2009, 10:25:08 AM
I had not thought about making them release the start button. Just a push to start/stop option with anything more then 3 seconds automatically shutting off the car no matter what.  Does the new E_Check section need to be included in the branch options?

No -- the Car_Stop branch falls through to E_Stop if the car is not in park; Car_Stop is called when the car is running and the Start button is pressed, but the safeties are not engaged -- this is the point where you  would check an emergency stop condition.
Jon McPhalen
EFX-TEK Hollywood Office

suprvulcan

Okay, I see it now. Not sure why I missed that, maybe it was the "E_Check:" all the way to the left that threw me off. I understand the release start logic now, it is does seem like a good idea and it wont take away from the operation overall. As long as the 3 three second emergency shut off is in place it should be okay.

I'm trying to mimic the operation of the modern keyless ignition systems you see on some of the newer cars. Most of them have some kind of emergency shut off method. Most of what I've looked at have either a 3-5 second hold on the start buttton or 3 quick presses of the start button or either one to shut off the car in an emergency. I thougt a 3 second hold on the start button would be enough and since it's going in my car when it's done I know exactly how it is supposed to operate.

Thanks again.