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.

http://kd1jv.qrpradio.com/

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 -

http://www.njqrp.org/


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.

Tuesday, September 2, 2008

FM Tracking (1 transistor) transmitter schematic


OK, here's the schematic of the FM tracking transmitter I discussed earlier. It's called "tracking" because its original purpose is to be put into a model rocket, then use an FM receiver to track down the rocket after it lands. The basic oscillator / transmitter is unchanged from the web site I listed earlier. I added the FM modulator section and changed up the oscillator and pulse timer part to suit that change.

Revision 3/15/2010 - The diode used in the modulator should be a 1N4148, not 1N4848.  In other words, a common small signal silicon diode.  Sorry about that write-o.

Monday, September 1, 2008

Ham Electronic Homebrewer




This blog is about building electronic stuff, mostly ham radio related. I've been keeping a homebrewer's diary to help me remember what I've done. This puts it on line.

I build RF circuits (usually 1 to 30 MHz) and ham accessories and test equipment. I also mix in microprocessor (or MCU) programming in assembly language.

My diary not only describes what I built but also what I learned, so I don't keep reinventing the wheel. It supplements an Excel file called where I'll keep measurements in tabular or sometimes graphical form.

I'm constantly getting excited about new projects and getting them 90% done (or even less), then getting distracted by something else. My diary -- blog, helps me pick up where I left off when I get back on track.

I'm currently building a receiver which started with the HYCAS (from QST) IF amplifier with AGC and will include things like some of the audio sections of the R1 receiver and a LO (VFO) that will first be the NJQRP AD9851 DDS but may be a PLL/VCO driven by a DDS eventually.

But now I'm sidetracked learing to program ATmel ATMega 8-bit microcontrollers as an alternative to the PICs I've been doing for some time.

OK, here's some of what I've been up to lately.

8/2/2008

MFJ-4225 P/S thermostatic fan control
Not much homebrewing lately as I’ve been playing with my new K3. But one thing I’ve been wanting to do is to quiet down the fan on the MFJ-4225 power supply in keeping with the quiet fans of the K3 and the new Dell laptop.

For more organized info, schematic and photos, see my web page:

http://pages.suddenlink.net/wa5bdu/fan_control_page.html

First I made some temperature measurements. The P/S has two heat sinks, one with two devices mounted to it and one with just one. Using a LM34Z sensor glued to the heat sink, I measured the temperature at 20 A load for 10 minutes. It went from 74.5 F to 115 F at 5 minutes and 132 F at 10 minutes. But then I realized the sink toward the middle of the unit was getting hotter. So I moved the sensor there and did the test again. Ambient was 79F. In 5 minutes T was 134 F, in 10 it was 138 F.

I also experimented with running the fan at lower voltage. It got very quiet at less than 11 volts, but with the cover back on, it was not so quiet. Pulling air through the perforated cover made the difference. The fan current was 127 mA at 14.9 V and reduced to 80.6 mA at 10 volts. So a 2N7000 with a rating of 200 mA could handle it.

Goals:
I don’t like noisy fans. I also don’t like noisy fans that start, run for a few seconds, stop again, and repeat. If the unit is hot enough to require a fan, I want it to run long enough to cool the sink down a little.

I don’t think the fan is too critical in this P/S, so I decided to go with a temperature reached after 5 minutes at 20 amps load. In this way, it might never come on during light duty operation and listening. If it does come on, I want a deadband of about 10 degrees at the heat sink before it goes off. If the 20 A load continues, the fan might never go off, which would be OK.

I was going to use a comparator (LM319A), but couldn’t find my chips. My next choice was an op-amp that could be driven rail to rail and work on a single 5 V supply. For a chip with high saturation voltage of 5V and low saturation voltage of 0V, they hysteresis is 5 / (N + 1) where N is the ratio of the feedback resistor to the input resistor. I used 390 k and 10 k for a hysteresis of about 5/40 or 0.125 volts or 12.5 degrees F.

