New to PICAXE, looking for some advice on best practices.

mattstrike

New member
New to PICAXE, but have some basic questions (took a class in Java at one point).

I've decided to dive right into the project I'm working on, which is a stand-alone controller for the torque converter on my truck project. Using the 08m2, three 5v digital inputs, one analog input (switched to ground between 0-100hz), and a single output that will go to a transistor control of a relay.

First question I have, is if I use the command high C.5 (or any pin) over and over again, will it cause issues? Let's say that the code has previously resulted in a C.5 high, then loops back to the beginning, then C.5 high comes up again does it have a problem if it's already at the high state? My initial thought was that it might cause instability and that the code should check the status, and only execute C.5 high if it's not already high. But I couldn't figure out how to check C.5 for it's current state before commanding high C.5

Here's an excerpt from what I'm trying to accomplish (I was going to post the full code, but limited by characters):


Code:
Sensor0:                                     ;Label Sensor0 - read sensors
;    pause 500                                ;optional wait 500ms
    Count C.3, 1000, speed                        ;VSS - Count pulses over 1 second, output variable is named speed
    ReadADC C.1, throttle                        ;TPS - Read sensor, output variable named throttle
    ReadADC C.2, boost                        ;MAP - Read sensor, output variable named boost
    goto Main0
    
    ;Current state variables defined.  

    ;Begin Main Logic 


Main0:                                    ;Label Main0.
    if speed < v_0 then                        ;If speed is less than 25mph
        goto TCC1                        
    end if
    if speed > v_0 then                        ;if speed is greater than 25mph
        if throttle < t_0 and boost < b_0 then        ;if throttle is less than 20% and boost less than 2.5psi
            goto TCC0
        end if
        goto TCC1
    end if
;TCC processes               

TCC0:                                        ;label TCC0
    high TCC                                ;turn on TCC
    goto Sensor0                            ;loop back to sensor read
    

TCC1:                                        ;label TCC1
    low TCC                                ;Turn off TCC
    goto Sensor0                            ;Loop back to sensor read
I guess I thought that TCC0: and TCC1: processes should be able to poll the current state of C.5 and only run if the state is not already set.



My second question is related to how one of the input signals works. VSS output from the vehicle PCM is described as follows:
Code:
;            The vehicle speed sensor in the trans is a permanent magnet generator that produces a sine wave output.
;            That signal is fed to the PCM, which uses it to produce a vehicle speed output signal
;            that is switched to ground at a frequency of 4000 pulses per mile.
;            That output is pulled up to 5V or higher by the speedometer, cruise module, etc.
In my application, there is nothing connected to this PCM output. So I think this means that I need to make sure that this input has a pull-up resistor to make sure it gets to 5v - the VSS signal won't exceed 100hz - how do I calculate the correct pull-up resistor if it's connected to the 5v input for the PICAXE?

I can post more details (circuit, code) if I need, let me know.
 

hippy

Technical Support
Staff member
Welcome to the forum.

Setting outputs high should have no effect if already set high, and the same for low, nor cause adverse issues.

Reading your PCM output as an input should mostly just be a matter of connecting that output to a PICAXE digital input. It would be necessary to put a resistor in-line with the connection to prevent any issues if the input is accidentally or inadvertently made an output, and to cater for the fact the PCM may output more than 5V.

The PCM output of 4000 pulse per mile works out at 60 x 4000 in an hour at 60 mph. Those 240000 pulses per hour, are 4000 pulses per minute, 66.6 per second, one every 15ms.

Accurately trying to determine speed with a one second count is going to be difficult, and will also slow things down, make everything somewhat unresponsive, but you could time the pulses and determine the speed that way.

Whether things will be fast enough would depend on what you are attempting to achieve, what your TCC0 and TCC1 control.
 

lbenson

Senior Member
Welcome to the forum.

The simulator is your friend.

The first thing you would find if you tried to make C.5 high on the 08M2 is that pin C.5 is input only:

do: high c.5: pause 1000: low c.5: pause 1000: loop

(And note that C.5 is the SERIN pin for downloading, so if you issue a DISCONNECT and use C.5 as an input, you would have to do a "hard reset" (cycle power off and on after clicking "Download") in order to download a new program--and C.5 must not have a pullup resistor on it when powering up--in fact, must be low on power-up).

Otherwise, for an output pin, you can repeat, for instance, HIGH C.4 as often as you like.
 

premelec

Senior Member
AND don't ever leave the input pin floating - resistor to V- or input circuit does the job...
 

Hemi345

Senior Member
what happens if the speed = 25mph? Answer: it'll fall into your TCC0 function regardless of throttle position or boost pressure.

I would rewrite your code as follows as it is easier to follow than using a bunch of goto statements:
Code:
do
    Count C.3, 1000, speed                     ;VSS - Count pulses over 1 second, output variable is named speed
    ReadADC C.1, throttle                      ;TPS - Read sensor, output variable named throttle
    ReadADC C.2, boost                         ;MAP - Read sensor, output variable named boost
    if speed < v_0 then                        ;If speed is less than 25mph
        low TCC                                ;Turn off/unlock TCC
    else                                       ;if speed is greater than or equal to 25mph
        if throttle < t_0 and boost < b_0 then ;if throttle is less than 20% and boost less than 2.5psi
            high TCC                           ;turn on/lock TCC
        else
            low TCC                            ;Turn off/unlock TCC
        end if
    end if
loop
 

Hemi345

Senior Member
What if noise on pin C.3 shows up while idling through a parking lot or while trying to start the engine making your program think the speed is over 25 mph? You might also consider programming in a valid range for the "speed" variable. I'm just trying to think of things that might catch you up. Sounds like a cool project, I'd be interested in hearing/seeing how it turns out :cool:
 

mattstrike

New member
So the thing I was worried most about, the VSS "output" from the PCM (maybe calling it an output was wrong?) seems to be the right question to ask here. I assumed that because the wire is grounded by the PCM at the 4k PPM rate it should be considered an analog signal. The only reason I picked the count c.3, 1000 was because the math works out easier (25mph = 28 counts per second. 60 = 66).

Here's my actual pin assignment:
Code:
;PICAXE 08M2 pin assignments
;    pin 1 = +5v
;    pin 2 = C.5
;    pin 3 = C.4 ADC/IN/OUT 4.............ECT digital input 0-5v
;    pin 4 = C.3 IN 3.....................VSS analog input (switched ground)
;    pin 5 = C.2 ADC/IN/OUT/PWM 2.........MAP digital input 0-5v
;    pin 6 = C.1 ADC/IN/OUT 1.............TPS digital input 0-5v
;    pin 7 = C.0 OUT/SERIALOUT/INFRAOUT...TCC analog output to transistor circuit to control a relay
;    pin 8 = GND
;
Here's the TCC apply profile :

Code:
Main0:                                    ;Label Main0.
    if speed < v_0 then                        ;If speed is less than 25mph
        goto TCC1                       
    end if
    if speed > v_9 then                        ;if speed is greater than 70mph
        if throttle < t_9 and boost < b_4 then        ;if throttle is less than 20% and boost less than 2.5psi
            goto TCC0
        end if
        goto TCC1
    end if
    select speed                           
        case v_0 to v_1                        ;when vehicle speed is between 25 and 30
            if throttle < t_0 then                ;if throttle is less than 7%
                goto TCC0
            end if
            goto TCC1
        case v_1 to v_2                        ;vehicle speed 30-35
            if throttle < t_1 then                ;throttle under 10%
                goto TCC0
            end if
            goto TCC1
        case v_2 to v_3                        ;vehicle speed 35-40
            if throttle < t_2 then                ;throttle under 12%
                goto TCC0
            end if
            goto TCC1
        case v_4 to v_5                        ;speed 40-45
            if throttle < t_3 then                ;throttle under 14%
                goto TCC0
            end if
            goto TCC1
        case v_5 to v_6                        ;speed 45-50
            if throttle < t_4 then                ;throttle under 15%
                goto TCC0
            end if
            goto TCC1
        case v_5 to v_6                        ;speed 50-55
            if throttle < t_5 and boost < b_0 then    ;throttle under 16% and boost under 0.5psi
                goto TCC0
            end if
            goto TCC1
        case v_6 to v_7                        ;speed 55-60
            if throttle < t_6 and boost < b_1 then    ;throttle under 17% and boost under 1psi
                goto TCC0
            end if
            goto TCC1
        case v_7 to v_8                        ;speed 60-65
            if throttle < t_7 and boost < b_2 then    ;throttle under 18% and boost under 1.5psi
                goto TCC0
            end if
            goto TCC1
        case v_8 to v_9                        ;speed 65-70
            if throttle < t_8 and boost < b_3 then    ;throttle under 19% and boost under 2.0psi
                goto TCC0
            end if
            goto TCC1
    endselect
This profile was developed while towing a typical load, using values from a scan tool, based on a 600 mile drive (where I had to switch the toque converter on manually). It's not perfect and will need to be tuned, but thought it was a good start point.

To specifically address your point:
What if noise on pin C.3 shows up while idling through a parking lot or while trying to start the engine making your program think the speed is over 25 mph?
The transmission won't apply the torque converter in park, neutral, or 1st gear, even if got the +12v signal. It's limited by internal hydraulic circuits.
 

hippy

Technical Support
Staff member
So the thing I was worried most about, the VSS "output" from the PCM (maybe calling it an output was wrong?) seems to be the right question to ask here. I assumed that because the wire is grounded by the PCM at the 4k PPM rate it should be considered an analog signal.
From the description it seems to be an open-collector style output, so either floating, pulled up to +V, 5V or higher, potentially 12V or 24V, with an external resistor or pulled down to 0V. So it's a digital signal, +V or 0V, rather than analogue -
Code:
.----------------.    .--------- +V
|                |   .|.
|                |   |_|                  ___   ___   ___   ___
|                |    |   __           +V    | |   | |   | |
|            .---|----^--|__|--> PCM         | |   | |   | |
|            |   |                     0V    |_|   |_|   |_|
|        __|/    |
|          |\    |
|            |   |
|        ----^---|-------------- 0V
`----------------'
 Speed Monitoring
 
Top