In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Zoot wrote: That's fine if that's all that's going to happen -- in my own projects I always use (or like to leave open) the ability to have real-time or other RTC processes (i.e. ms or us counters in the ISR, serial comms w/buffer, PWM, IR generation, IR communication tx/rx, etc.). If the commitment is made to pin generated interrupt *hardware* then it can be a one-way street. For example, in my code above, I presume that the sample time is constant -- i.e. it's counting samples received in fairly precise 10ms frames (although there's no flag for the mainline). So if sample windows were an issue, a pure RTCC interrupt would prevent that. Another way to put it -- with a few changes to bit frame counts, Jon's ISR based serial TX/RX w/buffers could be dropped right in w/o changes to firmware nor hardware. David -- here's a slightly revised version that sets a flag to let the mainline know that the count has been "captured". The scenario below presumes that the mainline will never take more than 10ms before getting around to checking/clearing the flag (to keep this example relatively simple): samplePin PIN RB.0 INPUT Led PIN RB.1 OUTPUT flag VAR Byte ' global var sampleReady VAR flag.0 sampleFrame VAR Word sampleCount VAR Word sampleCaptured VAR Word sampleState VAR Byte __IsrRate CON 400_000 ' will count pulses up to 100khz reliably SampleHz CON 100 ' this many samples per second SampleTicksPerFrame CON __IsrRate / SampleHz INTERRUPT __IsrRate sampleState.0 = samplePin ' capture pin right now IF sampleState.0 = 1 THEN ' this state was 1 IF sampleState.1 = 0 THEN ' previous state 0, must be rising edge INC sampleCount ENDIF ENDIF sampleState = sampleState << 1 ' save current state as previous INC sampleFrame IF sampleFrame >= MySampleRate THEN ' capture sampleCaptured = sampleCount sampleCount = 0 sampleFrame = 0 sampleReady = 1 ' set flag for mainline Led = ~Led ' toggle led -- this would be 50% duty cycle at the sample rate (in this case 100hz) ENDIF RETURNINT Start: Main: IF sampleReady = 1 THEN ' must have captured a value during a 10ms sample frame ' debug or display or watch the value: sampleCaptured sampleReady = 0 ' clear the flag ENDIF GOTO Main ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=406111#m407834 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)