I'm almost done with the serial code coding on the AVR. Working with only 2k of RAM is really quite interesting. I had to delete quite a few log messages just to conserve space. I had never really thought of ASCII text as taking up a lot of space but it really does when each byte counts.
The last remaining piece of serial code for the AVR that I need to write is the part that receives the new settings from the PC. This shouldn't be that bad. Of course, I still need to finish the serial code for the PC side of things before I can actually test it on real hardware.
I realized it would be nice to see some status without having to rely on the serial port so I dedicated a few of the AVRs pins to controlling LEDs. I haven't nailed down exactly what I want the LEDs to mean but at the moment I'm thinking that I want one LED to indicate whether vsync is being received properly (so it will blink rapidly with each vsync), and I want the other LED to indicate any errors. I am thinking a solid LED would indicate all is well, 1 blink per some interval would indicate that the AVR hasn't heard from the PC yet (may be a problem with the serial port) and 2 blinks per some interval would indicate that the serial buffer has overflowed and some characters had to be dropped (something that I want to avoid at all costs but it's tricky when I have such a small amount of RAM for my buffers).
A little more about serial buffer overflow: I put in a log message to say "vsync!" every time a vsync pulse occurred. This would overflow my outgoing transmit buffer in less than a second because the data could not be sent over the 115200 bps serial link fast enough. So things like that are things I need to watch out for; I need to ensure that I am not spamming log messages too frequently.
UPDATE: Well, I did the math (again) about how fast 115200 bits/second really is and it's really not that fast compared to the speed of a 14.7MHz AVR. I posted the above chart to show that each byte comes in (or goes out) every 1,280 cycles on the AVR so that is an eternity of time to do the necessary processing. So spamming "Got vsync!" every field (16.666ms) should work fine because I can send 192 bytes every field.
So I checked my code again and found a bug. I fixed it and I may try spamming "got vsync!" again just to be satisfied that it won't overflow over a long period of time :)
No comments:
Post a Comment