Пример #1
0
def main():
    print "These are the connections for the digital to analogue to digital test:"
    print "jumper connecting GP11 to SCLK"
    print "jumper connecting GP10 to MOSI"
    print "jumper connecting GP9 to MISO"
    print "jumper connecting GP8 to CSnA"
    print "jumper connecting GP7 to CSnB"
    print "jumper connecting DA1 on J29 to AD0 on J28"
    raw_input("When ready hit enter.")

    # enable and access SPI
    spi = gb_spi.gb_spi()
    spi.setup_spi()

    # The value returned by the A to D can jump around quite a bit, so
    # simply printing out the value isn't very useful. The bar graph
    # is better because this hides the noise in the signal.

    print "dig ana"

    # repeated write followed by read
    # from 0 to 256 stepping by 32
    for d in range(0, 256 + 1, 32):
        if d == 256:
            dac_val = 255 * 16
        else:
            dac_val = d * 16
        spi.write_dac(1, dac_val)
        time.sleep(0.01)  # allow output to settle (10 ms)
        v = spi.read_adc(0)
        # v should be in range 0-1023
        # map to 0-63
        s = v >> 4
        print "%3x %04d" % (dac_val, v),

        # show horizontal bar (repeated '#' characters, then spaces)
        print "#" * s,
        print " " * (64 - s)

    # repeated write followed by read
    # from 224 down to 0 stepping by -32
    for d in range(224, 0 - 1, -32):
        dac_val = d * 16
        spi.write_dac(1, dac_val)
        time.sleep(0.01)
        v = spi.read_adc(0)
        # v should be in range 0-1023
        # map to 0-63
        s = v >> 4
        print "%3x %04d" % (dac_val, v),

        # show horizontal bar (repeated '#' characters, then spaces)
        print "#" * s,
        print " " * (64 - s)

    print ""
Пример #2
0
def main():
    while True:
        chan = raw_input ("Which channel do you want to test? Type 0 or 1. ")
        if (chan == '0' or chan == '1'):
            break;

    chan = ord(chan) - ord('0');

    print "jumper connecting GP11 to SCLK"
    print "jumper connecting GP10 to MOSI"
    print "jumper connecting GP9 to MISO"
    print "jumper connecting GP8 to CSnA"
    print "Potentiometer connections:"
    print "  (call 1 and 3 the ends of the resistor and 2 the wiper)"
    print "  connect 3 to 3V3"
    print "  connect 2 to AD%d" % chan
    print "  connect 1 to GND"
    raw_input ("When ready hit enter.")

    # enable and access SPI
    spi = gb_spi.gb_spi()
    spi.setup_spi()

    # The value returned by the A to D can jump around quite a bit, so 
    # simply printing out the value isn't very useful. The bar graph
    # is better because this hides the noise in the signal.

    # repeated read
    for r in range(100000):
        v = spi.read_adc(chan)
        # V should be in range 0-1023
        # map to 0-63
        s = v >> 4;
        print "\r%04d" % v , 
        # show horizontal bar (repeated '#' characters, then spaces)
        print "#" * s,
        print " " * (64-s),
        time.sleep(0.0001)   # short_wait() replacement (0.1ms)

    print ""
Пример #3
0
def main():
    while True:
        chan = raw_input ("Which channel do you want to test? Type 0 or 1. ")
        if (chan == '0' or chan == '1'):
            break;

    chan = ord(chan) - ord('0');

    print "These are the connections for the digital to analogue test:"
    print "jumper connecting GP11 to SCLK"
    print "jumper connecting GP10 to MOSI"
    print "jumper connecting GP9 to MISO"
    print "jumper connecting GP7 to CSnB"
    print "Multimeter connections (set your meter to read V DC):"
    print "  connect black probe to GND"
    print "  connect red probe to DA%d on J29" % chan
    raw_input ("When ready hit enter.")

    # enable and access SPI
    spi = gb_spi.gb_spi()
    spi.setup_spi()

    # Most likely, the DAC you have installed is an 8 bit one, not 12 bit so 
    # it will ignore that last nibble (4 bits) we send down the SPI interface.
    # So the number that we pass to write_dac will need to be the number
    # want to set (between 0 and 255) multiplied by 16. In hexidecimal,
    # we just put an extra 0 after the number we want to set.
    # So if we want to set the DAC to 64, this is 0x40, so we send 0x400
    # to write_dac.

    # To calculate the voltage we get out, we use this formula from the
    # datasheet: V_out = (d / 256) * 2.048


    d = 0x000
    spi.write_dac(chan, d);
    # V_out = 0 / 256 * 2.048 (gives 0)
    print "Your meter should read about 0V"
    raw_input ("When ready hit enter.")

    d = 0x400
    spi.write_dac(chan, d);
    # V_out = 64 / 256 * 2.048 (gives 0.512)
    print "Your meter should read about 0.5V"
    raw_input ("When ready hit enter.")

    d = 0x7F0
    spi.write_dac(chan, d);
    # V_out = 127 / 256 * 2.048 (gives 1.016)
    print "Your meter should read about 1.02V"
    raw_input ("When ready hit enter.")

    d = 0xAA0
    spi.write_dac(chan, d);
    # V_out = 170 / 256 * 2.048 (gives 1.36)
    print "Your meter should read about 1.36V"
    raw_input ("When ready hit enter.")
  
    d = 0xFF0
    spi.write_dac(chan, d);
    # V_out = 255 / 256 * 2.048 (gives 2.04)
    print "Your meter should read about 2.04V"
    raw_input ("When ready hit enter.")