Shop OBEX P1 Docs P2 Docs Learn Events
Newbie question, about recieving a number and send it to a DAC — Parallax Forums

Newbie question, about recieving a number and send it to a DAC

avionikerenavionikeren Posts: 64
edited 2009-06-01 21:11 in Propeller 1
I can send a number to the DAC and the output of the DAC changes... number 0 = 0 volt and number 255 = 5 volt
but when I try to send a number recieved with rs232 the output will not respond, here is some of the code:

    VARIABLE := serial.Rxdectime(1)
    
    outa[noparse][[/noparse]daccs] := 0
    BS2.SHIFTOUT(dacdata,dacclk,loaddacb,BS2#MSBFIRST,8)
    BS2.SHIFTOUT(dacdata,dacclk,VARIABLE,BS2#MSBFIRST,8)
    outa[noparse][[/noparse]daccs] := 1

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-05-29 03:45
    avionikeren,

    You need to provide more information like what kind of DAC you are using, and how you have it hooked up to the Propeller. Also the pin numbers that you are assigning to dacdata,dacclk,loaddacb.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • avionikerenavionikeren Posts: 64
    edited 2009-05-29 07:04
    But the DAC works perfect, this code outputs 1volt:

        outa[noparse][[/noparse]daccs] := 0
        BS2.SHIFTOUT(dacdata,dacclk,loaddaca,BS2#MSBFIRST,8)
        BS2.SHIFTOUT(dacdata,dacclk,50,BS2#MSBFIRST,8)
        outa[noparse][[/noparse]daccs] := 1 
    

    It`s when I use a variable, it stops working:

        VARIABLE := serial.Rxdectime(1)
        outa[noparse][[/noparse]daccs] := 0
        BS2.SHIFTOUT(dacdata,dacclk,loaddacb,BS2#MSBFIRST,8)
        BS2.SHIFTOUT(dacdata,dacclk,VARIABLE,BS2#MSBFIRST,8)
        outa[noparse][[/noparse]daccs] := 1
    
  • BradCBradC Posts: 2,601
    edited 2009-05-29 09:11
    avionikeren said...

        BS2.SHIFTOUT(dacdata,dacclk,loaddaca,BS2#MSBFIRST,8)
    
    



    It`s when I use a variable, it stops working:

        BS2.SHIFTOUT(dacdata,dacclk,loaddacb,BS2#MSBFIRST,8)
    
    


    Being completely obvious, it's not this is it?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "VOOM"?!? Mate, this bird wouldn't "voom" if you put four million volts through it! 'E's bleedin' demised!
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-29 09:35
    Hard to say what's wrong when you don't send the full code. Did you start the serial interface properly?

    In your code you wait for one ms for a value. That might be to short if you enter it manually with a terminal-program.
    And rxdec/rxdectime need a string delimiter which usually is the carriage return (=13). The delimiter is needed to find the end of the number. 1 is a one digit number, 10 is a two digit number but for the program there is no difference in the 1 in the 1 digit number and the 1 in the 2 digit number, so how should it know how many digits it should expect? That's why you have to send an end of number character. You can set it with SetDelimiter(char) to any other character.

    If rxdectime does not receive a number·AND it's delimiter within one millisecond, it will· ... hmmm .... return -1 or abort. I'm not sure·with this - never used the abort in my code so far.·For me it looks like the abort is unreachable code because the return comes first?! If you don't catch·an abort condition, your program will end.
    If abort is not reached you very likely get a -1 as value which translates to a byte as %11111111.



    Post Edited (MagIO2) : 5/29/2009 9:43:57 AM GMT
  • BaggersBaggers Posts: 3,019
    edited 2009-05-29 09:51
    avionikeren won't the variable be -1 for most of the time? as it will time out.
    you might want to try something like this
      tmp := serial.Rxdectime(1)
      if tmp=>-1
        VARIABLE := tmp
      outa[noparse][[/noparse]daccs] := 0
      BS2.SHIFTOUT(dacdata,dacclk,loaddacb,BS2#MSBFIRST,8)
      BS2.SHIFTOUT(dacdata,dacclk,VARIABLE,BS2#MSBFIRST,8)
      outa[noparse][[/noparse]daccs] := 1
    
    


    ( code is untested, but you should get the idea from the source )
    basically only set VARIABLE when you get a valid value from serial

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • avionikerenavionikeren Posts: 64
    edited 2009-06-01 18:52
    Ah, I just changed the speed from 115200 to 57600 and everything worked perfect, but shouldn`t it work fine at 115200 or is there any tricks to make it work at that speed?
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-01 20:17
    You have to set the same speed on both sides - then it should work - at least if you have the prop running with a chrystal.
  • avionikerenavionikeren Posts: 64
    edited 2009-06-01 21:11
    The prop is a spin-stamp the start of the string is correctly recieved, but not the end, thats why I didn`t think of the serial com to be the problem in the beginning...

    I sent this to the prop: s,101,102,103,104,105,106,107,108,109,

    And this is what it understood at 115200: s,101,102,103,108,109,255,255,255,255
Sign In or Register to comment.