Shop OBEX P1 Docs P2 Docs Learn Events
my head is Spinning :) — Parallax Forums

my head is Spinning :)

whiteoxewhiteoxe Posts: 794
edited 2009-10-21 21:46 in Propeller 1
I·have only just connected to a breadboard(used regulater 1Amp and 16volt Capacitors) and hoped it would allwork ,yep no prob!

After working through the PE Labs ( couple of times i started getting the hang of it but still working through them again especially the Counter Modules.
·· Seems some basic languages provide commands whereas the spin language reqires the use of Objects to get the same things done with some extra coding; making it a little more complex.

One thing I tried to do is use one cog to send a serial data and have another Cog use 'fullduplexserialplus[noparse][[/noparse]2]'
·send·the serial mesage to the terminal , can you offer a little help here??

·I tried for a few hours, even the Debug.Start(30,31,0,57600)
and Debug.Start(16,0,0,56700) didnt seems to anything but hang program or fill trminal with rubbish!

Does the 'fullduplexserial' only work with the Parallax Terminal.

There are also Basic commands such as readdac to converent digitalto analog or commands to read from analog to digital.

I gather getting the hang of COUNTER MODULES will be the way to go. I have more questions but Ill keep experementing before i post again.

THX11_38 [noparse]:)[/noparse]
·
·
·

