I put the design files for my PS/2 to parallel ASCII adapter online when I ran out of PCBs. I get an occassional question about programming the AVRs. Mostly it is straight forward, however for the RS232 port to work properly, the internal RC-oscillator must be calibrated. Here are some notes about the calibration procedure.
Calibrating and programing is a four stage process. The calib and operation FW are built from the same source. Look in the source for a .IFDEF CALIB to see the difference.
When booting the calib image, it will output a 4Khz square wave out port B.
The calibration is done by connecting a terminal to the serial port and typing one of the following 4 commands.
I – this increases the calibration frequency
D – this decreases the calibration frequency
W – this neither increases or decreases frequency
Q – this quits the calibration process, displays the calibration variable, writes it to the last location of EEPROM and exits the calibration process
You need to connect a frequency counter or scope to one of the “B” port outputs and either increase or decrease the frequency until it is as close as possible to 4Khz. These days, many inexpensive meters have frequency counters that will be accurate enough for this job.
The AVR will not echo the correct character to the RS232 port, when it is out of calibration. The calibration routine will default to decrementing the calibration value if it receives a character that it doesn’t understand. Just keep typing and eventually it will wrap around into a good range, at which point you can fine tune it.
So the four steps are:
1) First load the calib file (AVRPS2_keyboard_calib.hex) and run it to adjust the frequency, as described above. When you have the frequency in a good spot, type Q and the the controller will output the calibration value and also writes it to the last location of the EEprom. For record keeping purposes, it is a good idea to write the calibration value with a marker on the underside of the chip when you are done.
2) I have an AVR dude script that reads the EEPROM – I would run this to get the calibration value into a hex file.
3) Now you can program the regular firmware (PS-2keyboardv3.0.hex). Unfortunately, with AVRdude, this process also erases EEPROM, so you need to reprogram the calibration value into the last byte of the EEPROM.
4) Reprogram the calibration value into EEPROM using the AVRdude script provided, using the EEPROM file you read from the system in step 2 and you are done.
If you are doing a batch of them, once you get things set up, it takes only about 30 seconds or so to go through the scripts, to calibrate and program, each part.
In this design, it would have been nice to use a crystal for clock generation to avoid the calibration hassle. However, that would take two pins of the AVR, which I didn’t have available. I could have freed up a couple of pins by configuring the settings with the keyboard or serial port. It would have taken time to write the software that I didn’t have available, as, at that point, I was in the middle of the inital Apple 1 cloning effort for Mimeo.