Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need 6 channel digital input to PC

Status
Not open for further replies.

iwonder

New Member
Hi, i am at a loss after having scavenged the net for hours without finding any precise answers for this.
I have been asked to program a PC based scoreboard for Tae Kwon Do competitions which I will do in VB.
I need to register the 3 judge's inputs in this manner:
each judge has a hand control with two buttons - one for each contestant.
In order for a score to be registered, at least two of the judges have to push the same button within 2 seconds.

I was thinking that RS232 seems to be leaving the world of laptops, so parallell or USB (or USB via a port replicator) would probably be the way to go.

I am familiar with assembling electronic circuits, but not designing them so I was hoping maybe someone here would help me out...


Best regards
Jens
 
Hi:

There are many ways to go about that, such as designing a fully sequential state machine. However, I see two good options. The first on is using a small microcontroller (PIC's or AVR's are just fine). The issues here are you need to program the microcontroller (write code, and actually programming the hardware). Since most microcontorllers have UART's, RS232 is probably the way to interface with the PC. You could try USB, but will need an additional USB interface chip.

The second is to use the PC's parallel port directly. If the PC has an EPP you will have enough inputs as is. Older PC's probably have just SPP (four inputs), and you will have to multiplex the pushbutton inputs. You can then code everything in VB. Another issue here is some OS (Win2K, XP etc.) do not allow easy access to the parallel port. You will need special DLL's to give you that access.

Jem
 
Hi Jem,
the PCs used for this will always be laptops, meaning that ports are going scarce except for USB - i know they still supply the parallell port, but for how long?
I think a USB design would be the best way to go, but will I be able to make one? I know little about microcontrollers and programming them, but I can learn. Do you have any concrete suggestions on how I should proceed?


regards
jens
 
Hi Jens:

That's a fair enough answer. Here is how I would approach it then. Please bear in mind that like most engineers, I have my own bias toward certain components. First, I would use an Atmel AVR chip. I think a 90S2213 would be just fine for the job. You can get one for about $2.80 to $3.50 from Digikey (www. digikey.com). Mouser (www.Mouser.com) also sells them. You can get a basic system running with nothing more than a crystal, two caps (for loading the crystal), and a resistor and cap for teh reset. Then get over to www.atmel.com, and you will see tons of free SW (from assembler, to simulator, to a complete collection of code examples). You need to build a simple programmer. A simple one can be built for about $15 - $20. Go to: www.xs4all.nl/~sbolt/e-spider_prog.html, and you are on your way.

Now for the USB, I have used several FTDI chips. Check them out at:
https://www.ftdichip.com/. Not only their chip (yes it is a single chip solution) works, but they have stable Windows drivers (make the device looks like a standard serial port to Windows).

Once you have all this, you can then write your application in VB.

Jem
 
Jem, this looks good thank you.
I need a little more help please: I found a sample application at Atmel for use with a 8x8 matrix keypad which is probably the closest I get to a finished application I can use - but I can't figure out which pins on the controller actually constitute the RS232 output because both B and D ports are used for input and the XTAL ports seem to be used for clock synch. and the remaining 2 pins for voltage supply...
Could you also tell me which frequency the crystal needs to be and the capacitance of the caps..

Regards
Jens
 
The application you are referring to uses a Mega162 AVR. I think this is overkill for what you have in mind. Anyway, if you want to use it, you can use TxD1 and RxD1 (PB2 and PB3) for your UART. you will also need a different, more universal programmer (Try a Ponyprog programmer - ).

As for the crystal, I typically use a 9.213 MHz crystal and a pair od 20pF caps. (I have successfully used 18pF and 22 pF with almost no degradation in timing accuracy). 9.213 MHz gives very accurate (bang on) RS232 baudrates. It also allows exact delay timings (using the timers) for 1ms (or multiples) using the predivision set to 1024.

Hope that helps,

Jem
 
Sorry, I didn't notice that it was for the Mega162 but I don't want to complicate this more than I have to - so I'll stick with the S2313 and find an application that can be modified for my use.

