Shop OBEX P1 Docs P2 Docs Learn Events
ADC0831 pulsout vs high/low — Parallax Forums

ADC0831 pulsout vs high/low

Howdy, in the code below there's the line "PULSOUT CLK, 210" and I was just wondering why couldn't this just be a high followed by a low?

' -----[ Subroutines ]----------------------------------------------------- 
ADC_Data:   
LOW CLK   
LOW CS   
PULSOUT CLK, 210    
SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8]   
HIGH CS RETURN

Comments

  • PULSOUT has a defined length (210 times whatever the BS-2? units are). HIGH/LOW makes a pulse of whatever length it happens to be.
  • would it not work with high/low or is it a lot faster with pulsout?
  • Don't know whether that would work with that particular ADC or not. Try it and see. But why not just use the PULSOUT?

    As to whether HIGH/LOW is faster/slower than 420 usec (210 times 2 Usec), don't know that either off the top of my head. Set up your measuring device and try it.
  • Yeah sure, I use PULSOUT all the time,I just want to know why. Thanks : ]
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Speed is another consideration. PULSOUT is one command whereas separate HIGH/LOW commands may take more time to execute since each instruction has to be fetched from EEPROM. I'd have to write some code and look at the results on my logic analyzer, but if speed were an issue I would definitely base it on that.
  • Thank you! : ]
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    As a side-note the LOW Clk statement in the subroutine is also a waste of time. I know it's our code, but it should be executed once in the initialization section of the program and that's it. There's no need to make that pin low each time the subroutine is called.
  • Useful to know that! How would you write the PBasic code below into the SimpleIDE C format?
    CS              PIN     0 
    CLK             PIN     1 
    DataOutput      PIN     2
    
  • Franny,

    The ADC0831 requires one pulse on the clock line after being activated to do the
    voltage conversion.

    Maybe this subroutine from StampWorks Experiment # 28 makes more sense.
    Read_0831:
      LOW CS                                      ' enable ADC
      SHIFTIN DataIn, Clock, MSBPOST, [result\9]  ' read ADC
      HIGH CS                                     ' disable ADC
      RETURN
    

    result is a BYTE variable, which is 8 bits, so I am guessing that the extra bit, that isn't needed anyway, just gets dropped.

    In PBASIC, I/O pins can be defined as a PIN variable or a constant (CON).
    This Propeller C lesson defines constants for I/O and also shows how to use SHIFTIN in C.
    http://learn.parallax.com/propeller-c-simple-protocols/bit-masks-better-code

    I am not sure if Jon's (JonnyMac who wrote StampWorks) 9-bit SHIFTIN trick will work correctly in C.
    I didn't get any build errors when I tried it.
  • Cool, so it's const int. Thanks
  • Genetix wrote: »
    Franny,

    The ADC0831 requires one pulse on the clock line after being activated to do the
    voltage conversion.

    Maybe this subroutine from StampWorks Experiment # 28 makes more sense.
    Read_0831:
      LOW CS                                      ' enable ADC
      SHIFTIN DataIn, Clock, MSBPOST, [result\9]  ' read ADC
      HIGH CS                                     ' disable ADC
      RETURN
    

    result is a BYTE variable, which is 8 bits, so I am guessing that the extra bit, that isn't needed anyway, just gets dropped.

    In PBASIC, I/O pins can be defined as a PIN variable or a constant (CON).
    This Propeller C lesson defines constants for I/O and also shows how to use SHIFTIN in C.
    http://learn.parallax.com/propeller-c-simple-protocols/bit-masks-better-code

    I am not sure if Jon's (JonnyMac who wrote StampWorks) 9-bit SHIFTIN trick will work correctly in C.
    I didn't get any build errors when I tried it.

    Extremely useful, Thanks! : ]
Sign In or Register to comment.