Save variable contents to EEPROM at power-down?
N8YX
Posts: 18
Greetings to all - great forum you have here!
I'm planning to use a BS2p-24 as part of an RF synthesizer design. It will be used
to control a DDS chip (AD9851). An optical encoder will be used to "tune" the Stamp,
which will perform some internal math with the "tuning" values and store them in internal
RAM (thanks W4ATK!), then output a control word to the DDS unit.
What I would like to implement is a way to store the last "stored" value prior to power-down.
The encoder might sit for minutes...hours...or seconds after it was "tuned" for the last
time, so an immediate write to EEPROM isn't a realistic solution. What I have in mind
is to monitor the state of the parent equipment's power supply through one of the
Stamp's INPUT pins, then at the first sign of power loss do an immediate write of the data
to EEPROM - which will be a 24LC32 or equivalent. (At most I'll need to keep track of 6 bytes
worth of data, but I don't want to use the Stamp's internal EEPROM area.)
The power-conditioning circuit I'm planning to use with the Stamp will keep +5v on the device for
at least 2 seconds after the main supply cuts out, so this idea is doable in theory.
At power-up, the Stamp will do the reverse...read the EEPROM and look for control-word
data which was captured at power-off. If such is found - and is valid - the Stamp will
send the data to the DDS. If not, a default value for the control word will be used.
Before I reinvent the wheel, has anyone actually done this? If so, do you have source
code and/or some guidelines?
Thanks!
...Fred...
I'm planning to use a BS2p-24 as part of an RF synthesizer design. It will be used
to control a DDS chip (AD9851). An optical encoder will be used to "tune" the Stamp,
which will perform some internal math with the "tuning" values and store them in internal
RAM (thanks W4ATK!), then output a control word to the DDS unit.
What I would like to implement is a way to store the last "stored" value prior to power-down.
The encoder might sit for minutes...hours...or seconds after it was "tuned" for the last
time, so an immediate write to EEPROM isn't a realistic solution. What I have in mind
is to monitor the state of the parent equipment's power supply through one of the
Stamp's INPUT pins, then at the first sign of power loss do an immediate write of the data
to EEPROM - which will be a 24LC32 or equivalent. (At most I'll need to keep track of 6 bytes
worth of data, but I don't want to use the Stamp's internal EEPROM area.)
The power-conditioning circuit I'm planning to use with the Stamp will keep +5v on the device for
at least 2 seconds after the main supply cuts out, so this idea is doable in theory.
At power-up, the Stamp will do the reverse...read the EEPROM and look for control-word
data which was captured at power-off. If such is found - and is valid - the Stamp will
send the data to the DDS. If not, a default value for the control word will be used.
Before I reinvent the wheel, has anyone actually done this? If so, do you have source
code and/or some guidelines?
Thanks!
...Fred...
Comments
There is no need to add an external eeprom. You can simply use the one built into the stamp.
Look in the help file under "READ" and "WRITE".
That's sounds like a very interesting project, please keep us updated.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
Available now... SX-Video OSD module $59.95 www.sxvm.com
Those that would give up freedom for security will have neither.
·
If the onboard EEPROM has a write lifespan of considerably more than
100,000 cycles, I would consider using it...as it were, I would prefer
to use an external chip which could be changed in the event of a failure.
What I don't want to happen is for the Stamp to quit working somewhere
down the road...besides, I'm not sure exactly how much code the control
program will require. I just might end up using all of it!
What I'm up to is the design of a synthesizer which will replace the analog
PTO (permeability tuned oscillator) in the old Drake 7-line amateur radio
gear. Those rigs are highly regarded - even by today's standards - and
the only negative with them is that their main tuning method is somewhat drifty.
This isn't a problem if you're using them for casual shortwave listening, but if
you're using the radios to demodulate RTTY, AMTOR or other digital signals the
units won't cut the mustard. They have to stay on a given frequency and hold
it to +/- 5hz in order to remain in the external demodulator's "passband".
There are a couple of add-on DDS VFO units available for the rigs at present,
but you lose some of the "factory" functionality by using them ...and you cannot
computer-control either of the units.
A Stamp allows me to interface the DDS serially to a PC and use any number
of existing rig-control programs to remotely tune the synthesizer. I can also use
an ADC to read other voltages in the rig; the output of which could be used to
calculate a tuning-offset, or to send a byte-value representation of the rig's
signal-strength meter to the PC...the possibilities are endless.
There are several other ham transceivers which could benefit from this design;
Cubic's Astro 102/103 series readily come to mind. They're as good or better in
performance as the Drakes, and use a PTO for tuning (of course...).
Computer control of these old "classics" would be really neat, as would absolute
stability.
...Fred, 'YX...
·· I have dealt with this issue before in the past, however not on the BASIC Stamp.· The principle should be the same though.· There are two ways I can think of doing this.· One involves having a power supply with a nice set of caps on the output (Filtering caps).· You may have noticed that some equipment, when turned off, doesn't go right off.· This usually happens when the mains voltage is what's being switched off, and sometimes the power supply has a good charge on it's output (filter) capacitors.
·· What I have done is monitor the A/C line directly at the input to the P/S using an opto-coupler.· The output goes to an I/O pin which you monitor in your main program loop.· As soon as power-fail is detected, you initiate a save data routine, which stores critical values to the EEPROM.
·· As a side-note in my applications I had used a battery-backed RTC w/RAM or even battery-backed RAM (Dallas had some good NV-SRAM Chips).· Writing to EEPROM is slower than writing to RAM, so you can write more data before the power finally runs out.· If you had already had a·chip, such as a DS1302 or some other similar chip which had battery-backed RAM on it, you could use that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
The monitor-AC-voltage idea is a good thought; I'll look at doing
just that. These rigs can also be powered from 12VDC, so I may
have to monitor the 12VDC output as well.
I had considered using a Dallas RTC, but given that the assembly
will be placed into the radio I'm leery about introducing a 32.768 KHz
clock oscillator (with attendant harmonic "noise" in the form of square
waves) into the works...
...Fred, 'YX...
·· 12V hmmm?· Well, the idea is to catch the loss of power to the input of the regulator (If you unit uses one, which it should).· Depending on how much power the unit consumes, you may or may not have· sufficient time to perform the same.· You can usually tell just by having the BASIC Stamp write data to the LCD or blink an LED, and when you kill main power see how long it does this after.· If you can see a noticable delay, then you should be okay.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
monitor the rig's separate +12VDC "input" line - but this is doable. I'm planning to use a rather
large follower cap on the Stamp's 5VDC regulator output (10,000-15,000 uF) so a few seconds
of power after shutdown should be obtainable.
Jon - Is there a bit of example R/W code for the 24LC32 floating around here somewheres? BTW,
thanks for the heads-up on pin usage...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I've got some parts to order; already have the Stamp on hand.
Should anyone else be interested in the outcome of this experiment,
stay tuned...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Next step...get the DDS units built. Two are headed my way, along with the optical encoder and a bunch of other required parts.
Got two of the AM-QRP DDS60 units in the mail yesterday. Decided to have a go at building one myself.
www.amqrp.org/kits/dds60/index.html
I've never soldered any SMT stuff before, and I built one of these complete without the use of a magnifier. About
the build process: "Solder wick is your friend"...and darn, those devices are SMALL!
After the unit was finished I dug a Proto-board out of my desk, then installed a BS24p, the DDS60 unit and a few support
components. On to the code...I borrowed a few lines from W4ATK's example and checked the output. The unit appeared
to be generating something but I couldn't find the frequency on a general-coverage receiver. Nor could my counter discern
it.
I began to wonder if I was sending the right data string to the unit...did some digging and came across the following
online tools:
www.analog.com/Analog_Root/static/techSupport/designTools/interactiveTools/dds/ad9850.html
www.analog.com/Analog_Root/static/techSupport/designTools/interactiveTools/dds/ad9851.html
Plug in the reference oscillator frequency, the frequency you wish to generate and the utility spits out a serial and
parallel wordset for each.
Armed with the new values, I modified the code...and sent the program to the Stamp. Lo and behold, a nice strong signal
right where I expected it to be.
I then put together the following pseudocode:
MAIN:
Set Frequency = 6.500.000
Set Frequency = 6.502.000
GOTO MAIN
No delays betewwn the "Set" commands (which are in actuality SHIFTOUT operations).
The goal was to test the set-up time of the DDS60 synthesizer. When I tuned the frequency in with the station's receiver,
I got a nice solid ~240hz buzz...which is what was hoped for. The Stamp communicates with the DDS60 at
9600 baud, and the control "word" that it sends 40 bits long. 9600/40 = 240...proving that I can shift
frequency cleanly at 240 times per second or thereabouts. This is important because the optical encoder I'll be
using for tuning has a 256 p-p-r output; it's wholly possible for a user to spin it at 1 rev per second (or faster).
I'm probably going to use a BS2PX24 in the final design; it communicates @ 19200 baud max and should alleviate
serial-comm speed problems - if any do arise.
Next step: Emulate an optical encoder via the use of a couple of pushbuttons...until the one which is on backorder
finally shows up. Then it's time to start laying out the main carrier board and fitting parts.