I am looking at the FTDI sample for a USB to RS232 converter
Am I right in assuming that I connect MISO and MOSI to the RXDATA (pin2) and TXDATA (pin3) on the U1 chip in the sample, and PD0-6 for the digital inputs?
But where do I connect RESET and SCK RTS?
Can I use Vcc from the USB circuit on the AVR?

Hope I am not being too hopeless here.

Jens
 
Don't know which one you are looking at, but this one is what you should be be considering. It is straightforward RS232 (plus some flow control pins) to USB adapter. In other words, you use the UART on the 2313, plus a couple of IO pins for the handshake. Both operate on 5V. That leaves plenty of IO for you own application. In that case, you program the 2313 UART, and it gets converted to USB compatible signals for linking to the PC.

MOSI, MOSI and SCK are for SPI applications.

Jem
 
Overkill to the max. He only needs 6 bits (buttons) of input to the pc, and the parallel port has 8 (12 if you count the status register bits too).
Wire each button to one of the data bits. Grounding the data bit by pressing the button will set the port input data register bit=0, open button will produce a 1. Read the port and the rest is programming logic. I'll post some BASIC code suitable for parallel port access under dos, win95-ME.
Dialtone
 
Here are some code snippets you may find usefull
For really good info on parallel port, goto Beyondlogic.com. They have documented just about anything you would need to program for the port in any mode.


SUB LptPortFind (BaseAdd%)

'Find out which LPT ports are equipped and get their base addresses'
DEF SEG = 0 'Set memory segment offset to absolute "0" for subsequent PEEK'
'Read BIOS storage locations for LPT port assignments'
LPT1 = PEEK(&H408) + (256 * PEEK(&H409)) 'returns the decimal address of the port'
LPT2 = PEEK(&H40A) + (256 * PEEK(&H40B))
LPT3 = PEEK(&H40C) + (256 * PEEK(&H40C))
[bios will set above addresses = to the base address of each equipped port]
[unassigned ports will return "0" as address}
[insert some decision code here to determine which port to use]
DEF SEG 'Return memory offset to basic'
END SUB





SUB SetLptPortMode (BaseAdd%, PortType$)
[how to set an ECP defined port to any mode of operation]
SELECT CASE PortType$
CASE IS = "ECP+EPP", "ECP"
'Test for presence of ECP extended control register
s% = INP(BaseAdd% + &H402)
IF s% <= 254 THEN 'anything but all 1's indicates register current value'
'Test the ECP port ECR for EPP operation mode setting, Set to EPP mode if needed'
' Test ECR bits 7-5 <> 100 for EPP mode [001 for bi-dir mode if desired]
IF (&HE0 AND s%) <> &H80 THEN
'Set bits 7-5=100 (add d'128 to value in bits 4-0) if test fails'
OUT (BaseAdd% + &H402), ((&H1F AND s%) + &H80) 'Combine mode bits 7-5=100 with existing bits 4-0 value'
END IF
END IF
CASE IS=[other operation mode]
[code here to setup for desired parallel port operation mode]
END SELECT
END SUB




SUB TimeOut (BaseAdd%, TimeOutFlag%)
[how to manipulate an EPP port timeout register bit]
'Read and reset if necessary EPP timeout bit at baseadd+1; bit 0'
IF (1 AND INP((BaseAdd% + 1))) = 1 THEN 'Timeout bit is set'
Tries% = 0: TimeOutFlag% = 1 'Set flag if timeout was set on entry'
DO
'set direction foreward for write'
OUT BaseAdd% + 2, 4
' Clear the bit by writing a "1" to the status port..that's correct..write a "1 to clear bit'
OUT BaseAdd% + 1, 1
' Execute Data Read to check unit response)'
b% = INP(BaseAdd% + 4): Tries% = Tries% + 1

LOOP WHILE Tries% <= 10 AND ((1 AND INP((BaseAdd% + 1))) = 1)
ELSE
TimeOutFlag% = 0' Clear flag if no timeout was set on entry'
END IF
IF Tries% >= 10 THEN
CLS
PRINT " Unit is not responding... 10 consecutive timeout errors detected."
END 'Stop program execution, unit is dead'
END IF
END SUB




