Gpio pin connected to a long wire

Go To Last Post
43 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All

 

I got a slight issue. I had connected flow sensor to out microelectronic using the following circuit. The sensor was simply outputting a pulse. "Input 1" connects to the GPIO pin of my AVE and "Input_Control 1" is the output of the sensor.

 

The sensor has been removed, but the wire which about 1.5 meters is till connected to this circuit and then the GPIO.

 

We are detecting pulse on that GPIO. We are monitoring the pulse using a counter variable that is TX using the internet.

 

 

Is this normally behaviour?

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With a 10:1 ratio on the base of Q11 it is possible that noise in the air could be causing false triggers.

 

Ground the input terminal, or disable the GPIO pin in your firmware.

 

Jim

 

EDIT:

Never thought to ask if you have pullup resistors enabled in your Micro (Is it an AVR?)  If those are not enabled hen the input could be left in a floating state thus also picking up noise.  Enable teh Pull up

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Thu. Mar 5, 2020 - 02:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Jim

 

Yes the pull up is enabled. 

 

I guess i will need to get someone to remove the wire.

 

Thanks

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or simply connect the wire to your widgets ground terminal

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, will do that once i get to the site again. Its a remote sensor.

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There’s no input protection and no filtering. You circuit is not really suitable for the real world.
What type of output the flow sensor has?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
There’s no input protection and no filtering. You circuit is not really suitable for the real world.

 

I've seen a similar circuit used in an alarm panel I used to work on 30 years ago at ADEMCO, and its still in use today.  Granted, maybe a diode on the input for negative spike suppression, but with a 4.7k resistor I'd think that would keep the reverse currents below the limits.

 

What do you have in mind Russell?

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First i’d start with the sensor. What is its interface? If it is a simple single ended output, then it is probably not suitable. I’d be looking for a 4-20mA output or similar. Then judicious use of movs or transzorbs and some capacitance to limit the frequency response.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman,

In the OP:

djoshi wrote:
The sensor has been removed, but the wire which about 1.5 meters is till connected to this circuit and then the GPIO.

 

THe sensor has been disconnected, hence:

djoshi wrote:
We are detecting pulse on that GPIO.

 

Me thinks the sensor has a low impedance output that flips between ground and a positive voltage so as long as the sensor is connected the circuit is stable.  Based on the circuit above with the input wire floating in the air Q11 is turned on, leaving Q14 off thus teh input pin of the AVR is floating, and possibly picking up noise form the surrounding environment.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
There’s no input protection and no filtering. You circuit is not really suitable for the real world. What type of output the flow sensor has?

 

Water flow meter , is there a recommended design. 

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is the flow sensor i am using

 

https://www.seeedstudio.com/G1-2-Water-Flow-Sensor-p-635.html

 

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am to keep this circuit for various input pulsing sensors. Is there anything else i can do to improve it as i am making a new PCB soon?

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is your environment?  Quiet household, noisy industrial? , or something in between?

 

Stronger pullups (lower ohms) fight noise better.  47K is somewhat middle of the road, 10K is harder to knock around by accident.  Of course, some lucksters get by with 1 meg in a quet setting.

Is power consumption (such as batteries) of any concern?  That can drive things towards higher ohms.

 

 

Les's get some transorbs (or other esd parts) in there!

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Mar 6, 2020 - 12:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unfortunately the datasheet doesn't tell us too much out the output specs. For 1.5metres, shielded cable is adequate. For tens of metres, then you would want some conditioning circuitry on the sensor as well.

 

As mentioned, for an industrial application, I'd expect a 4-20mA interface or simply a reed switch.

 

For an outdoor application the issues you'd expect is lightning and RF interference from cell phone, local radio stations and radar if you're close to an airport or military installation. 1.5 metres is long enough to pick up a healthy signal from any of those sources. You can't protect from a direct lightning strike as this usually results in a fair amount of destruction, but local lightning strikes induce a voltage into your wiring - thus the need for transient voltage protection like tranzorbs or varistors (movs). Varistors normally have a fair amount of capacitance, so that acts as a filter as well.

 

As the others have mentioned, you probably want the pullup resistor lower to pull a bit more current from the sensor which will make the circuit less sensitive. 100pF of capacitance on the input should go a long way to stopping a bit of RF.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

djoshi wrote:

I am to keep this circuit for various input pulsing sensors. Is there anything else i can do to improve it as i am making a new PCB soon?

 

