Posts

Showing posts with the label PIC

Another interesting mid-level assembler

While I'm still digesting COMFY in my "ample spare time," a post on comp.sys.apple2 mentioned some assemblers from "Ron" having a similar flavor : SPL for the 6502 and PIC0 for PIC 10F2xx microcontrollers . They are apparently implemented in Python, and inspired by Forth. They emit assembler.

Symbolics Rev. C Keyboard Secrets

The ADB adapter has fulfilled its main purpose: providing an example of hardware which can speak to my Rev. C Symbolics keyboard. The apparent trick is that the clock pulses must be narrow, without being too rapid (i.e., a relatively low duty cycle.) A 10 microsecond long low pulse on /CLR, followed 30 microseconds after the beginning of that pulse by the clock going low for roughly 9 microseconds, continuing with a clock period of approximately 50 microseconds does the trick. The ADB adapter pauses somewhat between groups of 11 clock pulses, corresponding to the natural "section breaks" of the keyboard mapping; I don't know if that is strictly necessary. My first crude approximation, using bit-bashing for the PIC with timing loops resulted in Caps Lock and Mode Lock that felt a bit sluggish---needing to be held down relatively long to "lock" or "unlock." The overall cycle time may be important in that regard. In any event, I reconstructed the key...

Baker's COMFY for the PIC?

I encountered Henry G. Baker's COMFY compiler a couple years ago. ( Baker's site contains a text article , a TeX format article, and an Emacs Lisp implementation . The ACM published the two articles COMFY theory and COMFY-65 ) COMFY is not a very high-level language, in the conventional sense, but is an attempt to provide a clean but simple set of control structures on top of conventional machine code. Baker calls it 'medium-level.' The resulting compiler is very small; its main task in life is to automate the generation of branch instructions, which is one of the tedious parts of tightly optimizing assembly programs. Yet it allows as well for arbitrary Lisp-style macros. I found the concept intriguing, but I found the article and the compiler code itself rather obscure. Part of the obscurity is the unconventional names for the 6502 operations, unconventional notation for the addressing modes, and decimal numbers for opcodes (because Emacs Lisp does not accept o...

Beginner PIC mistakes, and detective work

Step 1 in the Symbolics keyboard to PIC project was not as quick as I had hoped. It was pretty easy to generate the reset pulse, and get the serial port to send a clock signal to the keyboard. I then was using an oscilloscope to look at the keyboard response, but various attempts to get the PIC code to light up LEDs in response didn't work at all. In fact, I was being bitten by two bugs, which I used the PICkit 2 in-circuit debug to discover. An array overrun bug (it seems the default radix in MPASM is hex, so reading 16 bytes into a sixteen element array doesn't work! Unfortunately, my byte counter was located after the array, was stomped directly from 6 to zero, missing the "decrement and skip if zero" termination test until the array covered well into register bank 1.) Safety tip of the day: put your counter before the array! Something not addressed in the early lessons: ANSEL. The RX/DT pin of the 16F690 is shared with AN11, and the low bits of PORT C drivin...

Symbolics keyboard to PIC, step 1

The first step is to connect the Symbolics keyboard to the PIC. I am using the 16F690 which comes with the PICkit 2 starter kit on the low pin count demo board (Microchip DM164120-1). The keyboard cable mates to a 6-pin modular jack (such as Digikey part number 609-1061-ND), which I tacked onto the side of the board. Unfortunately, this mod jack has pin spacings of 50 mil "horizontally" between successive pins, so I bent up the odd pins and soldered the even pins to the demo board. Mod jack pin Keyboard function PIC function PIC pin marking 6 GND 5 GND (N/C) 4 Vdd 3 Key Data RX/DT RB5 2 CLK TX/CK RB7 1 /CLR RC5 RC5 My first task will be to power up the keyboard, code a scanning loop, and try to detect keystrokes for a single key, such as the Left Control Key, displaying the count of key-down events in binary to the LEDs connected to RC0-RC3. If the keyboard is not debounced by the internal microcontroller, the count will not inc...

Debouncing switches

I made a little exercise out of compacting the example "switch debounce" code that the PIC tutorial examples uses. My next exercise will be to improve the debouncing in the "reverse variable speed LED rotation by pressing switch" by interleaving the debouncing check into the delay loop. As it stands, when the rotation is slow, the example can miss brief switch pushes. My glorious savings of three instructions is documented on a separate page . One nifty trick I found through Google that might be very helpful if I have to debounce 88 keys on a Symbolics keyboard (naturally, the same number as on a piano) is called " vertical counters ." This consists basically of replacing counter increments with boolean operations, which can be easily performed in parallel, if the corresponding bits for multiple counters are grouped in register-sized words. This page shows how to use a four-count two-bit vertical counting scheme to debounce eight switches in paralle...

Learning more about PIC

A few comments about the PICkit 2 learning experience. There's a slight bit of polish that could be applied to the example code. A few redundant instructions, such as Extraneous operations setting register pages In A-to-D examples, the data sheet seems to say the 5 microsecond settling time is needed only when changing the input source, not for every conversion, as in the examples For the 5 microsecond interval, a few of those microseconds are covered by the non-NOP instructions before the conversions In one of the variable-speed rotating bits examples, the carry flag is not explicitly cleared when it needs to be clear. When I modified the example to change the sign of the pot setting-to-delay conversion, I would sometimes set the carry, putting extra bits into the display. Took me a good fifteen minutes to debug that. I think a few extra instructions are wasted using the W register and an explicit move to the file register when the file register destination could be...

Making lights blink...

My latest diversion is a Microchip PICkit2. The idea is to make something that can understand the Symbolics keyboard I have, and then connect that something to other things that can speak Apple Desktop Bus (ADB), PS/2 keyboard protocol, or USB, in roughly that order. If I can make something that takes a multi-button PS/2 mouse and a Symbolics keyboard and connects both to a MacIvory, I could be set for beautiful three-button mousing and classic keyboarding on my Lisp Machine. I've mostly traced out the schematic of my Rev. C Symbolics slim-line keyboard (thank god for simple two-layer boards!). Rev. C has LED's in the Caps Lock and Mode Lock keys, in contrast to this picture of the similar Symbolics Rev. B keyboard . Compared to the Symbolics 3600 keyboard schematic , mine is roughly similar, but unfortunately has a 40-pin microcontroller (an Intel 8749H, a member of the MCS-48 family) soldered in. I am certain I could make something work with the simple protocol the 3600 key...