Comparator Interrupt and pause

oracacle

Senior Member
Will a comparator interrupt a pause on the 28x2, or is it a case of it being polled after the pause. not worried about the pause after the interrupt has been called.
this is the section of code I am thinking about using this on a 28x2 @16mhz - although I am not 100% happy with the double loop exit, seems a little clunky but should work, in theory at least
Code:
[color=Blue]do
                  let [/color][color=Purple]tempbyte [/color][color=DarkCyan]= [/color][color=Navy]0
                  [/color][color=Blue]do while [/color][color=Purple]tempbyte [/color][color=DarkCyan]< [/color][color=Navy]128
                        [/color][color=Blue]readadc [/color][color=Navy]0[/color][color=Black], [/color][color=Purple]tempbyte
                        [/color][color=Blue]if [/color][color=Purple]row1 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then exit
                  loop
                  if [/color][color=Purple]row1 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then exit
                  high focus
                  setintflags [/color][color=Navy]%00010000[/color][color=Black], [/color][color=Navy]%00010000    [/color][color=Green]'set comparator interrupt flag
                  [/color][color=Blue]pause [/color][color=Purple]time_out
                  [/color][color=Blue]setintflags off
                  low focus
            loop[/color]
if the general consensus is that it will work I will test it when I get home later, else I will go to an incrementing loop of small pauses similar to this (this runs on a 08m2@16mhz), just without the extra sense variable.

Code:
                  [color=Blue]do while [/color][color=Purple]loopnumber [/color][color=DarkCyan]< [/color][color=Purple]time_out [/color][color=DarkCyan]and [/color][color=Purple]sense [/color][color=DarkCyan]= [/color][color=Navy]0
                        [/color][color=Blue]inc [/color][color=Purple]loopnumber
                        [/color][color=Blue]pauseus [/color][color=Navy]102
                  [/color][color=Blue]loop[/color]
 

hippy

Technical Support
Staff member
Will a comparator interrupt a pause on the 28x2, or is it a case of it being polled after the pause.
The most definitive answer often comes from trying it with a simple test program. It seems that SETINTFLAGS interrupts do prematurely end the PAUSE and enter the interrupt routine. I will update the online documentation to reflect that.

The following test code sets both comparators to compare against a low Internal Reference Voltage and interrupt on change so just finger contact with the appropriate pins will trigger an interrupt. Interrupt messages are generated more often than the 60 second pause so it would seem the interrupts do curtail the PAUSE -

Code:
#Picaxe 28X2
#Terminal 9600

PowerOnReset:
  CompSetup %0011110011, %10000001
  Gosub Interrupt_Enable:
  Do
    SerTxd("- ")
    Pause 60000
  Loop

Interrupt:
  SerTxd( "INTERRUPT " )

Interrupt_Enable:
  compFlag = 0
  SetIntFlags %00010000, %00010000
  Return
 

oracacle

Senior Member
had to add a flags = 0 just before the setintflags to stop triggering from the previous input (and holding loop until the input had gone low), but other than that it worked perfectly.
 
Top