If spurious (short and fast?) pulses are a problem, and given you have amplification through your transistors, a passive low-pass filter (resistor in series, capacitor to ground) between the two transistors might not be a bad idea.  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Making your data cable a twisted pair may help to keep common mode noise out of your circuit.

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

What is your environment?  Quiet household, noisy industrial? , or something in between?

 

Stronger pullups (lower ohms) fight noise better.  47K is somewhat middle of the road, 10K is harder to knock around by accident.  Of course, some lucksters get by with 1 meg in a quet setting.

Is power consumption (such as batteries) of any concern?  That can drive things towards higher ohms.

 

 

Les's get some transorbs (or other esd parts) in there!

 

 

 

 

The environment is a household, but would like to re design it for all purpose.

 

Usually i would have removed the the complete wire, but i had some else do task and flow sensor was removed but the wire to circuit was left. The positive side of that was i got to see the issue before the new boards got made.

 

I can replace the 47K resistors by 10K resistors.

 

Should the 4.7K,be replaced by any other value?

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

Unfortunately the datasheet doesn't tell us too much out the output specs. For 1.5metres, shielded cable is adequate. For tens of metres, then you would want some conditioning circuitry on the sensor as well.

 

As mentioned, for an industrial application, I'd expect a 4-20mA interface or simply a reed switch.

 

For an outdoor application the issues you'd expect is lightning and RF interference from cell phone, local radio stations and radar if you're close to an airport or military installation. 1.5 metres is long enough to pick up a healthy signal from any of those sources. You can't protect from a direct lightning strike as this usually results in a fair amount of destruction, but local lightning strikes induce a voltage into your wiring - thus the need for transient voltage protection like tranzorbs or varistors (movs). Varistors normally have a fair amount of capacitance, so that acts as a filter as well.

 

As the others have mentioned, you probably want the pullup resistor lower to pull a bit more current from the sensor which will make the circuit less sensitive. 100pF of capacitance on the input should go a long way to stopping a bit of RF.

 

Is there a recommend conditioning circuit for industrial application? I will reduce the pull up resistor to 10K. 

 

Should the 4-20mA interface or reed switch need to be on sensor side or would we need to add this to the circuit?

 

Our circuit has got a GSM module and external antenna ( antenna wire next to the flow sensor wire), so i guess the noise could be coming from that. 

 

Should the 100pf need to be near the AVR pin or at input where the sensor connect to transistors.

Thanks

Regards

DJ

Last Edited: Fri. Mar 6, 2020 - 06:53 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Using the links in your sensor datasheet leads me to believe that the sensor output is a normally open reed switch contact; ie either open circuit or shorted.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes it does, but when i measured the output it is either 5V or 0V?

 

Would it be appropriate to ask few conceptual firmware/software questions on this page as we discussing this flow sensor.

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From what i read from the datasheet, the sensor is hall effect. Unfortunately, it doesn’t say much about the hall effect sensor in terms of its specs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These were cheap Chinese sensor, which does not have any good document 

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i believe you fail to mention how many of these you will make...1?  10?  100? 1 million units?  That will play a role in how much $$$ you will put into the circuit.

 

Don't go higher on the 4.7k input res, since it will affect the divider margin (to turn off the base), when the input is grounded.

 

Actually, if VoutDCDC is large (say24v), the base may not get pulled low enough...so I assume VOYTDCDC is 5V and Vbase.low is low enough.

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Mar 6, 2020 - 09:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We aim to make a few hundred. Yes it is 5V

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

This Flow sensor rotates times 450 per litre.

 

At the moment in my firmware, it is simply increment a variable on each input trigger and after a certain interval transmitting the variable to  a remote API.  On the API side i simply dividing the number by 450, to display the total litres.

 

The downside is there is a chance that the variable could overflow . I do not want to divide the variable by 450 on the AVR , as if the flow sensor is changed then it can be easily adapted on the API side.

 

I would like to know if this solution would work....

 

 I would calculate the flow rate as litre per min on the AVR, if the rate is below one litre for example then i would ignore it as this could be noise. If anything is above 1 Lpm then it would be transmitted to the API.

 

And on the API using the flow rate and time stamps i could calculate volume as a total.

 

Would this software type solution work?

 

 

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The interval is inherently part of the calc...half the time , half the count.

Do both sides know the time (2 sec, 5 sec , 2 minutes, whatever).

 

