Justin Fielding wrote: > > I am a newbie to Pic's (just got to the interrupts section in the Easy Pic'n book) and have thought of a great little project. I want to make a fault reader for my car's ECU. > > If the ECU detects a fault (can be simulated by disconnectiong something) then it pops the warning light on. You can then (bit of a quick hack) conect an LED accross two of the pins on the diagnostics port and short two out and it will flash a code on the LED. > > It first flashes 1 2 to let you know it is working, then the fault, say 2 6 and then 1 2 again. > > Trouble is it does this in a rather strange way, in the above example it would. > > Flash the LED once > Short pause > Flash the LED Twice > Long pause (so the above was "1" then "2" but this should be read as 12) > Flash LED Twice > Short pause > Flash the LED six times > Long pause ( representing "2" then "6" or 26) > and so on..... > > I would like to use an F84 with an input from the ECU (from where the LED goes) and then a LCD display to show what the fault is (use a lookup table here). > > Problem is how do I know the difference between the long and short pause (so I can stop counting flashes and move to the next digit) AND the big how... How do I turn "1" & "2" into 12 (for use in the lookup table)? > > Any help or tips from similar projects would be appreciated. > > Thanks. > > Justin. This psuedo code may help you decide what to do. I haven't had much time to test it obvously, but it may help. Loop Is Led On? No - goto Loop Yes - detected code start expecting '1' flash Test_1 Is Led Off? No - goto Test_1 Yes - detected 1st '1' start measuring pause The loop timing should be set so that X loop counts = a short pause The X value should fit easily into the register(s) assigned to count the loops. clear Pause_Count register(s) PseTest Is Led On? Yes - goto On_2 No - increment Pause_Count value goto PseTest On_2 The value in "Pause_Count" = a short pause Now you have a reference to determine long and short pauses. It may pay to add a small value to this to allow for discrepancies in the pulse time. subroutine to count flashes you are expecting 2, if not then error. call Flash is result = 2? No - Error Yes - Continue use the flash subroutine to get the next 2 digits. wait for led to come on again call Flash store result in Error_Code_1 wait for led to come on again call Flash store result in Error_Code_2 the next data should be 1 wait for led to come on again call Flash if data <> 1 then error the next data should be 2 wait for led to come on again call Flash if data <> 2 then error use a lookup table to return a 7 segment value for Error_Code_1 and display it use lookup table again to return a 7 segment value for Error_Code_1 and display it goto Loop - wait for next code Error flash 'E' on leds for a short time goto Loop - wait for next code this is the flash subroutine the LED will have just turned on when this routine is called. wait for it to go off and then use a loop to count how long it stays off. If it is longer than the short pause count then the pause is a "long pause". If it is a "short pause" then keep incrementing a flash counter Flash clear Flash_Count F_Loop is led off? no - goto F_Loop increment Flash_Count Now determine the pause length between flashes clear Test_Count PL_loop is led on?? yes - goto F_Loop no - increment Test_Count is Test_Count > Pause_Count ?? no - goto PL_loop yes - long pause return from subroutine data is in Flash_Count -- Best regards Tony mICros http://www.bubblesoftonline.com mailto:sales@bubblesoftonline.com -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body