interrupts

I have a very simple application with 6 sensors each controlling one of 6 servos. Each sensor generates a 20ms pulse when detection occurs and the corresponding servo should change from one limit to the other.

My program works but is insufficient. It appears that the processor polls input pins serially. The more inputs polled the higher the latency between polling cycles. The outcome is that the servos change position when sensing occurs only intermittently. Going to an interrupt implementation should eliminate the polling latency and fire the servo code immediately upon sensor detection.

The Atom Pro manual lists WKPINT_0 through WKPINT_5 interrupts. I have the interrupts enabled in the program and all the jump to labels set. However, no sensor signals are ever caught regardless of the pin being used. Does anyone know to what pins on the Mini Atom Bot Board WKP0 through WKP5 are connected? Thanks.

If you’re good with programming, have you considered FSM?

FSM is Finite State Machine programming model that allows a simulated multi-tasking program routine. How it works is the way code is executed. The traditional way is linear, meaning that the code has to wait until a particular function is complete before moving on to the next line.

With FSM, the code can send pulses to several servos in increments while executing other lines of code. So by removing the 20ms pause command, your code moves on to other lines of code, then goes back to move the servos a little bit more until they reach the proper destination. The speed at which the micro can execute lines of code allows for several servos to move seemingly at once all while the sensors are being read also.

Here is a link with more information on this:

bluebelldesign.com/FSM_explain.htm

To get into interrupts on the AtomPro you need to get the h8-3664 hardware manual as well. Just enabling the interrupt jump point(the label you specify in the ONINTERRUPT command) doesn’t enable most interrupts. You ussually have to set bits in different control variables(registers) depending on the interrupt you are interested in. For example the IEGR2 register(interrupt edge select register 2) has bits in it to select the edge to trigger the WKP0-5 interrupts on. You must also set the correct bits in the PMR5 register to enable the WKP pins to cause interrupt instead of being used as standard I/O pins. You also need to enable the interrupts. Use the enable command to enable the interrupts you are trying to use. The enable command handles the IENR1 register for you so you can ignore that one. Also in the case of the WKP interrupts the IWPR flag register is handled automatically by the interrupt system.

So the basic procedure for using the WKP0 interrupt is:

[code]ONINTERRUPT WKPINT_0,MyWKPIntHandler0 ;point to where I want to go when an interrupt on WKP0 accurs.
PMR5.bit0 = 1 ;enables pin as WKP interrupt instead of normal I/O
IEGR2.bit0 = 0 ;this is the default so doesn’t have to be in your code. Pin will interrupt on a falling edge.
;Change to 1 to interrupt on a rising edge.
enable WKPINT_0 ;sets the IENR1 bit to enable the WKP0 interrupt

main
;main program code here
goto main

MyWKPIntHandler0 ;On entry the IWPR bit for Wkp0 is automatically cleared.
disable ;with no arguments disable disables the global interrupt enable flag

;do my handler here

enable ;re-enable global interrupt flag.

resume ;you must always resume(not return) from an interrupt or you will eventually crash.[/code]