P8055 and Phototransistor

I have a lap timer board for a Scalectrix set which uses phototransitors.

Is it possible to use these to trigger the inputs of a P8055 board?

I’ve tried the obvious of hooking the phototransistor to the digital inputs I1 and I2. The other side of the phototransistor goes to GND on the same block.

No joy.

Do I need to lower the resistance with another resistor in parallel perhaps?

Regards
Marty

If it is NPN phototransistor, you should connect the collector pin to the digital input (e.g. I1) and connect the emitter pin to the GND terminal. (The transistor must be “stand alone” - i.e. isolated from the circuit where it was connected in the lap timer board.)

There is 20k pull-up resistance on the K8055 board. This should be appropriate value.

When you give some light (or maybe infrared light) to the transistor, the effect should be same as pressing the digital input test button. - The digital input will be pulled down.

Hmmm.

Am thinking perhaps then that the difference in voltage may be causing me an issue.

Normally the timer board operates at 15V. (Scalectrix voltage)

I am only getting 5V off the P8055 in order to drive the LEDs.

Perhaps I need to adjust the resistor on the timer board down so that the LEDs get enough juice? I measured the resistor at 5k. The circuit looks like positive voltage goes through two LEDs and then a 5K resistor to GND.

Would I be correct in thinking that if the voltage is one third then I should also drop the resistor to one third of the current 5K?

Regards
Marty

[quote]Would I be correct in thinking that if the voltage is one third then I should also drop the resistor to one third of the current 5K?[/quote]Indeed, the LED current is too low at 5V.
The remaining voltage over the two LEDs is over 3V maybe. You should use quite low resistor to get the same current as there is with 15V.

Indeed.

From my poorly remembered high school electronics course I seemed to recall that two more 5k resistors added in parallel to the existing one would drop it to a third.

The board picks up the phototransistors perfectly now.

Thank you for the assist! I now have a pretty nice lap timer / race counter / stats recorder.

Regards
Marty

I am making a lapcounter for my track also
I have three lanes so need three counters

I have successfully tested the board with a simple version of lapcounting and have all 5 inputs counting a and recording fastest laps/switching track power on etc. However the problem I have is that I want the board to count when the beam is broken by a car, Currently it counts when the test button is pressed/beam is clear ie the reverse of what I want. Everything else works fine

Any help is much awaited

[quote]However the problem I have is that I want the board to count when the beam is broken by a car, [/quote]If I understand right, you want to count during the very short period of time when the beam is broken by a car?
Using the K8055 you can sample the digital input with 10ms interval. The resolution will be very bad to measure such a short period of time when the beam is broken by a car.

Not quite

I want to measure the time between the beam getting broken each lap not the length of time the beam is broken… ie each time a car crosses between the IR transmiter and receiver I want it to act like I have pressed the button on the board.

A car breaks the beam and a lap is registered and current time (T1) recorded. Next time a car breaks the beam the new current time (T2)is recorded, Therefore the lap time is T2 - T1 = lap time. This part works fine

(Hope I am making sense) So the test buttons would be replaced with momentary open ones

I used to use the old LPT ports but newer PCs dont come with them hence the move to USB.
Just got to crack this one small issue and I can start prettying up the programme

OK - I see.
I don’t think it is a big issue to invert the phototransistor pulse in the software.
You can also post some snippets of your code.

Code is Liberty Basic but the instructions should be readable
These calls are actioned when the relavent button is pressed

calldll #velleman, “ReadAllDigital”, channel as long, ret as long
count(channel)=ret
if count(channel) = 1 then call count11’calls lane 1
if count(channel) = 2 then call count22’call lane 2
if count(channel) = 4 then call count33
if count(channel) = 8 then call count44
if count(channel) = 16 then call count55
startime=time$(“ms”)
return

This is a sample sub for lane 1
sub count11
time1a = startime
IF time1b = 0 THEN time1b = time1a
IF time1a < time1b + 50 THEN GOTO [back1]
count(1)=count(1) +1
tb1 = time1a - time1b
tb1=tb1/1000
playwave “beep.wav”, async
print #main.cntr1text, count(1)
print #main.cntr11text, tb1
IF b1htid = 0 THEN b1htid = tb1
IF tb1 < b1htid THEN b1htid = tb1
print #main.cntr111text,b1htid
[back1]
time1b = time1a
end sub