The LM34Z is kind of over-kill for this application, but it made calculating settings easy. It’s output is directly proportional to temperature, so volts * 100 = temperature in degrees F. I considered using a Vbe multiplier as a sensor. To maintain a constant deadband, the op-amp’s supply voltage needs to be constant, so I used a 78L05 regulator. The LM34Z will work off 5 volts, so I connect it to that bus.

Since the fan’s current draw is low, the 2N7000 works as a switch. One could handle the current OK, but I put two in parallel for conservatism. The fan goes in the return (to ground) lead. I cut the black wire to the fan and connected the end from the fan to the drains of the MOSFETs. The other end of the black wire is ground and goes to the board for its ground. I shaved the insulation from the intact red wire and tapped off another wire to go to the board’s 78L05 regulator’s Vp/s input.

Load test –

From loading to 20A to fan ON: 2 min, 5 sec, remained loaded one more minute, then unloaded
Time for fan to go off after unloading: 1 min, 12 sec

August 10, 2008

Working with the Arduino Decimila board Mike gave me for my 60th. Today I used a Vbe multiplier for a temperature sensor and have the thing reporting temperature via the serial link. Here’s some info from my Measurements.xls sheet and from my source code:

Using analog input to read temperature

My sensor is the Vbe junction voltage of a 2N3904 NPN transistor

I have it in a Vbe circuit, so it amplifies its own signal

The circuit is

1k6 ohms from 5V to collector
3k3 ohms from collector to base
1.6k ohms from base to emitter
emitter to ground
The output voltage is the voltage from collector to emitter
about 2 volts is room temperature

I put the transistor (wired to the multiplier circuit and DMM) in
an ice bath and in boiling water

Ice bath: (32F) 2.157 volts (cheating, I only had resolution to 0.01 V)
Boiling point: (212F) 1.578 volts

Note that the slope is linear, so my change is -3.22 mV / DEFG

In the Arduino, ice bath gives 443 - 444 counts or 2.163 -- 2.167 volts

Also was reading in EDN about how long a good capacitor can hold a charge. It can be a long time, maybe days. But if you measure it with a 10 MEG meter, you’ll discharge it. So I’ve got it hooked to the gate of a MOSFET. From 12V battery, 47k to the drain, source to ground, 0.22 uF polystyrene (the big green ones) to gate from ground. Charged the capacitor to 5 volts and let it go.

I had checked the drain at various voltages. The MOSFET will stay ON (conducting, so the drain is near 0 volts) from 5 volts all the way down till about 1.8 volts, where the drain will be at 9.85 volts. When gate voltage drops to about 1.99 volts, the drain voltage is about 50 mV. As of now, it’s been holding 0 volts for about 6 hours.

This 0.22uF poly held its charge for about 4 days before being accidentally discharged. Next I tried an ordinary 0.1uF ceramic disk. It held up for about two to three days.

August 16, 2008

I’m working on the audio amplifier for my receiver. I’m going to use the famous R1 direct converstion receiver board (QST 8/92 or your EMRFD disk) with modifications and gain reductions. And I won't need so much audio filtering with all those expensive miniature inductors.

Diplexer. I’m not buying all the expensive parts of the original R1 for filtering and diplexing. So I eliminated all the components between the mixer and the 6.8uf coupling capacitor. I went to VE3BPO’s page to read about post-mixer diplexers and selected on that uses two equal valued inductors and two equal valued capacitors. VE3BPO makes his crossover at 1kHz, but I want mine to work on phone and CW so I divided his component values by 3 to triple the bandwidth.

Things looked good on LTSpice, even after I had to substitute the available 3.5mH chokes for 3.3mH calculated.

