// counting events assume square wave port generates events. every transition from 0 to 1 is an event. we count the number of events over a time period. This time period is easily determined by interrupt, using int1. port 11 is a square wave input with period 1000. Therefore it will generate 10 events during the simulation time (10,000 ticks). If we use time base 4000, int1 will generate 2 interrupts. We can use the first one as 'start' and the second one as 'stop'. The time period will be the interval between interrupts, 4000 ticks. // global ecount, flagstart, lastx // toggle start/stop int1() if flagstart == 0 then flagstart = 1 else flagstart = 0 print(ecount) // sampling input int0() x = readport(11) if lastx != x then if x == 1 then ecount++ lastx = x // update lastx main() settimer0(200) settimer1(4000) flagstart = 0 ecount = 0 lastx = readport(11) while(1) doze()