Shop OBEX P1 Docs P2 Docs Learn Events
ASM/ADC Question — Parallax Forums

ASM/ADC Question

tom90tom90 Posts: 55
edited 2008-02-01 13:51 in Propeller 1
I have been writing code to control a max 1270 ADC.· Most of the code is in assembler but I pass
the final value back to a cog running spin to output the final ADC value.· This isn't fast enough!

Is there any way I can output my ADC value directly from assembler (without going through the hub)
to something like hyperterminal or vb?· (Something like the debug.dec statement only for assembler).

Or is there any other way of doing this that is much faster?

Thanks
Tom

Post Edited (tom90) : 1/31/2008 9:18:44 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-31 21:23
    You can output your ADC value directly from assembler, but it's complicated and it won't do what you want.
    Hyperterminal or VB is already way slower than anything you'd write in Spin because of the serial communications.
    Even at 115KBps, you're converting the ADC values to character strings, then adding additional text in the form of
    "ADC Value: ", then blanks after the value ... all of which takes time to transmit. You need to go back to basics and
    think about what you want to accomplish overall. For example, do you want to convert a series of values at maximum
    speed, then display them? If so, what do you want to use as a trigger to start? Perhaps you need to buffer values?
    Perhaps you need to buffer values and stop when a display trigger occurs, then display the last "n" values? If speed is
    of the essence, you may want a parallel ADC rather than the multichannel serial ADC you're using.

    I didn't have a chance to look in detail at your assembly code, but it seems like the timing may be too fast for the ADC.
    At the 20MHz clock you're using, most instructions take 200ns which is a 5MHz rate. I don't know how you've hooked
    the ADC up, but you need to take at least 3 instructions to do a clock to get a 2MHz rate. Make sure your timing is correct.
  • bambinobambino Posts: 789
    edited 2008-01-31 22:33
    tom90,
    Two points that will speed you up a little.
    Use the built in counters to feed the 1270 a clock and waitpeq and waitpne to sync with the clock and strobe line.
    Leave cs low instead of switching.

    As mike said though, serial out is a bottle neck, not the asm.
    Also, look at the data sheet, it's possible to start output of the next control word before the last result is clocked in!
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-01 13:51
    To be more precise: The bottleneck is neither the ADC acquisition nor the seriel transmission via FullDuplexSeriell @100 kbaud.

    It is the intermediate handling through SPIN from the binary value to a converted string.

    REPEAT
      IF newData
         div := newData/100
         tx(div+"0")
         newData -= 100*div
         div := newData/10
         tx(div+"0")
         newData -= 10*div
         tx(newData+"0")
         tx (13)
    



    I did purposely not optimize this, to make the point more obvious: This loop delays your processing around 400µs/sample
Sign In or Register to comment.