Make sure to set  one value to indicate an illegal or error condition....say  99999 means an error was detected (99999 is never a possible valid value).  Something like that is ok if you are only going to spit out one number and nothing lese & not  accept status queries.

 

 on the AVR, if the rate is below one litre for example then i would ignore it as this could be noise.

You can do the same (ignore) on the PC....you say you don't want to do blah blah on the avr, but then say do this on the avr.  Must make up your mind. I'd vote for doing everything on the AVR.  if the sensor changes...send it a different calibration value to save in the eepprom.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The first thing is to understand your signal. What are the minimum and maximum pulse rate you expect? What is the pulse width you expect? Design your circuit so that hopefully it filters out most of the garbage then your software can do additional filtering to ensure that the pulses you count are true and correct. Lightning and ESD are usually pulses in the range of around 2- 80us. If you use interrupts as the trigger - then these pulses will cause a valid interrupt. If you need to power save, then wake on interrupt but then sample the input to determine if it is a valid pulse width. If you don't need to power save, then sample the input via a timer interrupt. The technique is the same as debouncing . The more samples you take, the better you can determine whether an input pulse is true or not.

 

As for coping with potential overflow of the count - mechanical meters have done this for ages - if you have 6 digits, then 999 999 just rolls over to 0. This is simple to do in software.

 

I've done a bit of industrial  control, and my boards used Modbus for communication and would store various cal factors in the eeprom. These could be changed via a simple menu with three pushbuttons and a 16x2 display or via Modbus.

 

You need to determine the output specs of your sensor. If the manufacturer doesn't have it in their datasheet, then you have to measure it. Does the hall effect sensor actively drive the signal high and low? Or does it only pull the signal low requiring external circuitry to pull it up? Put a 20mA load (resistor) on the output - measure haow much the voltage changes vs without a load. That should give an idea of the drive capability. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

The interval is inherently part of the calc...half the time , half the count.

Do both sides know the time (2 sec, 5 sec , 2 minutes, whatever).

 

Make sure to set  one value to indicate an illegal or error condition....say  99999 means an error was detected (99999 is never a possible valid value).  Something like that is ok if you are only going to spit out one number and nothing lese & not  accept status queries.

 

 on the AVR, if the rate is below one litre for example then i would ignore it as this could be noise.

You can do the same (ignore) on the PC....you say you don't want to do blah blah on the avr, but then say do this on the avr.  Must make up your mind. I'd vote for doing everything on the AVR.  if the sensor changes...send it a different calibration value to save in the eepprom.

 

The intervals i was referring, it intervals when the PCB sending data to my API(maybe 1 min), but the AVR would have intervals of 10 seconds to calculate the flow rate.

 

Yes the l will add an error values, maybe this will be 65356(16-bit)

 

Yes i agree , I will send a calibration factor variable to the AVR and then have a counter total litres passed as well. There could be chance(very unlikely) if within interval period(when data is sent to the API) if the flow rate was to change then the API not have a very accurate calculate as only the flow rate at interval periods would be sent. 

 

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

The first thing is to understand your signal. What are the minimum and maximum pulse rate you expect? What is the pulse width you expect? Design your circuit so that hopefully it filters out most of the garbage then your software can do additional filtering to ensure that the pulses you count are true and correct. Lightning and ESD are usually pulses in the range of around 2- 80us. If you use interrupts as the trigger - then these pulses will cause a valid interrupt. If you need to power save, then wake on interrupt but then sample the input to determine if it is a valid pulse width. If you don't need to power save, then sample the input via a timer interrupt. The technique is the same as debouncing . The more samples you take, the better you can determine whether an input pulse is true or not.

 

As for coping with potential overflow of the count - mechanical meters have done this for ages - if you have 6 digits, then 999 999 just rolls over to 0. This is simple to do in software.

 

I've done a bit of industrial  control, and my boards used Modbus for communication and would store various cal factors in the eeprom. These could be changed via a simple menu with three pushbuttons and a 16x2 display or via Modbus.

 

You need to determine the output specs of your sensor. If the manufacturer doesn't have it in their datasheet, then you have to measure it. Does the hall effect sensor actively drive the signal high and low? Or does it only pull the signal low requiring external circuitry to pull it up? Put a 20mA load (resistor) on the output - measure haow much the voltage changes vs without a load. That should give an idea of the drive capability. 

 

Thanks

 

