Shop OBEX P1 Docs P2 Docs Learn Events
Question about pointers to data addresses for Handheld Persistence of Vision in — Parallax Forums

Question about pointers to data addresses for Handheld Persistence of Vision in

ZootZoot Posts: 2,227
edited 2008-01-21 20:14 in General Discussion
I cranked out a handheld POV module in an Altoids tin Monday evening after seeing a photo at MakeZine.com. It works *really* well -- the kids *love* it and everybody wants to play with it.... initial test code and photos are at bottom. We're trying to figure out a way to take photos of it in "action".

In any case, the one thing that came up is using adddresses of data (DW instructions) as "computed" constants for other data statements. On my Stamp and Motorola projects I like to create a short table of data address pointers so that I can setup bitmaps, text strings, sound scores, whatever, of varying lengths and can change data at any time before compiling without rewriting pointers or having a lot of "if/thens" in my mainline code.

With that in mind, I couldn't figure out an "SX/Bish" way to do the following, and after screwing with it for a few minutes I decided to just to do in ASM -- but am still curious because wouldn't there be a way to do this in straight SX/B?

Msg_00:
DATA $01
DATA $02
DATA $FF

Msg_01:
DATA $01
DATA $02
DATA $FF

' etc

ASM
Msg_Pointers:
DW @Msg_00&$FF
DW @Msg_00>>8
DW @Msg_01&$FF
DW @Msg_01>>8
DW @Msg_02&$FF
DW @Msg_02>>8
DW @Msg_03&$FF
DW @Msg_03>>8
ENDASM




Quasi-related question because the power-on pushbutton for this project wound up on the wrong side (I built it so the label on the tin would be right side up , but then the button didn't fit with the lid, so you can't use your thumb) -- I don't think there is an analogue to REVERSE on the Stamp in SX/B? I'm thinking of emulating it with something like this...

ASM
BANK 0
' ioByte is input...
Reverse_Bits:
   CLR tmpW1_MSB ' will be output byte
   MOV tmpB1, #%0000_0001 ' input mask
   MOV tmpB2, #%1000_0000 ' output mask
:loop
      MOV W, ioByte
      AND W, tmpB1
      JZ :next
         OR tmpW1_MSB, tmpB2
:next
      CLC
      RL tmpB1
      CLC
      RR tmpB2
      TEST tmpB1
      JNZ :loop
:done
   MOV leds, tmpW1_MSB
ENDASM


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
900 x 1200 - 532K
900 x 1200 - 481K

Comments

  • JonnyMacJonnyMac Posts: 9,217
    edited 2008-01-10 18:57
    SX/B does have a REVERSE instruction that is similar to the instruction in PBASIC.

    If you were wanting to pass a pin number, like PBASIC actually uses, this subroutine should do it. It's a bit verbose to keep things simple:

    ' Use: REVERSE_PIN pinNum
    ' -- "pinNum" is 0 (RB.0) to 15 (RC.7)
    ' -- to mimic PBASIC version of REVERSE
    
    SUB REVERSE_PIN
      tmpB1 = __PARAM1 & $0F
      IF tmpB1 < 8 THEN                             ' pin on RB
        tmpB1 = 1 << tmpB1                          ' create mask
        TRIS_B = TRIS_B ^ tmpB1                     ' reverse selected pin
      ELSE
        tmpB1.3 = 0                                 ' make 0..7 for RC
        tmpB1 = 1 << tmpB1 
        TRIS_C = TRIS_C ^ tmpB1
      ENDIF
      ENDSUB
    

    Post Edited (JonnyMac) : 1/10/2008 7:15:55 PM GMT
  • BeanBean Posts: 8,129
    edited 2008-01-10 19:20
    Zoot, I'm pretty sure the SX/B Beta version CAN use labels as DATA elements.

    In PBASIC (and SX/B) REVERSE means to change a pin from an input to an output (or vis-versa). You are wanting a bit reversal. There isn't any command to do that in SX/B. You ASM is probably the way to go. If it was me I'd just do:

    Out.0 = In.7
    Out.1 = In.6
    Out.2 = In.5

    Great project, I've been wanting to do a POV project, but I've never gotten around to it.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • ZootZoot Posts: 2,227
    edited 2008-01-10 19:35
    For fewest instructions, bit by bit may be the way to go -- a generated MOVB is 4 instructions, so that's 32 total, fewer than my loop.

    Bean -- I was going to try address labels as constants in the Beta, but I want to be able to post my code in completed projects smile.gif. Will try it out in the beta this evening or over the weekend.

    Jonny -- I realized I slightly mis-wrote -- I didn't mean the pin command REVERSE in Pbasic, I meant the operation REV, i.e.

    x = REV x 8 ' reverse right-most 8 bits

    (Writing in too many different languages these days -- sometimes I lapse into French, if you know what mean).

    Regardless, I had written something like your routine, but as you prob. know, shifting a register by a variable amount generates a substantial number of clock cycles (it doesn't really matter for this app, but I've been trying to practice getting my code more compact). Your routine is cool though -- I will need to try something like that out possibly to make open-true serial TX/RX truly open true on the SX.

    Generally, I wouldn't need to reverse 'em -- it's just a software hack to correct a technical error; would have been better to wire things properly smile.gif -- next POV in a tin, I'll put button on the other side...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2008-01-10 22:55
    Zoot,

    Your POV device looks neat. I would like to see it in action!

    To photograph it you might try hot-wiring it to be on, then placing it on a phonograph (record player) turntable. If you can get it to stay put without flying off it might allow you to photograph it in motion. Set the camera focus when it is stationary. Then experiment with rotational speed settings and shutter delays. If your camera does not have adjustable shutter settings, choosing a low value ISO setting should keep the shutter open longer.

    - Sparks
  • MikeSMikeS Posts: 131
    edited 2008-01-10 22:56
    Zoot,
    Nice project. Could you post a schematic?

    Thanks,
    MikeS
  • ZootZoot Posts: 2,227
    edited 2008-01-10 23:44
    Will post full workup in completed projects when it's done (text strings, more messages, maybe PWM for fadein/fadeout) and maybe with video or still of it in action.

    Schematic is almost trivial -- see the SX/B code for pin setups -- RC.0-RC.6 is 7 led anodes through 270ohm resistors. RA.0 goes to the RC circuit straight out of the Pbasic and SX/B manuals except I used a 100k pot and .01uf cap because that's what I had on hand.

    Regulator is LM2940 with only a 22uf bypass cap on the output. .1uf cap on Vdd/Vss at the SX. 4-pin prog. header to OSC1/OSC2/Vdd/Vss. The button is SPST NO between the battery and the regulator, so push the button and it starts up. That's it.

    I whipped up a .php web page today that builds SX/B or ASM data statements for bitmaps from a handy little series of "right-reading" check boxes. Makes it much faster to draw pictures and images.... visit it at the link below

    1uffakind.com/robots/povBitMapBuilder.php

    P.S. -- because I shouldn't claim inspiration for the nugget of the idea itself: blog.makezine.com/archive/altoids_and_tin_cases/. I put the LEDs on the short side rather than long because it fits better in your hand.

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

    Post Edited (Zoot) : 1/11/2008 12:03:01 AM GMT
    768 x 588 - 40K
  • ZootZoot Posts: 2,227
    edited 2008-01-21 20:14
    Completed project photos, schematic, code are posted at: http://forums.parallax.com/showthread.php?p=703220

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

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.