In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Matthias09 wrote: Hey guys, I have a SX 28 that controls a stepper motor and ultrasound sensors. The sensors are measuring the position of a ball on a beam and the stepper motor turns the beam accordingly (Ball and Beam system). So far I have one big loop in which: 1) Sensors read the ball position 2) angle to turn the beam is calculated 3) and the stepper motor is instructed to turn (cw or ccw) with one step 4) then next loop The problem I have here is that the calculation and sensor read outs take some time which result in a big time one loop needs to run and hence in a non smooth stepper motor movement. I only run one step per loop as the direction of turning the beam can change with every loop. So my idea is: instead of letting the motor wait in every loop for the instruction for the next loop, I could just run it "in background" in one direction and only give him signals when it's time to turn. This signal would come from the main loop that runs simultationously and still keeps on calculating the position of the ball and the direction to turn. Now I know that the SX only has one processor inside, so would it work, when I make this whole thing with an periodical interrupt (rather than a loop). It would look like that in pseudocode: INTERRUPT Every 20ms calculate new directions for stepper if directions <> current direction give signal to stepper to change direction endif MAIN: DO DRIVE_STEPPER direction LOOP Question I have here: - during the execution of the periodical interrupt, is the loop in MAIN still working, or is it stopped temporarely until the interrupt finished working? (which meant I would still have the same problem) - I already have a not periodical interrupt, that fires whenever the encoder (that measures the angle of the beam) detects a change in of it's two channels (Quad). Can I have both kinds of interupts at the same time. Do the interfere somehow? Should I consider anything? Independent of that I have another question. In Debug Mode the motor runs as slow as in normal mode. I use 50MhZ in normal mode, and Debug should only work in 4Mhz (as far as I know) Shouldn't there be a difference in performance? Means the motor should run significantly smoother when not in debug mode? Of course I use the oscillator for the 50mhz. This are my first lines of code, where I think I define the speed of the processor. [code] DEVICE SX28, OSCHS3, TURBO, STACKX, OPTIONX FREQ 50_000_000 [/code] Thanks guys! Thanks! You are great and without your support (on other earlier questions) I wouldn't be where I'm today! Matthias ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=394074 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)