I had some difficulties to understand the Liberty Basic code.
Anyhow I think I know what you want it to do.

I made an example code using the Visual Basic in Excel.

Here is the screenshot of the result:

Pressing the buttons are used to emulate the phototransistor operation.

This is the “core” of the lap time counter procedure:

Dim data As Long Dim diff As Long Dim i As Long timecounter = timecounter + 1 data = ReadAllDigital() If data > old_data Then ' check if any one of the digital inputs is activated (pulled down by the phototransistor or switch) diff = data - old_data For i = 0 To 4 If (diff And 2 ^ i) > 0 Then ' find the input who changed state lap(i) = lap(i) + 1 ' increment lap counter ActiveSheet.Cells(lap(i) + 1, i + 2) = 0.01 * (timecounter - time(i)) ' print the lap time in seconds on sheet time(i) = timecounter ' save the time counter value for this channel End If Next i End If old_data = data

This routine is inside a 10ms timer event handler.
The digital input of the K8055 is read.
The input value is compared to the previous input value.
If any one of the input channels has changed state from 0 to 1 then the input is checked more detailed.
The time counter value assigned to the input(s) who changed state is loaded with the global time counter value.
The lap time is printed on the Excel sheet.

Here is the complete script:

[code]Option Explicit
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Long

Private Declare Function SetTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Dim TimerID As Long
Dim TimerSeconds As Single
Dim time(0 To 4) As Long
Dim lap(0 To 4) As Long
Dim old_data As Long
Dim timecounter As Long

Sub Button1_Click()
Dim h As Long
Dim i As Long
timecounter = 0
old_data = 0
For i = 0 To 4
time(i) = 0
lap(i) = 0
Next i
h = OpenDevice(0)
If h = 0 Then
ActiveSheet.Cells(1, 7) = “Card 0 Connected”
TimerSeconds = 0.01 ’ the timer interval is now 0.01 sec.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
Else
ActiveSheet.Cells(1, 7) = “Card 0 Not Found”
End If
End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
On Error Resume Next
Dim data As Long
Dim diff As Long
Dim i As Long
timecounter = timecounter + 1
data = ReadAllDigital()
If data > old_data Then ’ check if any one of the digital inpus is activated (pulled down by the phototransistor or switch)
diff = data - old_data
For i = 0 To 4
If (diff And 2 ^ i) > 0 Then ’ find the input who changed state
lap(i) = lap(i) + 1 ’ increment lap counter
ActiveSheet.Cells(lap(i) + 1, i + 2) = 0.01 * (timecounter - time(i)) ’ print the lap time in seconds on sheet
time(i) = timecounter ’ save the time counter value for this channel
End If
Next i
End If
old_data = data
End Sub

Sub Button2_Click()
KillTimer 0&, TimerID
CloseDevice
ActiveSheet.Cells(1, 7) = “Card 0 Closed”
End Sub[/code]

Here is the link to download the Excel workbook including this VBA macro:
box.net/shared/gakgqb7dx6ltnfqbnfqk

This is almost exactly what i am trying to do with my K8055 Board. Do you think you could help me? This is actually on a full size 1/8th Drag Strip we are going to be using this on. What i am wanting to do is use Garage door sensors aka Photo sensors. When the beam breaks it starts the timer at start of the track and once you hit beams at end it stops timer and then displays for both sides times and who is the winner? Could i use your project to learn off of?

[quote]This is almost exactly what i am trying to do with my K8055 Board. Do you think you could help me?[/quote]Yes - if I can.

[quote]Could i use your project to learn off of?[/quote]Yes, you can use it as a “starting point”.

Please download also the latest software package for the K8055.
Here is the link to the download page:
velleman.eu/distributor/supp … code=K8055
Download the: “[color=#008000]Complete SDK Pack (Rev 4.0)[/color]”.

The package includes new K8055D.DLL and sample projects written in various programming languages. - Visual basic and Excel examples are included.
Pleas read the “README.TXT” and the “K8055 & VM110 Getting Started.pdf”.