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.

How to design a comparator?

Status
Not open for further replies.
thanks dougy its working, but alas not meeting the desired criteria. The machine that is passing the 5V signal can vary the duration of the signal, mean that the throughput

of the machine can vary(the machine is passing 5V signal each time a smart card comes under it). The problem is that the 5V signal duration can vary. So, If I pass data

each 100msec to TxD pin and 5V signal is passed to short TxD with RxD pin and as a result data is returned back but I will unable to differentiate data corresponding to one

card than other. Lets Suppose that each 100msec an application is passing data to TxD pin and the diode(1N4148) is off. Now, a card comes under the machine and it passes

5V signal for 100msec duration corresponding to this signal diode is switched ON and data is received back on RxD, Smart card counted. But after it another card comes after 200msec gap

& again 5V signal is passed for 100msec duration so another smart card counted. But the problem comes if production is slow and cards are coming slower under machine,

then corresponding to each card the machine can vary 5V signal for 100-500msec duration. Now the applcation reads 5 cards corresponding to 500msec duration in place of

just one card. I think this problem can be solved by going back where we were, that passing 5V signal to CTS,DSR or RxD pin will generate an interrupt. By doing this each time

the pin goes from Low-> High, a card counted. But this is'nt possible with this prolific USB/RS232 adapter.

Tell me is it possible with this circuit ? **broken link removed**
 
thanks dougy its working, but alas not meeting the desired criteria.
Sounds like the hardware portion is working fine & you just need to adapt your software.
The problem is that the 5V signal duration can vary.
As you would expect
Now the applcation reads 5 cards corresponding to 500msec duration in place of just one card.
The problem is how you've written the application. It's very simple to write an app that gives you a single event even if a number of data bytes are received from the serial port.

One simple method is to remember the time that a data byte is received; if the time difference between the current and the last data byte is more than some period (e.g. the minimum time between cards being inserted) then you know you have a new card, if the time diff is less than that period, then you know that it's the same card.

Code:
void dataReceived(char dat)
{
	static long lastRxTimeMs = 0;
	
	long timeNow = getTimeTicks();
	
	if(timeNow - lastRxTimeMs > 300)	// card out for > ~300ms
	{
		cardInsertedEvent();                  // raise card inserted event
	}
	
	lastRxTimeMs = timeNow();
}
 
Last edited:
It shouldn't be difficult.

If the card is there for 100-500ms, you should make sure that you send a character more often than once every 100ms; e.g. 1 byte every 25ms wouldn't hurt. That way you won't miss the insertion of a card.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top