Welp, I’m having trouble tweaking my existing SX code. If I modify the timing of the current code, I’m getting all garbage output — even adjusting small amounts to one side or the other, produces much worse results.
With some help from Guenther and others at the Parallax forums, I’ve pretty much determined that writing SX code that has to deal with two interrupt sources is hard. The two sources in my case are the edge-event, and the rollover event. I’ve long thought that I’m missing edge events because I’m in the middle of an RTCC rollover. I’ve actually seen this happen, but because of the speed and the lack of a scope that can store seconds worth of data — I really can’t narrow down why. Obviously, the timing is off.
A few people in the past have suggested I approach coding this differently than I have — and now that I’m getting more input, it really looks like there is a better method. This different method uses only RTCC rollovers, sampling the data at a high speed, and simply counts the number of rollovers between edges.
This seems like a better method. Even the SX manual suggests polling for detected edges instead of using the edge-detection-trigger method like I am now — exactly because of the conflicts I’m seeing.
I hate to go backwards here, but I’m going to rewrite the code from scratch. The only reason why I don’t like this method is when the next edge occurs, you get this onslaught (ok, either 1, 2 or 3 bits) of data all at the same time. What this means is that you are now working with two storage bytes instead of one. I’m not sure how well SX/B is going to be suited to this.
Another thing I’ve discovered through talking with other people, is that there’s another way of thinking about this problem. I’ve always considered an edge a “1”, and a HIGH a “0” — and this is very true. I’m now thinking about an edge as a BOUNDARY of data bits on the left and on the right of a certain number of place-holder 0’s. So really the data is defined by how many 0’s are in between the 1’s.
Before when I saw a HIGH after an edge, I “stored” a zero. But really, I don’t need to STORE it, I just need to shift left for every HIGH that I see. Sure, the net-effect is the same, but the implementation is a little different — and a little bit easier as well.
I should have the rough draft of the code written today.