Shop OBEX P1 Docs P2 Docs Learn Events
Writting to main memory — Parallax Forums

Writting to main memory

BeginerBeginer Posts: 21
edited 2010-01-17 19:07 in Propeller 1
Could You help me please with writting to main memory (in assy)? I use assy code to measure severally time delays. Its totally 8 values. What can get I these values into spin language (and then to the second object) ? Originally I wanted use pointer and par register, but this dont me go well. (Ihave got one first value only).
Then crossed my mind to write values direct into some memory cells. I use for this wrlong command, but I get all values equal always. I think that Im writting this way into cog RAM, so not into Main RAM... Also Ihave read warning: "Register cannot exceed $1FF"

Could You tell me how can I solve this problem? What Im doing false? Is it possible, somewhere any examle to find?

ThankYou very much!!!

beginer

Post Edited (Beginer) : 12/28/2009 10:00:42 PM GMT

Comments

  • LeonLeon Posts: 7,620
    edited 2009-12-28 20:03
    wrlong should work. How are you coding it?

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
  • Sal AmmoniacSal Ammoniac Posts: 213
    edited 2009-12-28 20:34
    Post your code. It's hard to know what you're doing without seeing it.

    Keep in mind that the wrlong pasm instruction is the only one (along with wrbyte and wrword) that doesn't follow the "destination,source" operand ordering. It uses "source,destination".
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-12-28 21:20
    Take a look at the FullDuplexSerial object. That has hub buffers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
    · Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
  • BeginerBeginer Posts: 21
    edited 2009-12-28 21:57
    Here is my code. At begin the program are the metods that retrieve values that I get in asembler. I dont know what should I writing to memory. I think, obtained values are equal maybe due the $1FF size, that limited required value. Or what You think, where is problem? (sory, I let code in my language)

    Thanks

    beginer
  • SamMishalSamMishal Posts: 468
    edited 2009-12-28 22:40
    Beginner,
    ·
    When you start the Cog you must give it the address of a Variable main Ram that you want to use as the start of a block of ram to write data to from the Cog.
    ·
    So lets say you have an array in the VAR section called Long DataStore[noparse][[/noparse]50]…..so then you must start the cog and pass it the address of the array.
    · okay := Cog := cognew(@StartOfPasmCode,@DataStore) + 1
    ·
    ·
    Then in you PASM code you must save the passed address (inside Par) to a location in the Cog RAM so as to use it· eg (do this at the beginning of your Pasm code)
    ·
    ··········· Mov· StartAddress,Par
    ·
    StartAddress should be defined as a Long or Res· in the Dat section just after the PASM code. You also need to have another Long or Res right after that lets call it ActualAddress.
    ·
    Later when you want to move data to say DataStore[noparse][[/noparse]10] (i.e. the 11th Long) then you would do (assuming the data is in a variable called MyData in the Cog Ram ie. it is also part of the Dat section and is defined as long or res)
    ········· Mov ActualAddress,StartAddress·············· ‘put start address so as
    ········· Add ActualAddress,#40·······························‘to increment it by 10*4 (i.e. 10 longs)
    ········· WrLong MyData,ActualAddress···················‘now write the data to the main Ram
    ·
    You can do the above too with WrByte or WrWord but you then use 10*1 and 10*2 Not 10*4 as the incrementer.
    ·
    Sam
    ·
    ·
    ·

    Post Edited (SamMishal) : 12/28/2009 10:46:05 PM GMT
  • SamMishalSamMishal Posts: 468
    edited 2009-12-28 23:21
    Beginner,

    Here is a program that illustrates what I said. It will write the numbers 9 to 0 in an array·in Hub ram
    from a Pasm program. A meaningless program but it illustrates the action and the pseudo code I
    mentioned above.

    Samuel

    CON
       
      _clkmode = xtal1 + pll16x                             ' Crystal and PLL settings.
      _xinfreq = 5_000_000                                  ' 5 MHz crystal (5 MHz x 16 = 80 MHz).
    VAR
      long  DataBlock[noparse][[/noparse]10]   'to be written to by the Pasm code
      Long  Cog             'to hold the cog number
        
    OBJ
      D    : "FullDuplexSerialPlus"                         ' Serial comms object
    PUB Main|n                                  
      D.Start(31,30,0,115200)                               ' Start the FDSP
      WaitCnt(ClkFreq*2+cnt)                                ' give it time to start
      Cog := cognew(@StartOfPasmCode, @DataBlock)           ' start the cog saving its number
      WaitCnt(ClkFreq+cnt)                                  ' give it time to do its work
      repeat n from 0 to 9                                  ' print out the values of the array 
        D.Dec(DataBlock[noparse][[/noparse]n])
        D.Tx(13)
      
        
    DAT
    'Pasm program that will write data into Hub Ram
    'it will write the values of a counter (9-0) to
    'the elements of an array in Hub ram [noparse][[/noparse]0] to [noparse][[/noparse]9]
    StartOfPasmCode             org
                                mov     StartAddr, par          'Get Hub-ram array address
                                mov     ActualAddr,StartAddr    'prepare to index into array
    Loop                        wrlong  Counter, ActualAddr     'Write the value of Counter to hub-ram array
                                                                '   WrByte if byte array and WrWord if word array
                                add     ActualAddr,#4           'increment index into array for next write
                                                                '  if the array is byte then #1 if word then #2
                                djnz    Counter, #Loop          'repeat 9 more times
                                
    'variables in the Cog Ram
    StartAddr    long  0
    ActualAddr   long  0
    Counter      long  9
    
    




    Post Edited (SamMishal) : 12/28/2009 11:27:15 PM GMT
  • BeginerBeginer Posts: 21
    edited 2009-12-29 14:06
    ThankYou Sam and others, for Your reply!
    Ihave corected my code. Program is working however in the same way always. Could You browse my corrected code and tell me, wheather some visible error is in the code ?
    It seems, code measure only one first value, the next other are equal. I dont believe, I have false in the function core the program, I think the false is in the writing to memory.
    But all it is posible now. I cant find some false. You can change anything in this code and send me it.

    beginer
  • kuronekokuroneko Posts: 3,623
    edited 2009-12-29 14:38
    What exactly is your program supposed to do? You seem to monitor 4 inputs, and write back some timing information ...
  • BeginerBeginer Posts: 21
    edited 2009-12-29 16:55
    Yes, kuroneko, you have true .
    I have 4 optical sensors, and I monitoring time delay between laser's beam coming(arrival) at 2 from 4these sensors. Totally its 16 combinations, some are empty,
    because are impossible (jmp#nic). When possiblle kombination is hapenned , the value (dataX=end-begin) are calculated. When next possible combination happened, end value is stored into begin and currently values,flags("soucasny") are stored into old values,flags ("predchozi"). and then are currently values ("soucasny") are zeroing.
    Program should continue next... around. I think, idea is visible from code.

    Do you see some false? Some errors?

    Thanks...

    beginer
  • SamMishalSamMishal Posts: 468
    edited 2009-12-29 17:17
    Beginer,

    I will need more time to look at your code....but....from a quick look at it
    it appears that your program DOES NOTHING.

    All those Pub methods are doing nothing except setting a value to the variables.
    Plus you are not even calling them anywhere????

    Your PASM code seems to also put values in the variables of the DAT section

    BUT.....these are not the same..... HUB RAM and COG ram are two different things.

    when the Res Dat variables or the Longs are in the Dat that follows the PASM code,
    they become part of the COG RAM...... they are ALSO part of the HUB RAM too.....

    BUT.....BUT.... the two are different. When the PASM program is copied to the COG RAM
    also the DAT variables that follow are also copied and become part of the Cog RAM, so when
    in the PASM program you write data to them that DOES NOT make the same data appear on
    the variables of the same name in the HUB ram.



    Also when you start the Cog with this line
    · okay := Cog := cognew(@Start,0) + 1

    YOU ARE NOT giving it an address of any Hub Ram so as to be able to write values to that
    area. The zero in red is WRONG.....

    Also I do not see HOW you are monitoring any action of the program. All you are doing
    is sending some CONSTANT values to the PST and that is it. The Spin program STOPS.

    I did not study your PASM code well...... but even if it is doing something I cannot see how you
    can VERIFY that ............ your program is ALL JUMBLED.

    Have a look at the code I posted and see how you need to pass the address of a HUB variable
    to the Cog so that you can use the WrLong to transfer data between the Cog Ram and the Hub Ram.

    Also do not think that the variables in the Dat section are the SAME.
    The ones in the Hub ram are not the same as the ones in the Cog ram even though they are the same
    name.....this is a confusing thing.....that is why you really need a DIFFERENT DAT section for the
    PASM and the SPIN variables.

    If you can explain in WORDS (I know English is not your language but try) what you WANT to do
    maybe we can help more.





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Samuel

    www.robotbasic.com

    Post Edited (SamMishal) : 12/29/2009 6:22:18 PM GMT
  • SamMishalSamMishal Posts: 468
    edited 2009-12-29 17:41
    Beginer,

    I can sort of see what you have done.....you have HARD CODED the addresses in the Hub Ram
    where you want to copy data from the Cog to the Hub......BAD programming.....but OK I will
    accept that and accordingly suggest a correction for the Main method so as to get it "working"

    PUB Main:okay
      Stop
      okay := Cog := cognew(@Start,0) + 1  
      pst.Start(115200)
      waitcnt(250_000_000 + cnt)
      [color=orange]repeat[/color]                         .you need a repeat here to have more than Just ONE TIME output
        [s]pst.Str(String(pst#NL))
    [/s]    [s]pst.Str(String(pst#NL))
    [/s]    pst.Dec([b][color=orange]Long[noparse][[/noparse][/color][/b]$00006500[b][color=orange]][/color][/b])    'you need a Long[noparse][[/noparse]] here to write the CONTENTS of the address $6500 not the VALUE $6500
        [s]pst.Str(String(pst#NL))
    [/s]    pst.Dec([b][color=orange]Long[noparse][[/noparse][/color][/b]$00006610[b][color=orange]][/color][/b])    'and the same with all of them
        [s]pst.Str(String(pst#NL))[/s]
        pst.Dec([b][color=orange]Long[noparse][[/noparse][/color][/b]$00006720[b][color=orange]][/color][/b])    'this is BAD programming to assume addresses like this...but that is another issue
        [s]pst.Str(String(pst#NL))
    [/s]    pst.Dec([b][color=orange]Long[noparse][[/noparse][/color][/b]$00006830[b][color=orange]][/color][/b])
    
    

    See new program below......

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Samuel

    www.robotbasic.com

    Post Edited (SamMishal) : 12/29/2009 6:19:42 PM GMT
  • SamMishalSamMishal Posts: 468
    edited 2009-12-29 18:06
    Hi Beginer,

    I also noticed that you are using the WRONG methods for the Serial object....here is the new
    Main method that outputs correctly to the PST
    PUB Main:okay
      Stop
      okay := Cog := cognew(@Start,0) + 1  
      pst.Start(115200)
      waitcnt(250_000_000 + cnt)
      [color=orange]repeat[/color]                         'you need a repeat here to have more than Just ONE TIME output
        [color=orange]pst.Clear                    [/color][color=blue]'this clears the screen so you won't keep scrolling
    [/color]    pst.NewLine
        pst.NewLine
        pst.Dec([b][color=orange]Long[noparse][[/noparse][/color][/b]$00006500[b][color=orange]][/color][/b])    'you need a Long[noparse][[/noparse]] here to write the CONTENTS of the address $6500 not the VALUE $6500
        pst.NewLine
        pst.Dec([b][color=orange]Long[noparse][[/noparse][/color][/b]$00006610[b][color=orange]][/color][/b])    'and the same with all of them
        pst.NewLine
        pst.Dec([b][color=orange]Long[noparse][[/noparse][/color][/b]$00006720[b][color=orange]][/color][/b])    'this is BAD programming to assume addresses like this...but that is another issue
        pst.NewLine
        pst.Dec([b][color=orange]Long[noparse][[/noparse][/color][/b]$00006830[b][color=orange]][/color][/b])
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Samuel

    www.robotbasic.com

    Post Edited (SamMishal) : 12/29/2009 6:17:17 PM GMT
  • BeginerBeginer Posts: 21
    edited 2009-12-29 18:22
    Its alright. These metods shall get to the main program values, which I measured in secong program in PASM. I sent only this code, main program I didnt send. Its no important, I think. From main program I really call these metods, and next I want doing somthing with them. I want only this simply thing: Get data from PASM to the spin. Then are values accesible to the main program. It does not matter, where I store the values.


    I Have a look at the code what you posted me, I tryied start the program with this configuration, but program are functionless. So I try it this way.
  • kuronekokuroneko Posts: 3,623
    edited 2009-12-30 01:51
    Beginer said...
    I have 4 optical sensors, and I monitoring time delay between laser's beam coming(arrival) at 2 from 4these sensors. Totally its 16 combinations, some are empty, because are impossible (jmp#nic). When possiblle kombination is hapenned , the value (dataX=end-begin) are calculated. When next possible combination happened, end value is stored into begin and currently values,flags("soucasny") are stored into old values,flags ("predchozi"). and then are currently values ("soucasny") are zeroing.
    Let's assume for a moment that the first sensor (senzorPh) constantly delivers 0 (not active?). In this case your code never looks at the other sensors. It's stuck because the tests at wait1 and wait2 always produce Z which satisfies the if_z condition, therefore skipping the tests for the other sensors. This could explain why you only ever see changes for the first sensor.

    Re: 16 combinations, it looks like you only have 4 valid cases (and 12 impossible ones). Why don't you just ignore the impossible cases, i.e. do the 4 valid checks and ignore the rest? There is really no point evaluating every single one.

    As for measurements, it seems you are better off looking at all 4 sensors at the same time, then - when one (or more) of them changes - take action (e.g. start timer). Then wait for the next change etc. How is beam arrival indicated anyway, low or high?
  • BeginerBeginer Posts: 21
    edited 2010-01-02 17:20
    Beam arrival is indicated with LOW... I forgot this tell you. I read your message now .... First senzor wait to first LOW, then the program begin work in loop... I think, I do it so what you write, or not?
  • kuronekokuroneko Posts: 3,623
    edited 2010-01-03 02:30
    OK, so how long are those LOW pulses? Also, do they overlap (i.e. is sensor A still active when sensor B becomes active)?
  • BeginerBeginer Posts: 21
    edited 2010-01-03 19:16
    Only one sensor is active in same time. Pulses lenght depends on speed of lasers beam. Its hard to say you, how is lenght. (But frekvency is 1/60Hz at 10 cm.... )
  • kuronekokuroneko Posts: 3,623
    edited 2010-01-04 02:48
    Let's leave the timing aside for the moment. Knowing that only one sensor is active helped quite a bit. So what happens is
    • catch event on sensor A
    • catch event on sensor B (could be the same as A)
    • make some decision regarding order, write some data
    It seems that only two sensors are sampled anyway. Is that on purpose/work-in-progress?

    An active sensor is represented by 1, inactive by 0. Furthermore, lets say the activation sequence is AABB (looped). This gives us all 4 transitions (AA, AB, BB, BA) and should therefore result in all 4 data locations being written to. Your decision making code looks like this (cut down for 2 sensors).

            cmp     Ap, As wz
    if_z    jmp     #label_0
    
            cmp     Ap, Bs wz
    if_z    jmp     #label_1
    
            cmp     Bp, As wz
    if_z    jmp     #label_2
    
            cmp     Bp, Bs wz
    if_z    jmp     #label_3
    


    Now let's assume that sensor B was activated twice. This means Ap/As are 0 and Bp/Bs are 1. And that's where the problem is. Comparing Ap to As will set the Z flag despite both being zero (inactive). I think what you actually want here is a test which sets a flag only when both Xp and Xs are 1, e.g.

            test    Ap, As wc        '         test    Ap, As wz
    if_c    jmp     #label_0         ' if_nz   jmp     #label_0
    
            test    Ap, Bs wc
    if_c    jmp     #label_1
    
            test    Bp, As wc
    if_c    jmp     #label_2
    
            test    Bp, Bs wc
    if_c    jmp     #label_3
    


    With that modification and a sensor cog - which generates the AABB sequence mentioned above - I am able to exercise all 4 data write paths in your code (prekmitP/L, volnobehPL, volnobehLP).
  • BeginerBeginer Posts: 21
    edited 2010-01-05 21:10
    I think you understand me good. But one again yet. I want to measure time delay beetween 2 detektion at 2 variables sensors (its beetween Ap,As,Bp,Bs). Kombination is currently and last sensors also. Exist also 16 combination. Some combination (or sequence, what you say) are imposiblle, therefore I dont actualize begin variable for this sequence. (its: last sensor prevent only certain actually sensor). Past some detection cannot hapend all of detektion. If possible kombination hapened, time is actualized (=MOV begin, cnt or mov begin,end - I dont know what is better, but it is not important now) and curently values are moved in last (= mov predchoz
  • BeginerBeginer Posts: 21
    edited 2010-01-05 22:08
    And one think yet. At pin these sensers are permanent HIGH (4,5V), when come beam, sensors are at LOW.
  • kuronekokuroneko Posts: 3,623
    edited 2010-01-06 03:39
    Beginer said...
    by the way, You think the writing to memory is not problem? Maybe you have true and some false is in the core of code.
    Writing was never a problem. The code evaluating the 16 combinations is broken (as explained in my previous post).
  • BeginerBeginer Posts: 21
    edited 2010-01-07 20:35
    thank You, I understood your message already. I corrected my code, and kombination 0,0 (cmp a,b) should do nothing also(I think). I didnt see this false. But problem stays again. Could you tell mi please where could be problem now? This is imposiblle ... :-/

    thanks
  • BeginerBeginer Posts: 21
    edited 2010-01-07 20:36
    .
  • kuronekokuroneko Posts: 3,623
    edited 2010-01-08 02:13
    Beginer said...
    But problem stays again. Could you tell mi please where could be problem now?
    Let's assume for a moment that predchoziPh is inactive (0). Your combination evaluation starts with:

            cmp predchoziPh, soucasnyPh             wz   ' 1st check
    if_z    cmp soucasnyPh, #1                      wc
    if_c    jmp #next3
    if_z    jmp #prekP
    
            cmp predchoziPh, soucasnyLh             wz   ' 2nd check
    if_z    jmp #next3
    


    With soucasnyPh inactive (0) you'll end up at next3 (Z set, C set). If it's active (1) the first check makes a decision based on C which is undefined, so you may or may not jump to next3. As soucasnyPh is 1 all the other sensors are 0 which means the second check will set Z and therefore jumps to next3 again. Which means if predchoziPh is inactive your evaluation stops here. End of line.

    From what I gather from your latest source file you want something like this (predchozi??/soucasny??, both active):
    • Ph/Ph: prekP
    • Ph/Pv: rychPL_P
    • Lh/Lh: prekL
    • Lh/Lv: rychLP_L
    • Pv/Ph: rychLP_P
    • Pv/Lv: volnoPL
    • Lv/Lh: rychPL_L
    • Lv/Pv: volnoLP
    So why don't you simply check those 8 cases and if they don't apply then fall through to next3? For example:

            test    pPh, sPh wz     ' perform logical AND without writing result
    if_nz   jmp     #prekP          ' Z is not set when both sensors are active
    
            test    pPh, sPv wz
    if_nz   jmp     #rychPL_P
    
            ...
    
    next3:
    


    Also, all long in your DAT section must be defined BEFORE any res.

    Post Edited (kuroneko) : 1/8/2010 2:57:26 AM GMT
  • BeginerBeginer Posts: 21
    edited 2010-01-17 19:07
    thank you kuroneko, you help me very much !!!
Sign In or Register to comment.