Shop OBEX P1 Docs P2 Docs Learn Events
Problem with SXSim — Parallax Forums

Problem with SXSim

ValioValio Posts: 29
edited 2009-06-06 18:00 in General Discussion
Can somebody plz explain me why SXSim doesnt
correctly initialyze constant's.


I took some code from included samples:


            ORG    $8

temp        DS    1            ;temporary workspace

            ORG    $10

acc0        DS    1            ;pwm accumulators
acc1        DS    1
acc2        DS    1
acc3        DS    1
acc4        DS    1
acc5        DS    1
acc6        DS    1
acc7        DS    1

duty0        DS    1            ;pwm duty cycles
duty1        DS    1
duty2        DS    1
duty3        DS    1
duty4        DS    1
duty5        DS    1
duty6        DS    1




The 0x and 1x row of reg file in simulator have
random garbage data instead initialized "1"
as it seen from code above.

So why study example doesnt work correctly ?


Thanks a lot.

Post Edited (Valio) : 6/4/2009 10:05:23 PM GMT

Comments

  • PJMontyPJMonty Posts: 983
    edited 2009-06-04 22:04
    Valio,

    You're not initializing those variables, just setting aside space. The "1" means "make this variable take up one byte of memory", not fill this variable with the number 1.

    Thanks,
    PeterM
  • ValioValio Posts: 29
    edited 2009-06-05 05:01
    I see Peter.

    I thought vars could be initialized this way, not just reserving space

    I took PWM.src example from "SX Assembly" directory of installation.
    If it's so, means this code doesnt works, as far vars contain garbage?
    Could you take a look plz.

    All above means it not possible have pre-initialized variables and
    they should be set by itself fro constant. How can I make org directive
    refer to program space ?


    Thanks,
    Alex

    Post Edited (Valio) : 6/5/2009 5:31:24 AM GMT
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-06-06 10:40
    Alex,

    You're a bit too quick to say the program "doesn't work" -- it does; what it doesn't do is initialize the PWM settings. Random values in the duty* variables will be output to the port; the values in the acc* registers will be overwritten every time the interrupt runs so they're it doesn't matter that they're not initialized. If you look at the code you'll find this comment:

    ;Interrupt routine does all PWM work, however, duty0-duty7 values may
    ;be updated here to modify individual PWM pin duty cycles.
    


    This is an invitation to set one or more of the duty* variables before running the loop (at Main). You can use mov for a non-zero value of clr if you want to set a duty cycle register to zero.
  • ZootZoot Posts: 2,227
    edited 2009-06-06 18:00
    e.g.

    acc0        DS    1            ;pwm accumulators
    acc1        DS    1
    acc2        DS    1
    acc3        DS    1
    acc4        DS    1
    acc5        DS    1
    acc6        DS    1
    acc7        DS    1
    
    duty0        DS    1            ;pwm duty cycles
    duty1        DS    1
    duty2        DS    1
    duty3        DS    1
    duty4        DS    1
    duty5        DS    1
    duty6        DS    1
    duty7        DS    1 ; to get a nice round half bank
    
    ; clear duty registers
    CLR duty0
    CLR duty1
    CLR duty2
    CLR duty3
    CLR duty4
    CLR duty5
    CLR duty6
    CLR duty7
    
    ; or loop it....
    MOV W, #duty0
    MOV FSR, W
    :loopme
    CLR IND
    INC FSR
    JNB FSR.3, :loopme
    
    ; looping with non-zero init value
    MOV W, #duty0
    MOV FSR, W
    MOV W, #128 ' preload W with duty val
    :loopme
    MOV IND, W
    INC FSR
    JNB FSR.3, :loopme
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php


    Post Edited (Zoot) : 6/6/2009 6:05:56 PM GMT
Sign In or Register to comment.