Multiple Interrupts in INT0 But only one signal - [ SOLVED ]

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

NewBie here...

I've a hall effect shield which is basically a hall effect ic with a compactor ic to convert the analog output of the first ic to digital output (5v or 0v).

it's default output is 0v , when a magnet is close it flips to 5v as long as the magnet is close .

I connected it to INT0 of the ATmega8  with this code : (The main part of it at least)


volatile unsigned char count=0;
char txt[5];
int main(void)
{
	Usart_Init(9600);
	MCUCR=0x02;  //Configure INT0 Falling Edge
	GICR|=(1<<INT0); // Enable INT0 Interrupt
	
	    DDRD &= ~(1 << DDD2);     // Clear the PD2 pin
	    // PD2 (INT0 pin) is now an input

	sei();
	
    while(1);
}


ISR (INT0_vect)          //External interrupt_zero ISR
{
        count++;
	int2str(count,txt);
	LtrimZeros(txt);
	Usart_Write_Text(txt);
	Usart_Write(0x0d);
}

But as my serial Monitor showing... when a magnet is close the ISR Function contents are excited at least 2 times ! (it reached 20 times) when bringing a magnet close

I expected that it was noise  But there is no way that i can make sure if it is (sorry no oscilloscope available) ,

Any Ideas ??

Please if any thing is not clear tell me... 

Thanks

This topic has a solution.

A Beam of Light out of the War

Last Edited: Thu. Dec 26, 2019 - 05:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can use the microphone input of your PC as an oscilloscope - Google 'soundcard oscilloscope'

 

You might need to add more hysteresis to the comparator circuit. 

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

Notes :

 - It's  " Falling  edge" Because i want to detect the moment the magnet Left the sensor  

 - My magnet is extracted from an old CD Driver it has a cubic  shape 

 

 

 

A Beam of Light out of the War

Last Edited: Mon. Dec 23, 2019 - 10:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you a have a web link/reference or a schematic of the hall sensor and comparator? You may need a pullup resistor.

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

Kartman wrote:
You might need to add more hysteresis to the comparator circuit. 

I Don't quite get what you mean

The Shield is a one peace component from factory 

A Beam of Light out of the War

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

If your comparator simply compares two voltages, its sensitive to noise, and may oscillate when the two voltafges are near identical. That will trigger multiple times.

 

Solution is to make a little positive feedback, eg make a schmitt trigger circuit. Google: comparator schmitt trigger.

 

Or debounce in software, google that too.

 

Good luck!

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

Kartman wrote:

Do you a have a web link/reference or a schematic of the hall sensor and comparator?

 

sorry i searched but i can't find one, But the sensor IC name is 49E and the comparator is LM393

 

Kartman wrote:
You may need a pullup resistor.

 I Tried Pullup And pulldown Res but Nothing changed 

A Beam of Light out of the War

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

So how can we help if we have no idea of what you're using? Picture? Use the power of the Goggles to find it.

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

AbDoO_ wrote:
If your comparator simply compares two voltages, its sensitive to noise, and may oscillate when the two voltafges are near identical.

 

I tried changing the attached Potentionmeter ( i don't know if i wrote it write but it's a variable resistor ), so the sensitivity is changed ... but no thing changed except that i have to bring the magnet closer now

A Beam of Light out of the War

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

I found this pic , It's the same as the one i have 

KY-024

A Beam of Light out of the War

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

And here's the schematic:

 

https://protosupplies.com/produc...

 

There's no hysteresis, so that might explain the multiple pulses. Use the soundcard oscilloscope to measure.

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

peteralarsen wrote:
Or debounce in software, google that too.

the point of using The INT0 instead of the regular input test  is because i want it to be fast and with no extra coding .

Thanks for Suggesting . 

 

A Beam of Light out of the War

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

AbDoO_ wrote:
the point of using The INT0 instead of the regular input test  is because i want it to be fast and with no extra coding .

 

And most likely you re getting some sort of 'bounce' even though the sensor is solid state.  Using the interrupt input is not always a good idea when interfacing to the outside world.  Especially if there is no external signal conditioning.

 

How long will the magnet be in front of the sensor?  How 'fast' is the sensors response time?

 

So, how 'fast' do you need the response to be anyway? 20 milliseconds fast enough?  Set up a timer to 'tic' every 10 milliseconds, in the ISR for the 'tick' you sample teh input of a pin connected to the sensor and save it.  Go back to your main and do something while waiting for another 'tick' save that in the ISR as well and set a flag.  Now in your main put together an IF that runs when the flag sets.  In the IF you compare the two samples and if they are the same, then the magnet is there and stable.  If they do not match,, flush the samples and reset the flag and start over.  With a sample every ten milliseconds you should have a solid result within two sets of samples.

 

