Shop OBEX P1 Docs P2 Docs Learn Events
Dummies guide to interrupts — Parallax Forums

Dummies guide to interrupts

Alex41Alex41 Posts: 112
edited 2007-08-13 16:34 in General Discussion
Hello,

I do have a question about using interrupts.·I'm using SX/B.

I've read that using interrupts can yield inconsistent results when using commands such ac RCTIME and other time sensitive commands in the main program. Can I solve this by having the interrupt run continuously? This may throw off a result from a RCTIME command as to not be the real time, but as long as the result is consistant - I don't see the big deal.

I would like to use the interrupt to read a frequency so it would be running continuously.

I'm still having a few issues setting up a program to use interrupts, as at this point I find the examples a bit confusing so I don't have a specific example to reference. Also I'm fairly new at this also.


Thanks for any help,

Alex

Comments

  • BeanBean Posts: 8,129
    edited 2007-08-10 02:51
    Alex,
    There are several ways to handle this. The trick is to make the interrupt routine take the same amount of time everytime it is run.
    You also want the interrupt to run very often, but be very quick. This will give the most consistant results.

    The other method is to incorporate the RCTIME procedure into the interrupt routine.

    Can you post your code ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-08-10 03:02
    I have been looking at your past post in order to understand this one and this thread came to mind by Gunther Daubach Pulse-Stretching, using an SX controller··

    I could be wrong, but it looks like your trying to fine tune a fuel injection system. Products like the K&N Power Comander for EFI motorcycles are just pulse strechers.
  • Alex41Alex41 Posts: 112
    edited 2007-08-10 17:49
    Bean,

    Here is my code without interrupts as I don't have a workable code for using them. This is what·I have come up with so far. I'm new to this so it may look a bit crude·smile.gif·

    I'm reading a square input frequency in the range of about 70hz to almost 200hz, so we are talking slow freqs here. The output frequency does not need to be in sync with the input frequency.

    I use the PULSIN command to read the input frequency, then read the potentiometer using RCTIME. The capacitor is small - 0.01 uF so I·was hoping to squeeze than in between a pulse and it appears to work. The output I get from the RCTIME is 0 to 53 so I use the IF THEN command to round off a value above 50 to 50 to use easier numbers.

    Then I do a calculation to apply the pot reading to change the PAUSEUS values to make a square output frequency. This looks a bit messy, but trying to get it to work and then I'll make it more efficient.

    This is very basically working with 2 problems.

    1. The output frequency jumps between 75 and 81 hz. I would assume due to the PULSIN command - hence the reason·I'd like to use·interrupts.

    2. The pot only changes the on and off duty of the output freqency, not the actual frequency. Increasing the pot makes the HIGHs longer and the LOWs shorter with the frequency being the same. Can't really figure out why this is happening, but not overly concerned with it at this point, as I believe I need to use interrupts to solve #1.





    Capt. Quirk,

    Yes, this is for an EFI. I'm trying to slow down the output freq of a Manifold air pressure sensor to get the ECU to cut back on the fuel delivered to the engine. I see those K&N power commanders are for specific applications, which I don't fall under. I have looked for a product to do this online, but haven't found anything yet. Making my own is very educational for me too. Also this would be easy to change the code to get it to work for other ECU's.

    Thanks,

    Alex
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-08-10 18:08
    What frequency range are you looking for and in how many steps? It seems to me that you could use a syncronous ADC (like the ADC0831) to read your pot, then use the value from it to toggle the output bit through the interrupt. For example, using the ADC0831 and an ISR rate of 10 uS you could go from 50 KHz down to 196 Hz.
  • BeanBean Posts: 8,129
    edited 2007-08-10 18:13
    Yes, the problem you are having is that PULSIN is going to stop the program until it gets a pulse to read. And RCTIME will take a different amount of time to execute depending on where the pot is. These two factors will prevent you from outputing a frequency that is independent of the PULSIN frequency.

    This could be done with interrupts, but it's going to be messy because all of the functions will have to be done in the interrupt routine. 1) Read the input pulse width, 2) Read the pot, 3) Output a frequency.

    A MUCH easier way would be to use the SX48 protoboard and use one of the hardware timers to generate the output frequency. Now you don't need interrupts at all. Just use the existing code to read the input frequency (with PULSIN) and the pot (with RCTIME).

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Alex41Alex41 Posts: 112
    edited 2007-08-10 18:41
    JohhnyMac,

    My output would be only about a 10-20% freq change from the input. I'll look into your solution with the ADC.



    Bean,

    I like your solution about the SX48. It's relatively cheap too.

    The SX48 can then do those 2 things at once? That timer will run independently from the rest of the program? Sounds like a good, staightforward·solution. I'll have to order one, and play with it.

    Just to be clear the input freq will be changing often, pretty much whenever you push on or let off of the gas pedal so the output will have to change with it to keep the vehicle driveable.

    Which commands will this be using to run the extra timer to create a seperate frequency so I can begin reading up on this while waiting for the chip to come?



    Thanks for the help,

    Alex
  • BeanBean Posts: 8,129
    edited 2007-08-10 19:16
    Alex,
    The SX48 has two 16-bit timers with prescalers.
    Look in the SX/B help file under the TIMER command.

    For generating pulses you just "set it and forget it".

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-08-10 19:27
    Here's a little program that may give you some ideas -- I haven't tested it but feel pretty confident it will do what you want, assuming your input duty cycle is 50%. Again, I haven't tested this so you might need to make minor (or even major) adjustments.

    Edit: New code posted -- original contained error (sorry).

    Post Edited (JonnyMac) : 8/10/2007 8:29:03 PM GMT
  • Alex41Alex41 Posts: 112
    edited 2007-08-10 19:38
    JonnyMac,

    Thanks so much for the program! I'll try it out and see how it works, that sure gives me a good example on using interrupts also. I'll order that ADC chip along with the SX48 board and try both.

    Bean,

    Thanks for pointing me in the right direction, that will get me started.


    Thanks so much guys!!

    Alex
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-08-10 20:22
    Whoops... I just spotted an error in the program; please re-download.
  • Alex41Alex41 Posts: 112
    edited 2007-08-13 16:34
    JonnyMac,

    Thanks for the program. I just ordered a couple of the the ADC0831 chips. Also the SX48 board to try this with the TIMER command.

    Thanks for you help,
    Alex
Sign In or Register to comment.