EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Causing an Interrupt on a event

Started by dimi...@gmail.com May 14, 2006
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

dimithri@gmail.com <dimithri@gmail.com> wrote:

> What I'm thinking is along the lines of a software interrupt > generated say in similar fashion to that of timer interrupts.
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.
dimithri@gmail.com wrote:
> 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 >
It is not possible. Check the value in the ADC interrupt. I assume you need to restart the ADC any way.
On Sun, 14 May 2006 20:07:06 GMT, Neil <NeilKurzm@worldnet.att.net>
wrote:

>dimithri@gmail.com wrote: >> 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 >> > > >It is not possible. Check the value in the ADC interrupt. I assume you >need to restart the ADC any way.
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.)
On Sun, 14 May 2006 21:20:27 GMT, in comp.arch.embedded Charles Jean
<alchemcj@earthlink.net> wrote:

>Quidquid latine dictum sit, altum viditur.
http://www.bbc.co.uk/dna/h2g2/A218882 martin
On 2006-05-14, dimithri@gmail.com <dimithri@gmail.com> wrote:
> 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.
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.
> 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.
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
the only reason i can imagine that you want to do this is that you've
already written your an interupt service routine (or borrowed one) and
you want to use that to process your "event" and you don't think you
can call it as a function because you don't know what the return from
interupt is going to do with the address on the stack.  and indeed, i
have no idea what would happen either.  best, i think, to take the
section of the interupt service routine you're trying to call and put
it into it's own seperate function so that you can call it from both
your interupt service routine AND your code.

dimithri@gmail.com wrote:
> 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
<dimithri@gmail.com> wrote in message 
news:1147602463.570610.199420@g10g2000cwb.googlegroups.com...
> 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 >
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.
Tom Lucas wrote:
> <dimithri@gmail.com> wrote in message > news:1147602463.570610.199420@g10g2000cwb.googlegroups.com... >> 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 >> > > 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. > >
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.
<dimithri@gmail.com> wrote in message 
news:1147602463.570610.199420@g10g2000cwb.googlegroups.com...
> 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.
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 http://www.fivetrees.com

The 2024 Embedded Online Conference