In SX Microcontrollers, SX/B Compiler and SX-Key Tool, robotworkshop wrote: Hello, I am stuck at the moment and could really use some help from the rest of you on the forum. At the moment there is one elusive bug in my program that has been driving me crazy trying to find. Another set of eyes could really help. Either I am overlooking the same problem over and over, missed something special in the SX datasheets and documentation, or have just run into some unexplained quirk using SX/B on the SX48. Whatever it is I would like to get this figured out so I can get onto some of the other aspects of my project. I've attached the program so that anyone with an SX48 could try it or you can at least look over the code for any glaring oversights. The program is relatively simple. It uses JonnyMac's ISR based serial routines to receive serial characters (On RA.2) and buffers them in the background. The ISR also checks an encoder connected to port B (pins 0 and 1) and an opto on pin 2 for the center position. If there is any change of the encoder it will update encValue accordingly. If it sees the "Center" it will reset encValue to 0. 0 is the center and is what I was basing the movements from. There is a motor connected to RB.6 for the Speed (driven by the TIMER1 PWM) and direction set by RB.5 These two pins just go to an L298 H-Bridge. Other than that some LEDs are wired up which have been useful for diagnostics. The Main program loop should check to see if any commands come in and address them as they show up. Once that is done (or if none come in) it should go on to control the motor. If there is an active movement going on it will see if it is done and end it is so. If not it will adjust the PWM and keep it going. The program starts up fine but I get one unexpected problem that is throwing off the whole thing. I found this by turning on an LED upon entering RX_BYTE and turning it off as it leaves that function. Upon normal operation I should barely see that LED flicker and only when I am actively sending data to the SX48 via the serial line. The LED is off when it powers up but if I turn the head (which makes the encoder change) for some reason it gets to RX_BYTE and just hangs there. This is a huge problem since while it's there waiting for a character it is NOT updating the PWM for the motor. Since I check rxBufCnt to see if there is anything there before calling RX_BYTE I can't figure out how it is getting there. So, either I have a mistake that I keep overlooking or something deeper is going on. For a moment I thought that perhaps since the encoder is on port B that it might be generating extra Interrupts. Even if that was the case I would have expected that it would just receive a garbled character (as was happening early on with the TIMER1 TIMER before disabling those Interrupts). Getting a garbled character isn't a problem since it would just return from RX_BYTE and it would be thrown away. The problem is how/why is it getting to RX_BYTE when there isn't a character in there to read?? Jon, if you happen to read this have you ever run into a problem like this and could this be another reason why you added an rxReady to the latest version of your code? Any ideas? Pointers? Suggestions? I had thought about possibly moving some of the code for the motor PWM to the ISR and would have to make sure it all gets done well before the next ISR cycle comes through. That may be an option but it still doesn't explain why the program ever gets to RX_BYTE and waits when it shouldn't have ever gotten there unless a character was waiting. Best Regards, Robert ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=254268 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)