Shop OBEX P1 Docs P2 Docs Learn Events
Weird numbers — Parallax Forums

Weird numbers

LuckyLucky Posts: 98
edited 2010-01-17 23:07 in Propeller 1
I'm trying to communicate with my MCP3208, but all the values that show up on the Debug screen look like weird symbols. I checked that the baud rate in the program and the baud rate on the terminal are the same. I used my oscilloscope to check the data in and out, and the clock and chip select. I calculated the expected value, and the 12 bits that are displayed on the oscilloscope match exactly what I expected(Vin= approx. 2.87V,
·value = 3560, so data in = 110111101000).I'm guessing there is some problem in my program as to reading the data in pin. Here is my program:
 
CON
   ADCclk   = 12       ' ADCclk <------<P12
   ADCdin   = 13       ' ADCdout>------>P13
   ADCdout  = 14       ' ADCdin <------<P14
   ADCcs    = 15       ' ADCcs  <------<P15
OBJ
   Debug : "FullDuplexSerial"
 
PUB Control | dataIn
 
   Debug.start(31, 30, 0, 115200)
 
   dira[noparse][[/noparse]ADCclk..ADCcs] := %1011
   outa[noparse][[/noparse]ADCclk..ADCcs] := %0000
   repeat
      pulse(ADCcs)
      ShiftOut
      pulse(ADCclk)
      pulse(ADCclk)
      dataIn := ShiftIn
      waitcnt(1200 + cnt)
      debug.dec(dataIn)
      debug.str(string(", "))
 
PRI ShiftIn : dataIn | bitCount
   repeat bitCount from 0 to 11
      dataIn |= ina[noparse][[/noparse]ADCdin]
      pulse(ADCclk)
      if bitCount < 11
         dataIn <<= 1
   return dataIn 
     
PRI ShiftOut | bitCount, mask, dataOut, begin
   
   mask := %1000_0000
   dataOut := %0001_1000
   begin := 0
   repeat bitCount from 0 to 7
      if begin == 1
         if dataOut & mask
            outa[noparse][[/noparse]ADCdout]~~
            pulse(ADCclk)
         else
            outa[noparse][[/noparse]ADCdout]~
            pulse(ADCclk)  
      else
         if dataOut & mask
            outa[noparse][[/noparse]ADCdout]~~
            pulse(ADCclk)
            begin := 1
         else
            outa[noparse][[/noparse]ADCdout]~
         
      mask >>= 1  
    
PRI Pulse(pin)
 
   outa[noparse][[/noparse]pin]~~
   outa[noparse][[/noparse]pin]~

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-17 20:35
    There's no _XINFREQ or _CLKMODE declarations. By default, the Propeller starts up using the built-in RCFAST system clock and that's not accurate enough to do serial I/O (or really any time-dependent I/O).

    Assuming you have a 5MHz crystal attached to the Propeller's clock pins, put
    CON
    _XINFREQ = 5_000_000
    _CLKMODE = XTAL1 + PLL16x
    


    at the beginning of your program.
  • LuckyLucky Posts: 98
    edited 2010-01-17 23:01
    OH!! I forgot all about that. I was writing this when my laptop turned off and I didn't save it beforehand, so I had to start all over again and I was so focused on remembering what I had written that I had forgotten to include that. Thanks.
  • LuckyLucky Posts: 98
    edited 2010-01-17 23:07
    IT worked! Thank you so much. I was boggling my brain to try and figure out what was wrong.
Sign In or Register to comment.