Dialtone
 
Dialtone:

I agree that a microcontroller is overkill for this app. However, in earlier posts the use of a parallel port was proposed, and was not acceptable for various reasons. Your proposal is quite worthy of being put up again, though. It considerably simplifies things.

Jem
 
OK, this poses a bit of a dilemma to me:
I would like to make things simple, so parallell would be fine, but as far as I understand, the parallell port isn't easily accessible in 2k/XP and this is a drawback since the people using this aplication will have mostly newer laptops and no special knowledge of hardware setup - so I have to make something that works out of the box.
So my options are to use the parallel port directly or to emulate it through a port replicator to USB
OR
figure out all the stuff required to make a microcontoller based solution - I still have a ways to go despite my effort so far.

I could also go to **broken link removed**
and buy the thing for $99, but that is not my first inclination since this is a challenge I would really like to take.


Best regards
Jens
 
USB has a maximum cable lenght is of 16 feet. And as you can probably tell most of the USB cables are failly short. Something to take into account when checking your layout. That is the maximum length at probably low speed. The RS232 (serial) cable standard maximum length is of 50 ft if I remember correctly.

Serial comunication would be fairly simple and cheap. I would use a PIC 16F628 or the PIC 16F84. This next to a MAX232 will give you the quickest and best solution. Not to mention how easy it would be to program with VB.

PortB on a PIC16F84 has 8 inputs. Can it be more convinient than that? By programming the PIC to read its portB 6 inputs (3 refer. 2 buttons each) then send that serially would be really fast and easy. Using PICBASIC PRO the thinks get even better. But getting all you need to get started (with any microcontroller) would not be efficient if you are only going to use it once.

So the PICs would be the fun way to do it :D But you can get and OCX that will work (according to them) in XP/2000/NT, like this one: **broken link removed** for U$14.99. Then with a 74HC245 buffer get your inputs and outputs. Since you said that all the laptops will be fairly new, then you will probably won't have any trouble with the type of port they have.

Good Luck,

Ivancho
 
You are right about not being able to directly access hardware port addresses under win2K-XP, but all is not lost. There is a freeware driver called "inpout32.dll" you can download. You access the dll API (and thereby the port) thru an API function/sub call in your VB program. From what I read (have not used it yet) it works under all flavors of windows OS.
Dialtone
 
So if inpout.dll or any other such API works right in any OS, the easy thing would be to make a parallel port solution and connect it to a Parallell<>USB converter so the thing will work on any PC with a USB port. Only thing is I see these converters are specifically made for printers (EPP) - does that mean they don't behave like a regular parallel port, and can the port be accessed through the drivers supplied with it?

Jens
 
I must have missed something in the earlier posts. Why on earth would you want to take a PC equipped with a perfectly good parallel port, and do a data capture thru a USB to Parallel adapter? Use the equipped Parallel port and forget the USB-Parallel adapter unless you need the services of more than 1 parallel port, and if so, then stick a printer or whatever on that.
SPP, B-Directional (enhanced), EPP, ECP are all IEEE1284 interface/operational standards based on the standard centronics pinouts. The only difference is the way the port is operated/controlled and the effective data thruput each can be expected to handle. For example, a parallel port running on an ISA internal bus operating under EPP mode can have a max thruput of 2 MBYTES/SEC and up to 10 MBYTES/SEC on a faster bus such as PCI or other fast local. So you are talking from 16 to 80 mega-bits per second potential. My bet is that Parallel ports will continue to be around on computers for quite some time given that potential. Only problem I see is that very few have figured out just how useful and fast it really is.
Dialtone
 
Dialtone,
the only reason I would use a USB adapter is that I expected parallell ports soon to be obsolete given how widespread USB is becoming - also on printers.
Anyway, I'll take the simple approach for now and make the program for a straight parallell port and then modify later if I need to.


regards
Jens
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top