I got these things built plus put the mixer on the board. It’s a SMT ADE-1, so I used one of Rex’s little adapters to adapt it to the board. (W1REX of http://www.qrpme.com/)

August 17, 2008

I got the DDS-60 card connected to the ATmel Butterfly demo board and Steve Weber’s software. It was necessary to read three PDFs, one for each of those items, to get them working together.
The DDS-60 runs on 12VDC but no more than that. I routed the input power (presumed 13VDC) through two diodes before the DDS-60 power input pin (#8). The DDS-60 puts out a 5VDC power level for other circuits and I routed that to the Butterfly. As suggested by Steve, I put a 10uH choke in series with that lead.

The DDS-60 can put out over +10 dBm and with the on-board pot I was able to adjust it down to +7 dBm.

So now I have a local oscillator I can use for starters. I still need to program in the offset and a pot or divider to handle bandswitching.

Next I need to build either the BFO or the rest of the audio amplifier.

August 24, 2008

Built the dual JFET BFO from QST 9/04 technical correspondence and feedback in Oct. and Dec. 2004 QSTs. Also used in a QEX January 2008 article.

It oscillates around 8003 kHz without much tuning range. The article called for a parallel mode crystal. I may need more C or some series L if I need to go lower.

With the scope, I measure 0.68 Vp-p output across the 1k resistor with no load. The amplitude hardly changes at all when I drop the supply voltage from 13V all the way to 8V. The frequency is 8003.5 kHz with one of my ECS crystals.

Tuesday – Tried adding 82p in parallel with the 18p on the gate side of the crystal, but it stopped oscillation. Put in a BG Micro crystal (CTS) and now I can get to 8001.07 kHz. Note that adjusting the trimmer does affect amplitude, though. Note that the center of the filter (500 Hz) I designed is about 8000.500 kHz. So for 400 Hz note, I need either 8000.100 or 8000.900 BFO frequency. With the CTS #2 crystal, I got to 8000.950 kHz.

I’ll need an amplifier with about 8 dB gain to follow it, having a 50 ohm output Z.

I’ve considered using a logic gate like 74HCT, 74HC, 74AC, 74ACT to drive the product detector. I built a circuit consisting of a 74AC04 with gates in parallel. The oscillator described enough didn’t have enough swing to drive it. I built the logic circuit with one inverter having 100 k-ohm feedback to increase sensitivity, and it drives the other four gates in parallel.

I drove the circuit from the DDS-60 and it did work, producing 4.5 Vp-p into 50 ohms at the scope. It has some high frequency ringing on the leading edge though, operating at 7 MHz. Maybe loading the input would help. (Nope, it didn’t.) As far as symmetry, the relative high and low times were 3.62 and 3.4 (times 20 ns for absolute). One guy uses a pot to DC bias the input at near Vcc/2 and adjusts for equal high and low times.
After going through all this, I'm asking myself -- Is there really much value in a super low phase noise oscillator for a BFO? For the LO, sure. I may go to a more conventional circuit such as a Colpitts.

I also have been working on the DDS-60. Actually, I’ve been improving my PIC DDS source code by looking at Steve Weber’s code for calculating the PI (phase increment). I’m now using a "real" 64 bit by 32 bit division to get rid of all the tricks. It can calculate a PI in 750 us on a 20 MHz (crystal) PIC 16F88. (The "stopwatch" feature of MPLAB's debugger is great for figuring out stuff like this.)

A 1% Voltage Standard-

I got tired of my meters telling me different things, so I put a MC1403 2.5VDC reference chip on a RS perf board. Input voltage can be 5 to 40 VDC. Output is 2.5 VDC +/- 25 mV, or within 1%. I also put in a divider of two 1.78 k resistors to give 1.25 VDC output. I might add an op-amp to go up to 10 VDC too.

Sears DMM --- RS DMM --- Harbor Freight $3 DMM
2.5 ........................ 2.50 ........... 2.49 (on 2.5V tap)
1.248 .................... 1.252 ......... 1.256 (on 1.25V tap)

I did this because I've been having a problem with the Radio Shack DMM being about 0.5 volt low (at 13V) compared with the Sears unit. It turned out the problem was with a cheap / bad test lead which I threw away. (Molded banana on one end and alligator clip on the other.) I wouldn't have thought that a crummy test lead could cause a voltage reading error into a 10 M-ohm meter, but it did.

August 25, 2008

I built this Tracking Beeping FM Transmitter

http://www.jbgizmo.com/page22.html#schamatic

from the web. It’s a single 2N2222 with a tank circuit in the collector lead, operated common base. Base drive is from a 4011 (4093) NAND gate package with an oscillator to produce tones and another to gate the first one ON and OFF. The transmitter is keyed on and off by this arrangement. It’s called a 108 MHz transmitter, but even after I reduced the fixed collector cap to 18 pF, I still had to trim it up to reach 87 to 88 MHz. It’s making a strong signal in my receiver but not much tone. I’m thinking about applying the audio to a varicap in the tank.
Will it oscillate with continuous DC base drive, not pulse stream? Yes.

The six turns of #26 AWG on a 1/8 inch drill bit gives 0.108 uH inductance.
See below for more comments on this thing and my 9/2/08 entry has my revised schematic. Super simple one or two transistor transmitters or receivers fascinate me. I had a hard time believing a single 2N2222 would work as an oscillator / transmitter at ~100 MHz, but it does.

8/26/08

Worked on the model rocket transmitter some more. On the original, I couldn’t hear much of any modulation, probably because it’s AM. So I FM’d it by adding varactor FM modulation. I used a 1N4848. I calculated that for 25 kHz deviation I’d need about 0.014 pF capacitance change. So my driving voltage needed to be pretty small too. I swapped out the 74C11 for a 74C14 hex Schmidt trigger. I don’t need the AND gate because one timer pulses the TX on and off and the other now goes to the modulator. The standard RC logic gate oscillator uses three gates and an inverter gives six per package while an AND gate only gives four. So the gating oscillator is running at 1 Hz and the audio oscillator at 800 Hz.

It works and sounds good. Still sensitive to antenna configuration and placement and body position too. Works best with the oscilloscope connected. Some sort of antenna isolation would help. I tried playing some music through it with no luck – I guess oscillation stopped.

8/27/2008

I had an email exchange with Baltasar (Canary Islands) on QRP-L about losses in a ferrite transformer. He followed up with these measurements:

"I made your test. I wound 2 11-turns winding on the toroid.
First, I put the two windings apart (i.e. w/o touching each other)
and I measure the following losses:
f=3.5MHz -> L=1.96dB
f=7MHz -> L=4.55dB
f=14MHz -> L=8.67dB
f=21MHz -> L=11.52dB
f=30MHz -> L=14.26dB
Conditions:
Power input -> -20dBm
0.6mm diameter wire.
Then I coiled the second winding over the first winding. I got no losses, only 0.2dB losses at 30MHz. It seems that the windings have to be very near to get full power transfer. "

That surprised me so I did my own test with 11 turns separated on opposite sides of the core. Here’s what I got

Sorry about HTML not allowing tabs or white space ...

...MHz ...... Loss (dB)
...1.8 ........... 0.5
...3.5 ........... 1
...7 .............. 3
...14 ............ 6.3
...21 ............ 8.5
...28 ............ 9.2

So sure enough, he's right. I always thought that with high-mu toroids, coupling would be high even if the windings were physically separated. Guess not.

Now I’ll need to repeat with the windings overlaid.

I also worked on the FM Tracking Transmitter some more. Tried taking the output off the emitter and it did make for less frequency shift with body capacitance, I think. I also decreased the tank fixed cap to about 15 pF and the trimmer to a 2 to 8 pF unit. Now I can get up above 92 MHz. I also tried modulating with music again. This time I had some success, but it was lo-fi for sure.

September 1, 2008

I wrote my first routines for the Atmel ATMega169 butterfly – a routine to put my name to the LCD. I’m pretty pleased that it worked the first time because programming this LCD is complex -- not like the Hitachi standard at all, and I’m also dealing with a whole new set of opcodes.