Add a few microseconds for processing >depending on your CPU clock< and your talking less than 50 milliseconds to get a solid result.

 

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

 

The board you are using has poor signal processing - a little bit of Googling would uncover others experiments with this.

 

A couple of resistors and a capacitor or two would fix this - but you'll need to learn about comparators and hysteresis. I'd suggest to use a digital hall effect sensor - you could probably get one from an old computer fan or VCR.

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

AbDoO_ wrote:

the point of using The INT0 instead of the regular input test  is because i want it to be fast and with no extra coding .

Thanks for Suggesting . 

 

You can also debounce an interrupt. I often do so.

 

To make it very simple: declare a volatile int outside the interrupt handler. Name it something like “flag”.

Assign a value of 0 initially.

Let the interrupt handler set the flag = 1. Multiple interrupts just set flag = 1 again.

Check flag outside of the interrupt handler. If flag == 1 wait for the signal to settle before you read the GPIO pin and set flag = 0.

Time needed to wait could be microseconds or milliseconds. Experiment or use an oscilloscope.

The delay between raising flag and reading GPIO effectively debounces the signal.

 

Another way is to disable interrupt for some time after first interrupt. This will be a little faster.

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

Thanks for you suggestions 

After some googling i think my problem is (as you said)  hysteresis  .

My new goal is to modify my circuit to give a more stable signal (let's try debouncing in Hardware first )

Please excuse my poor knowledge in electronics , How can I "Debounce" This circuit ?

Thank you 

Schematics :

 

A Beam of Light out of the War

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

You want hysteresis and low pass filtering. Google is your friend.

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

I'm very confused right now .... why would the factory sell a shield that is no working ??

and why only me is having this problem ??

I tried different shields form the same type , same problem

by the way my project is a pov display , I need the interrupt so it reset the display .

A Beam of Light out of the War

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

AbDoO_ wrote:

I'm very confused right now .... why would the factory sell a shield that is no working ??

and why only me is having this problem ??

I tried different shields form the same type , same problem

by the way my project is a pov display , I need the interrupt so it reset the display .

 

You can try to add reasonable big resistor between op amps noninverting input (+) and output (about 500k) to add some hysteresis. If it's not enough, you can go lower.

Computers don't make errors - What they do they do on purpose.

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

AbDoO_ wrote:

I'm very confused right now .... why would the factory sell a shield that is no working ??

and why only me is having this problem ??

 

It's not working the way YOU want it. I did a Google and found where people had observed the same problem you had and shown pictures from the oscilloscope. The module is working the way it was designed. You bought a cat and it goes 'meow' but you really wanted a dog. Your cat won't go 'woof'.

 

I gave suggestions for a more suitable sensor and some keywords for you to Google so that you could modify your circuit for it to work the way YOU want.

 

 

I Googled lm393 hysteresis

 

This is one hit:

http://www.kerrywong.com/2014/11...

 

You probably want, say 100pF capacitor across the 1M resistor to slow things down a little.

 

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

I recently used TLE4905L which is a digital hall sensor with integrated schmitt trigger. It works pretty well and comes in a 3-pin package and requires no external components except pull-up. I think it could be a better choice for you.

/Jakob Selbing

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Latest Updates:

----------------------

After 3 Days of work I finally found it ..

I added a 2Mohm Resistor with a 100pf cap in parallel between pin1 (output) and pin3(Input - ) of the comparator ,

then i added a 100nf cap on D0 ( The Digital output of the shild ) and Gnd . And it worked perfectly !

Imp Note : for some reason it only works when the potentiometer is at 40KOhm.

Here are some pics from the edited shield : (sorry for my poor soldering skills)

A Beam of Light out of the War

Last Edited: Thu. Dec 26, 2019 - 05:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Those resistors are 1 megohm EACH making it 2 megohms.

 

THat cap across the output has probably crated a sloping rising and falling edge of the output signal.  What does your Oscilloscope say?

 

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

jgmdesign wrote:
Those resistors are 1 megohm EACH making it 2 megohms.

Sorry i mean 2 Mohm, I edited it

jgmdesign wrote:
What does your Oscilloscope say

well, this solution was the result of alot of random tests and collected numbers from internet, I already destroyed my first shield XD
My first 2020 goal is to buy an OSC, I really do need one

A Beam of Light out of the War