Comments

  • lonesocklonesock Posts: 917
    edited 2009-10-20 23:44
    Just a quick note: you need to be using the crystal as a clock source (i.e. not RCFAST or RCSLOW) to get the timing precision required for serial communication (and for TV and VGA output).

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • whiteoxewhiteoxe Posts: 794
    edited 2009-10-21 07:25
    Thanks but I actually did use the external crystal cry.gif Thanks for ensuring I had the crystal done right, it was. I have managed working through the PE Labs, I am learning pretty slowly put up to now its all been going well.

    The code below is probably rubbish but i just wanted to show what I am doing. My experence is so basic I did a jig when I got the prop hooked up without knowing what a capacitor even was and using a 16V C instead of a 6.3 volt, then I used a 1 amp 3.3V regulator which the diagram said a 400mv(think) I got the potemeter RC working and everyother LAB. I did find the counter module confusing till i read it 3 or 4 times then it sunk in.

    I dont really get why I have to use a capacitor RC delay when another type of basic chip i used a little while ago read the potimeter using a readac command to measure the voltage being applied to an input pin which was an analog to digital conversion pin.

    I suppose this method type gives all the prop pins greater flexibility. Like there seems to be no serin serout pins or command for them allowing this conversion to be done on any pin.

    I have played a fair bit changing the code and the tx and rx pins, trying to get ·tx("2") from pin1
    and then trying to send the debug[noparse][[/noparse]2].tx("2") to the pin designated 0

    Then i wanted to send that "2"· to the parallax terminal.

    Sorry I have mucked about so much with the code its all looking a bit back to front but whatever I made no or little progress. Can anyone comment on my above dilemas ?


    var
      long Stack[noparse][[/noparse]40]
      byte thechar
      
    con
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    obj
      Debug[noparse][[/noparse]3] : "FullDuplexSerialPlus"
    PUB Sendtrial
        Debug.Start(31,30,0,57600)
        Debug.tx(debug#cls)
        dira[noparse][[/noparse]1..4]~~
         '
          cognew(cogget,@Stack[noparse][[/noparse]0])
          cognew(cogsend,@Stack[noparse][[/noparse]20])
        waitcnt(clkfreq + cnt)
        repeat
          waitcnt(clkfreq * 1 + cnt)
          debug.str(string("mike"))
          
    PUB CogGet
         Debug[noparse][[/noparse]3].Start(17,1,0,57600)
       repeat 
         waitcnt(clkfreq * 2 + cnt)
         debug[noparse][[/noparse]3].tx( debug[noparse][[/noparse]3].rx)
            
    PUB CogSend
       Debug[noparse][[/noparse]2].Start(16,0,0,57600)
       repeat
         waitcnt(clkfreq * 2 + cnt)
         debug[noparse][[/noparse]2].tx("2")
    

    · PPS· := whats the largest voltage capacitor that might be able to be used setting up a breadboard with
    the two regulators ...25?
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-21 09:20
    Hello greenspinner,

    First of all. In the circle of beginners You are OUTSTANDING GOOD !
    You maybe think: "hum ? why that ???"

    Because you posted your code regardless of what bugs might be into it.

    To all other beginners: EVERY Member in this forum is really friendly !
    So feel free to post or attach your code regardless of how messy or buggy it might be !
    This is the BEST WAY to get quick advice and correction !!

    OK now to your code:

    you don't have to start new cogs for everything
    send and receive can be done in a repeat loop. See code below.

    if you want to start several cogs declare a NEW stackvariable for each cog instead using parts of on big array
    using parts of an array. This is a source of bugs ! Different NAMES are much more sure to use the right one.

    For sending serial data to the PC you just need a serial driver like FullDuplexSerialPlus ONCE
    short democode

    CON
      'it's very important to set these constants !!
      'Otherwise serial communication will NOT work !    
      _clkmode = xtal1 + pll16x  
      _xinfreq = 5_000_000
    
    OBJ
      Debug : "FullDuplexSerialPlus" 'serial connection to PC       
    
      
    PUB Main 
      'you have to adjust the baudrate n the terinalprogram on the PC to 115200 baud
      Debug.Start(31,30,0,115200) 'start(rxpin, txpin, mode, baudrate) :
      '"rx" and "tx" viewed from Propeller-Chip Propeller-Chip-PIN-Tx ----> PC
    
      Debug.Str(string("Serial driver started",13))
      Debug.Tx(13)
    
      repeat
        Debug.Str(string("Hello World",13))
        Debug.Tx(13)
    
    



    don't code so much nestings as a real beginner

    don't code things like

      debug[noparse][[/noparse] 3 ].tx( debug[noparse][[/noparse] 3 ].rx) 
    
    



    the line above does the following
    wait for a byte to be received from driver 3
    and after received it send it over driver 3

    BUT as the receive is done first this code waits endlessly for something to be received

    more sense would make

      debug[noparse][[/noparse] 2 ].tx( debug[noparse][[/noparse] 3 ].rx) 
    
    



    driver 2 send what driver 3 has received still not very good as this would send around in circles endlessly
    with no feedback to you (over debug to PC) to see what is going on

    try this code

    CON
      'it's very important to set these constants !!
      'Otherwise serial communication will NOT work !    
      _clkmode = xtal1 + pll16x  
      _xinfreq = 5_000_000
    
    OBJ
      Debug   : "FullDuplexSerialPlus" 'serial connection to PC       
      Serial2 : "FullDuplexSerialPlus" 'serial connection Prop-to-Prop-pins       
      Serial3 : "FullDuplexSerialPlus" 'serial connection Prop-to-Prop-pins       
    
    
    VAR
      byte char
      long No
    
        
    PUB Main 
      'you have to adjust the baudrate in the terinalprogram on the PC to 57600 baud
      Debug.Start(31,30,0,57600) 'start(rxpin, txpin, mode, baudrate) :
      '"rx" and "tx" viewed from Propeller-Chip Propeller-Chip-PIN-Tx ----> PC
    
      Debug.Str(string("Serial driver to PC started",13))
      Debug.Tx(13)
    
      Serial2.Start(16,0,0,57600) 'start(rxpin, txpin, mode, baudrate) :
    
      Debug.Str(string("Serial driver on pins 16,0 started",13))
      Debug.Tx(13)
    
    
      Serial3.Start(17,1,0,57600) 'start(rxpin, txpin, mode, baudrate) :
      Debug.Str(string("Serial driver on pins 17,1 started",13))
      Debug.Tx(13)
    
      'with this parameters you have to connect PIN 0 to PIN 17 and PIN 1 to PIN 16 always Tx with Rx of the other side
      repeat No from 0 to 10
        Serial2.Tx(48 + No)      'send  ASCII-Code for "0", "1", "2" ...."9"
        Char := Serial3.Rx  'receive
    
        Debug.Str(string("received character",13))
        Debug.Tx(Char)      'send  ASCII-Code for a "1"
    
    




    If you want to debug what is going on add debugoutput after EVERY SINGLE step like this

    CON
      'it's very important to set these constants !!
      'Otherwise serial communication will NOT work !    
      _clkmode = xtal1 + pll16x  
      _xinfreq = 5_000_000
    
    OBJ
      Debug   : "FullDuplexSerialPlus" 'serial connection to PC       
      Serial2 : "FullDuplexSerialPlus" 'serial connection Prop-to-Prop-pins       
      Serial3 : "FullDuplexSerialPlus" 'serial connection Prop-to-Prop-pins       
    
    
    VAR
      byte char
      long No
    
        
    PUB Main 
      'you have to adjust the baudrate in the terinalprogram on the PC to 57600 baud
      Debug.Start(31,30,0,57600) 'start(rxpin, txpin, mode, baudrate) :
      '"rx" and "tx" viewed from Propeller-Chip Propeller-Chip-PIN-Tx ----> PC
    
      Debug.Str(string("Serial driver to PC started",13))
      Debug.Tx(13)
    
      Serial2.Start(16,0,0,57600) 'start(rxpin, txpin, mode, baudrate) :
    
      Debug.Str(string("Serial driver on pins 16,0 started",13))
      Debug.Tx(13)
    
    
      Serial3.Start(17,1,0,57600) 'start(rxpin, txpin, mode, baudrate) :
      Debug.Str(string("Serial driver on pins 17,1 started",13))
      Debug.Tx(13)
    
      'with this parameters you have to connect PIN 0 to PIN 17 and PIN 1 to PIN 16 always Tx with Rx of the other side
      Debug.Str(string("Enter repeat loop",13))
      repeat No from 0 to 10
        Debug.Str(string("just before Serial2.Tx(48 + No)= send"))
        Debug.Tx(48 + No)      'send  ASCII-Code for "0", "1", "2" ...."9"
        Serial2.Tx(48 + No)      'send  ASCII-Code for "0", "1", "2" ...."9"
        Debug.Tx(13)
        Debug.Str(string("just after Serial2.Tx(48 + No)= send"))
        
        Serial2.Tx(48 + No)      'send  ASCII-Code for "0", "1", "2" ...."9"
        Debug.Str(string("just before Char := Serial3.Rx",13))
        Char := Serial3.Rx  'receive
    
        Debug.Str(string("received character",13))
        Debug.Tx(Char)      'send  ASCII-Code for a "1"
    
    



    Posting code directly into a message take a lot of place. I did it here that other newbees can directly learn by reading it

    For bigger codes than 10 lines use the Post Reply button and the attachment manager
    For a deep analyse of your code attach the COMPLETE code
    use the file - archive - project... function (File-Item of the main-menu of Propeller-tool) see attached picture


    best regards

    Stefan
    So feel free to post as many questions and attached code as you like

    Post Edited (StefanL38) : 10/21/2009 10:31:13 PM GMT
    446 x 268 - 14K
  • whiteoxewhiteoxe Posts: 794
    edited 2009-10-21 21:46
    A Thousands thanks for the deep explanation of what ive done right and wrong! I was definately feeling a backwards in posting my code or the parts of it I could remember,, I almost posted it in the sandbox so less people would see it [noparse]:)[/noparse]

    Your encouragement was very appreciated !!!
Sign In or Register to comment.