Wednesday, September 10, 2008

ATmel versus PIC & Butterfly DDS

Better stick in a picture, this is getting pretty boring. The little white board with LCD display is the ATmel Butterfly development / demo board. It's mounted on a perf board used to accommodate other stuff, such as the NJQRP DDS board, which is mounted vertically behind the Butterfly. To the left is my optical encoder, made from a junked digital bathroom scales. You can get little mechanical encoders for $5 to $10, but they're not as glitch free. However, they are about the size of a quarter compared to this one the size of a beer coaster. The scope is showing the 7.040 MHz output of the DDS.

Since my last post, I've been immersed in learning to program the ATMega MCU in the ATmel butterfly board. The project at hand involves some modifications to Steve Weber's source code for his DDS (direct digital synthesizer) controller software.

Scroll down to his Butterfly Projects link. Steve recently won an ARRL building contest for designing an SSB / CW transceiver for under $50 parts cost.

Check out the NJQRP DDS here, click the DDS-60 link -

My main desire is to add use of a rotary encoder for frequency control. This essentially means I can turn a knob to adjust the frequency instead of, or in addition to using the UP/DOWN positions of the tiny joystick on the board.

Another feature I'll add is the ability to select control of the AD9850 based DDS or the newer AD9851 version. These DDS boards are both described on the NJQRP site, as NJQRP developed and sold them. (New Jersey QRP Club) Steve compiled (assembled, actually) separate programs for the two versions. But since I have both boards I'd like to be able to toggle between the two without changing my firmware.

I have the encoder code working fine and am mostly finished with the version selector. I'm going to save the last version choice in EEPROM so the butterfly can wake up controlling the last chosen version. BTW, there are only two differences between the two from the perspective of the controlling software: (1) the reference oscillator frequency for the '9850 is 100 MHz and for the '9851 it's 180 MHz, and (2) when you send the phase increment data to the chip there's a control byte after the data. On the '9850 that byte is $00 and on the '9851 it's $01. The $01 tells the '9851 to use an internal x6 multipler (PLL) to take the 30 MHz reference oscillator up to 180 MHz.

........ ATMega versus PIC ........

That's what this post was supposed to be about. It's a little early for me to be making pronouncements, but I'm trying out this chip to see if I like it better than the PIC. Both are 8-bit microcontrollers. Both have the usual peripherials built in or at least available in different versions: timers, ADC, PWM, and plain old digital I/O lines. Both can give you fast in-circuit programming and both have versions with on-chip high speed clocks, no crystal needed.

Both companies give you a free and very sophisticated IDE (integrated development environment) that includes an editor, assembler, and source code debugger, plus the ability to program the chip right from the IDE environment. The ATMel may have an advantage in that there's a 'C' compiler available as free or shareware. I don't think ATmel developed it though. I'm not much on 'C' as yet, but may give it a shot.

The big deal difference I was seeking was in a more powerful instruction set. Both MCUs claim to be of RISC design, but the PIC is definitely more RISC-ky. The PIC has 32 opcodes (instructions) while the ATmel 8-bitters have 130. Some of this may be just PR -- some PIC operations can be used or combined (with macros or pseudo-ops) to do more functions, while some of the ATMel instructions seem redundant to each other.

Also, the PIC instructions tend to be universally applicable (I think this is called orthogonality) while the ATmel processer has some instructions specific to a small set of registers, some specific to I/O locations, some specific to static ram addresses and so on.

With all that said though, the PIC doesn't have a true compare instruction and doesn't have a subtract with carry. I recently spent a couple days (off and on) and wrote a page and a half of source code to just subtract one 16 bit unsigned integer from another. Assembly language programmers are masochists, so that kind of thing can be fun ... developing sophisticated programs using primitive stone-axe instructions. But sometimes I long for the power of the 8088 or even the good old 6502.

Not giving up on PICs though. I just have a new toy to play with now.

No comments: