inglewoodpete
Senior Member
I have spent about 9 hours trying to get a 20X2 (Firmware C.1/PE Version 5.3.1) to interrupt on alternate rising/falling edges of a square wave.
The input signal has a frequency of about 500Hz, so the is plenty of time for the 20x2 to react to both the rising and falling edges. I am using a 60MHz/150MS/s oscilloscope to observe the input and output waveforms.
I have managed to get the PICAXE to trigger reliably on rising edges.
Is there further documentation on hardare interrupts, other than Manual 2, that I have overlooked?
Yes, I have read the latest command manual (Version 7.0). I have to add that I think it is inadequate in the area of interrupts. There are no examples in the manual - only examples of individual commands. There appear to be a lot of duplication of the bits in the hIntSetup and SetIntFlags commands: are they all required as per my code, or are they interacting? Am I understanding the descriptions correctly?
Finally, I find the statement in the SetIntFlags command description distracting: "Please also see the detailed usage notes under the ‘setint’ command, which also apply to the ‘setintflags’ command." What parts, specifically? Also, the statement "A polled interrupt is a quicker way of reacting to a particular event. It is the only type of interrupt available in the PICAXE system.", under SetIntFlags description. Why do we have hardware interrupts then?
Peter
The input signal has a frequency of about 500Hz, so the is plenty of time for the 20x2 to react to both the rising and falling edges. I am using a 60MHz/150MS/s oscilloscope to observe the input and output waveforms.
I have managed to get the PICAXE to trigger reliably on rising edges.
Code:
Symbol Version = 4 '0.4 27-Sep-2010 68 bytes testing negative triggering
'
#Picaxe 20X2
#No_Table 'Also prevents EEPROM Data from Downloading
'
'Connections for 20x2
Symbol oSynch = B.7 'Leg 11 B.7
Symbol iInfra = pinB.1 'Leg 17 B.1/hInt2
Symbol oLED1 = B.0 'Leg 18 B.0
Symbol oLED0 = A.0 'Leg 19 A.0/Serial Out
'
Init: SetFreq m64
Input B.1 'hInt2
hIntSetup %01000100 ' spare|cond2|cond1|spare||spare|hInt2|hInt1|spare (20x2: hInt2 = B.1)
' Condition Input Mask
SetIntFlags %00000100, %00000100 'set hardware int 2 (B.1) to interrupt
' ||||||||_ bit0: hInt0Flag INT0 (X2 series chips only 28x2 40x2)
' |||||||__ bit1: hInt1Flag INT1 (X2 series chips only 20x2 28x2 40x2)
' ||||||___ bit2: hInt2Flag INT2 (X2 series chips only 20x2 28x2 40x2)
' |||||____ bit3: hIntFlag INT0, 1 or 2 (X2 series chips only)
' ||||_____ bit4: CompFlag Comparator flag (X2 series chips only)
' |||______ bit5: hSerFlag Background receive has occurred
' ||_______ bit6: hi2cFlag hi2c write has occurred (slave mode)
' |________ bit7: TOFlag Timer overflow flag
'
Pause 4000
Low oLED0
Low oLED1
Do 'Do something in the foreground
For w10 = 1 To 200
w11 = w10 + 3
Next w10
Loop
'
' ***** Interrupt Routine **********************************
'
Interrupt:If iInfra = 0 Then
'iInfra is currently on (low). Configure for trigger on next rising edge.
PulsOut oSynch, 10
Low oLED0
High oLED1
hInt2Flag = 0
hIntSetup %01000100 'Next interrupt will be when hInt2/B.1 goes high
SetIntFlags %00000100, %00000100 'Set hardware int hInt2/B.1 to interrupt
Else 'Infra = 1 (normal)
'Infra is currently off (high). Configure for trigger on falling edge.
PulsOut oSynch, 80
High oLED0
Low oLED1
hInt2Flag = 0
hIntSetup %00000100 'Next interrupt will be when hInt2/B.1 goes low
SetIntFlags %00000000, %00000100 'Set hardware int hInt2/B.1 to interrupt
EndIf
Return
Yes, I have read the latest command manual (Version 7.0). I have to add that I think it is inadequate in the area of interrupts. There are no examples in the manual - only examples of individual commands. There appear to be a lot of duplication of the bits in the hIntSetup and SetIntFlags commands: are they all required as per my code, or are they interacting? Am I understanding the descriptions correctly?
Finally, I find the statement in the SetIntFlags command description distracting: "Please also see the detailed usage notes under the ‘setint’ command, which also apply to the ‘setintflags’ command." What parts, specifically? Also, the statement "A polled interrupt is a quicker way of reacting to a particular event. It is the only type of interrupt available in the PICAXE system.", under SetIntFlags description. Why do we have hardware interrupts then?
Peter