I minimum rate would be about 1 litre per minute but max could be anything much high such as 100 litres or even more.(might need to change the sensor for this). This would mean with 450 pulse equal to 1 litre , per second i should expect 7.5 pulse when 1 Lpm and 750 pulse when 100 Lpm. I will added denouncing feature in the firmware as well. I will not be putting the AVR in sleep mode.

 

What can i do on the hardware to filter out as much as possible. Is it as simple has placing an capacitor on input line?

 

Yes the sensor will output a high and low signal. But some sensor require a pull up resistors as well for which i have already on my PCB. 

 

Thanks

 

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So after every false trigger if I wait 1ms then re check the pin, would that be enough?

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The reason i asked about the expected min and max values is so you can make a decision based on hard numbers rather than guessing. I think your suggestion of 1ms is woefully inadequate. Determine what timing a ‘good’ pulse has and that will lead you to how you software can differentiate a good or bad pulse.

As for the hardware - the solution could be as simple as a capacitor - the next question is ‘what value,where’. Again, this is based on numbers. This is why the sensor specs are important. If you don’t know what they are, then you measure.
Personally, I’d suggest your input circuit has some hysteresis - arrange your two transistors into a schmitt trigger circuit or use a comparator chip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The next revisions of the PCB will have the updated changes, but for now i want to see if i can do this using software.

 

The datasheet for this flow meter is not available from any reliable source, as this was cheap part i got from amazon.

 

But from some tests, 1 litre passed is about 450 pulses, with a 50% duty cycle. The sticker on sensor says the it capable for detecting a flow rate of 1-30 litre a min. 

 

Therefore if with flow rate of 1 litre a min, the pulse per seconds would be 7.5 and at 30 litres a min the pulse per second would be 225 .

 

So if my calculation are correct the min frequency would be 7.5Hz and max would be 225Hz, which is 133 ms and 4.4ms.

 

So after every pulse if i was to check the status of the pulse after 1-2ms to insure it is valid pulse and not noise would that be correct?

 

 

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You want to sample the pulse many times if possible. The more times you look, the more likely you are to get a real picture.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So that i have understood it properly.

 

Once a interrupt(low) is detected on a pin. I could start a timer for 2ms. Then have a function(running on system clock 11.0952Mhz) sampling how many times pin is high and low. If after 2ms the low count is more high count , this would mean it is a true low, if not then it could be noise.

 

Would this be the correct way?

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You shouldn’t be using external interrupts. This was mentioned earlier. Use a timer isr to sample the input.

Last Edited: Sun. Mar 15, 2020 - 12:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So how often would this timer isr be?  So when i am sampling the pin, do i wait for the pin to go low before doing what i mentioned?

 

For example every 1ms check if the pin has gone low.

 

If it has gone low, keep sampling the pin against as much faster clk? 

 

So why would having pin interrupt not be a good idea?

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For the exact reasons your having the problem! You have no control over the rate the interrupt occurs, so given suitable input, the AVR can get so bogged down servicing interrupts that your system fails. As it stands, your circuit is unreliable by design.

If you’re in the UK and you've done 100 of these boards, how is it that you have not done EMC testing that is likely required by law?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To debounce/filter the input (denounce as you describe it), lets say you sample every 500us. Keep a count. If at least four of the last samples are high, then the input most likely has been high for 2+ms. You don't sit in a loop and wait.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

For the exact reasons your having the problem! You have no control over the rate the interrupt occurs, so given suitable input, the AVR can get so bogged down servicing interrupts that your system fails. As it stands, your circuit is unreliable by design.

If you’re in the UK and you've done 100 of these boards, how is it that you have not done EMC testing that is likely required by law?

100 boards have not been made yet, we are just producing few at moment to get it working before we do our CE and EMC testing.

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I’d suggest you get an experienced engineer to rework your design and code. Otherwise you’ll piss a lot of time and money trying to get compliance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
To debounce/filter the input (denounce as you describe it), lets say you sample every 500us. Keep a count. If at least four of the last samples are high, then the input most likely has been high for 2+ms. You don't sit in a loop and wait.

 

Ok, i can get this added onto my firmware.  No, i will not be waiting i till be keeping an count.

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good luck with the BG96 - its very picky about the pcb layout and support circuitry. Simple things like capacitor placement and specifications are critical.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BG96 is working well. Yes i agree. Have you used the module before?

Thanks

Regards

DJ