In SX Microcontrollers, SX/B Compiler and SX-Key Tool, kgracey wrote: Hey SXers: This is my first time attempting to use the SX's interrupt stack. This portion of the project consists of a Honda engine magneto connected to an SX, with a servo for throttle control. The bigger project is that I've got an alternator connected to the engine for a high-powered robot power plant, but this is where I'm stuck. Basically, I need to control the servo to set the engine's RPM. The signals I'm dealing with look like this: ( insert screen capture of USB Scope) Every 20-50 ms I generate the servo pulse, and meanwhile I'd like to be counting magneto pulses for 1 second. The scope capture above shows the engine in an idle state, so the pulse frequency increases with RPM. I'm able to control the servo and count pulses accurately, but putting these two tasks together is where I need some help. This is my schematic: (insert schematic) It looks like I can generate a periodic interrupt (every 50 ms) to pulse the servo with SX/B's INTERRUPT and RATE parameters. I created some psuedo-code which compiles, though the use of PULSOUT in the interrupt routine will wreck the timing. How can I incorporate the adjustment of a servo timing pulse within the ISR? It seems like I'd use the tix counter to adjust servo pulses. It seems like I need to draw a relationship between ServoVal and tix variables, so that I use tix and HIGH/LOW in the ISR to control the servo, but I'm not certain. I would benefit from a couple more hints. Preliminary psuedo-code is below, so you can understand the approach I'm trying to take (to format this code I used [url=http://www.phipi.com/format/]http://www.phipi.com/format/[/url]). [code] ' ------------------------------------------------------------------------- ' Throttle Feedback Control.SXB ' Magneto counting for Honda Engine / alternator coupling ' to set an RPM between two values ' ------------------------------------------------------------------------- DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX FREQ 4_000_000 ' ------------------------------------------------------------------------- ' I/O Pins ' ------------------------------------------------------------------------- Servo PIN RA.1 OUTPUT Magneto PIN RB.4 INPUT CMOS RCCircuit PIN RC.3 INPUT ' not used in this code ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- HighThrottle [b]CON[/b] 130 LowThrottle [b]CON[/b] 190 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- ServoVal [b]VAR[/b] [b]Word[/b] analog [b]VAR[/b] [b]Word[/b] RPM [b]VAR[/b] [b]Word[/b] MagnetoPulses [b]VAR[/b] [b]Byte[/b] tix [b]VAR[/b] [b]Byte[/b] ' ------------------------------------------------------------------------- INTERRUPT 200 ' ------------------------------------------------------------------------- ISR_Start: INC tix ' update tix counter [b]IF[/b] tix = 10 THEN ' every 50 ms tix = 0 PULSOUT Servo, ServoVal ENDIF ISR_Exit: RETURNINT ' ========================================================================= PROGRAM Start ' ========================================================================= Start: ServoVal = LowThrottle CountRPMs: COUNT Magneto, 1000, MagnetoPulses RPM = MagnetoPulses * 60 [b]IF[/b] RPM < 3000 THEN ServoVal = ServoVal - 5 ' increase throttle [b]IF[/b] RPM > 4000 THEN ServoVal = ServoVal ' hold throttle [b]IF[/b] RPM > 5000 THEN ServoVal = ServoVal + 5 ' decrease throttle ENDIF ENDIF ENDIF GOTO CountRPMs [/code] Thanks for any help ahead of time. Ken Gracey Parallax, Inc. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=147881 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)