Causing an Interrupt on a event

Hello people,

I'm wondering if someone can help me with internal interrupts. I'm using the PIC18f452 ADC to get a reading from a wall sensor (its an IR transmit receive circuit) which gives out numbers ranging from 0 to 500 (these numbers correspond to how far the sensor is from the wall). What I'm trying to do is generate an interrupt when the number is 250. I've thought about connecting a pin to the external interrupt pin on PORTB, but I'm already using them for another function and I have limited I/O pins available. What I'm thinking is along the lines of a software interrupt generated say in similar fashion to that of timer interrupts. I'm wondering if its possible to make timer0 (for example) over flow (FFh to 00h) when ADC returns 250. I'm not sure if what I'm thinking of is at all possible, and I am open to any ideas.

I hope there is somebody who can help me, thanks a lot.

Dimithri

Reply to
dimithri
Loading thread data ...

And what, pray tell, would that be supposed to gain you? What would an interrupt achieve here that a mere function call wouldn't?

You seem to be suffering from 'new hammer syndrome'. You've acquired a new tool (interrupts), and now you trying to use it for every task you come across, no matter whether it's the right tool or not.

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

It is not possible. Check the value in the ADC interrupt. I assume you need to restart the ADC any way.

Reply to
Neil

If you have enough processor time, you could set up TMR0 to interrupt every n microseconds. Inside the isr, turn off TMR0 and start one AD reading, and exit the interrupt. Set the AD module so that it triggers an interrupt on completed conversion. Then when the AD interrupt occurs, read the AD value, compare it to 250, reset TMR0, and exit the interrupt. Quidquid latine dictum sit, altum viditur. (Whatever is said in Latin sounds profound.)

Reply to
Charles Jean

formatting link

martin

Reply to
martin griffith

It's not clear what you're trying to do. Do you expect this interrupt to occur automatically without your software reading ADRES and comparing it to 250? That's not possible.

You can't make a timer overflow on demand, but you can set its interrupt flag (or any other peripheral's interrupt flag if it's writeable) if all you want to do is force the PIC to vector to the interrupt handler.

--
John W. Temples, III
Reply to
John Temples

Reply to
purple_stars

If you really really want to use an interrupt then you could use the external interrupt line.

If you AND all the lines of the data bus together then the AND will output high when the data is 256 (is that close enough to 250 for you) and then you can trigger the interrupt from it.

However, other people have suggested more sensible approaches that don't use interrupts.

Reply to
Tom Lucas

He is using the internal A2D So he can not decode the bus. If he did switch to an external A2D he would still need to trigger the conversions. That is a lot of hardware.

Reply to
Neil

Errr, why?

An interrupt is generally used to signal a hardware event. At the point where you're read the ADC, you can test for the value - and there you are. You're already running code, and you already know the condition. What good would an interrupt do?

Steve

formatting link

Reply to
Steve at fivetrees

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.