Shop OBEX P1 Docs P2 Docs Learn Events
BS2 - inconsistent program run — Parallax Forums

BS2 - inconsistent program run

mojoemojoe Posts: 8
edited 2012-12-30 20:52 in BASIC Stamp
I have one of those AD9851 DDS modules that you find on ebay hooked up to a BS2, on a Board of Education. When I first power on the Board of Education, the DDS module is programmed and I get the correct output. If I switch power off briefly, then back on, the DDS module is not getting programmed correctly and I get no output. If I hit the reset button on the Board of Education, the DDS works every time. It only seems to be a problem after the first power up. This makes no sense to me.

The code is posted below. I have already tried inserting pauses throughout the program to no avail.
' {$STAMP BS2}
' {$PBASIC 2.5}

D7         PIN 3  ' D7 is used as input in 40-bit serial mode.
W_CLK      PIN 2  ' Word Load Clock. Clocks each bit into D7 on rising edge.
FQ_UD      PIN 1  ' Frequency Update. Transfers 40-bit word from input buffer into
                  ' DDS on rising edge. Don't toggle unless valid data is loaded.
RESET      PIN 0  ' Reset. Active high.


Setup:                                                   ' Set needed pins to output and low.
    LOW D7
    LOW W_CLK
    LOW FQ_UD
    LOW RESET


Main:
    PULSOUT RESET, 10                                    ' Pulse Reset for 20 us.

    PULSOUT W_CLK, 10                                    ' Set serial load enable mode.
    PULSOUT FQ_UD, 10                                    ' This works when the serial mode is hardwired.

    SHIFTOUT D7,W_CLK,LSBFIRST,[$00,$00,$00,$00,$00]     ' Clear DDS input register with zeros.
    PULSOUT FQ_UD, 10                                    ' Pulse FQ_UD high for 20 us to transfer register to DDS.

    SHIFTOUT D7,W_CLK,LSBFIRST,[$79,$56,$34,$12,$01]     ' 12.8 MHz output with 30 MHz x 6 ref clock.
    PULSOUT FQ_UD, 10                                    ' Pulse FQ_UD high for 20 us to transfer register to DDS.

    END

Comments

  • mojoemojoe Posts: 8
    edited 2012-12-30 15:32
    I just discovered something else. If I hit the reset button on the Board of Education while power is off, it works every time when I power back on. Seems that something is holding the reset line on the BS2 for a while. Must be a cap somewhere.
  • mojoemojoe Posts: 8
    edited 2012-12-30 17:21
    I found a fix. If I remove the END statement and replace it with an endless DO LOOP, everything works as expected. Something about the END statement putting the Stamp to sleep is messing things up.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2012-12-30 17:24
    "END" means just that, program end. That is why it works after putting the DO LOOP in and removing END.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-30 18:01
    The END statement doesn't completely put the Stamp to sleep. As described in the Reference Manual, at the END statement, the Stamp wakes up to do some internal housekeeping every few milliseconds and the I/O pins will be set to input mode for a short time when that occurs.
  • mojoemojoe Posts: 8
    edited 2012-12-30 18:03
    If you look at my program, I am sending the necessary data to the DDS module only once, after power on. This is all that is required by the DDS module for it to output the desired frequency. If END really was what it says, then I should have had no problems. The fact that END actually puts the Stamp to sleep, with periodic wakeups, and that it changes everything back to inputs, that is what the trouble was. I have just read about this behavior, which is how I came up with the fix. As I mentioned, I inserted the empty DO LOOP at the very end of my program, after I have programmed the DDS once. The DO LOOP does nothing but keep the Stamp from going to sleep and messing with the I/O pins.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-12-30 20:52
    Placing a STOP command at the end of the code works much like the DO...LOOP, not allowing the BS2 to go to sleep.
Sign In or Register to comment.