In SX Microcontrollers, SX/B Compiler and SX-Key Tool, jdemeyer wrote: I experimented with this idea. I set Timer 1 up in Capture/Compare mode. The Compare register is set to $ffff. When Timer 1 reaches $ffff, it toggles RB.6 (i.e., low-high-low). This pulse should happen approximately every 1.3 ms (20nS/pulse * 65536 pulses = 1.3 ms). I set Timer 2 up in External Event Mode. In this mode, Timer 2 counts pulses on RC.3. I physically connect RB.6 (from Timer 1) to RC.3 (the external input for Timer 2) and Timer 2 counts the number of times Timer 1 reaches $ffff. I set Timer 2's Compare register to $0bf0 (2288 decimal) and set up for an interrupt when the Compare register and Timer 2 match. The interrupt should occur approximately every three seconds (2288 * 1.3 ms=2.99 s). After the SX48 is programmed, there is a two minute time period in which nothing happens. I set a break point as indicated in the code and there is no interrupt. After two minutes, the interrupt begins to occur regularly but not at the designed time of three seconds. It happens about every six seconds. 1. Why might there be a two minute delay before the code begins to operate as expected? 2. Why does the interrupt occur every six seconds rather than every three seconds? Thanks, Joe [code] DEVICE SX48,OSCHS1 FREQ 50000000 INTERRUPT GOSUB DoSomething T2R1CMH=$08 T2R1CML=$f0 T1R1CMH=$ff T1R1CML=$ff RETURNINT AFlag VAR Byte PROGRAM Start DoSomething: IF AFlag=1 THEN 'break point set here AFlag=0 ELSE AFlag=1 ENDIF RETURN WATCH AFlag,8,UDEC Start: LVL_B=%00000000 LVL_C=%00000000 PLP_B=%01000000 PLP_C=%00000111 TRIS_B=%10111111 'RB.6 is an output TRIS_C=%11111000 RC=%00000000 AFlag=1 T2CNTA=%00000100 'interrupt on compare T2CNTB=%00100011 'timer unrelated,edge detection,divide by one,external clock T2R1CMH=$08 T2R1CML=$f0 '$08,$F0 This is every three seconds T1CNTA=%00000000 'disable interrupts on timer 1 T1CNTB=%00000010 'timer unrelated,edge detection,divide by one,capture/compare T1R1CMH=$ff T1R1CML=$ff 'RB.6 toggles Main: GOTO Main END [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=138101#m138847 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)