Shop OBEX P1 Docs P2 Docs Learn Events
Basic understanding of interrupt — Parallax Forums

Basic understanding of interrupt

ClintClint Posts: 95
edited 2009-09-20 20:22 in General Discussion
Can you·please confirm that if I have an interupt with no prescaler or rate defined in SX/B and my frequency is 50mHz, does that interrupt occur every 5.12us? I have OPTION =·$88.

256/50,000,000 = 0.00000512

Thank you.

Comments

  • ClintClint Posts: 95
    edited 2009-09-20 03:19
    I verified this myself by using the interupt to count up for a timer. It does indeed execute about every 5.12us.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2009-09-20 09:08
    That figure can be adjusted by either changing the crystal/resonator to another frequency or by reseting the ISR's counter to less that 256 clock cycles.
    Using a slower crystal/resonator conserves power consumption while changing the ISR counter will to some degree speed up and find tune the interrupt period.

    There are more complex schemes of adjustment, but I omit discussion of those.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ain't gadetry a wonderful thing?

    aka G. Herzog [noparse][[/noparse] 黃鶴 ] in Taiwan
  • ClintClint Posts: 95
    edited 2009-09-20 16:05
    Thanks for the additional feedback. I am using the SX interrupt to monitor an incremental encoder and the 50mHz speed has prevented miscounts that I was having problems with at lower frequencies. For another part of my program I needed to be able to measure time, so I thought I'd also use the interupt to run a timer. I currently have it incrementing a counter variable on each interupt which I roll back to zero after 48827 counts or approximately 0.25sec. On each roll back, I increment another counter variable which essentially measures time in quarter seconds. It seems to work very well and has matched my stopwatch up to 15minutes.

    I would also like to reduce the power consumption, but I can't risk a miscount on the encoder for this application so dropping the frequency may not be an option.
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-09-20 20:22
    If you're using SX/B the compiler will do the dirty work for you. If you divide 5.12us into 1 you get 195,312.5. To have SX/B take care of the OPTION register for you start the INTERRUPT section with:

    INTERRUPT NOPRESERVE 195_313

    That way, if you change the clock frequency you'll still have the same rate without worrying about recalculating the OPTION register value.
Sign In or Register to comment.