November 21, 2024, 01:04:18 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Data Table Execution Error

Started by PDoyle, November 14, 2010, 06:42:41 PM

Previous topic - Next topic

PDoyle

Below is a selection from a script I've written for the Prop 2.  It uses data tables to control several DC 16's.

When running this part of the script, the DC16 doesn't turn on Pin 6 when Pin 7 is on.  In other words, it runs the first two lines of the data table but it only turns on Pin 7 in the last two lines.

I've checked everything from the DC 16 board to the ULN chip to the outputs but everything is in working order.  Any advice?


' {$STAMP BS2}
' {$PBASIC 2.5}


'============================ Variables/Pins/Constants   =========================================


Showpins VAR Word
  ShowpinsLo     VAR     Showpins.HIGHBYTE
  ShowpinsHi     VAR     Showpins.LOWBYTE
Pointer VAR Word

Runserout VAR Word
  Addr           VAR     Nib
  Delay2         VAR     Word
Pointer3 VAR Word


Baud CON 6

'============================== Main Program ===============================================

Main:

  PAUSE 3000
  Pointer = 0
  Pointer3 = 578
  GOSUB Run_Serout
  END



'============================== Serout Routines =============================================

Run_Serout:
  READ Pointer3, Word Runserout
  Addr.BIT0 = Runserout.BIT0
  Addr.BIT1 = Runserout.BIT1
  Delay2 = Runserout - Addr
  GOSUB Transmit
  Pointer3 = Pointer3 + 2
  PAUSE Delay2
  IF Delay2 = 0 THEN RETURN ELSE GOTO Run_Serout

Transmit:
  READ Pointer, Word Showpins
  SEROUT Aux, Baud, ["!DC16", Addr, "S", ShowpinsLo, ShowpinsHi]
  Pointer = Pointer + 2
  RETURN


                '       +--- Pin 7
                '       | +- Pin 6
                '       | |
DATA Word %0010000000000000             
DATA Word %0000000000000000
DATA Word %0110000000000000
DATA Word %0000000000000000


'Run_Serout Data:

DATA @578, Word 1000                     
DATA Word 1000
DATA Word 1000
DATA Word 0

bsnut

Your code is VARY hard too understand and do not know why you didn't post the whole code that you have. Here are some of your mistakes that I can see right now.

1) Not using the template that Jon has done for everyone. It would be EASIER too us to read
2) This is your other problem.... DATA Word %0010000000000000 You should have done this.
    DATA Word %00100000, %000000000
3) You didn't asigned a pin for AUX
 
They are so many mistakes, that I can go on for ever. What are you trying to do with the DC16? 

William Stefan
The Basic Stamp Nut

JonnyMac

If you have a very old DC-16 this can happen with specific combination -- it was an odd thing that we missed in testing and almost never affected anyone.   We corrected this issue with the version 1.5 code update, but nobody every sent their boards in for reprogramming.  

You don't have to -- you can update your code like this to get around the issue:

Transmit:
 READ Pointer, Word Showpins
 SEROUT Aux, Baud, ["!DC16", Addr, "S", ShowpinsLo, ShowpinsHi]
 SEROUT Aux, Baud, ["!DC16", Addr, "P",  6, Showpins.BIT5]
 SEROUT Aux, Baud, ["!DC16", Addr, "P", 14, Showpins.BIT13]

 Pointer = Pointer + 2
 RETURN


Adding the red lines will take care of that bit when your output value is in the affected range.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Quote2) This is your other problem.... DATA Word %0010000000000000 You should have done this.
   DATA Word %00100000, %000000000

Actually, Bill, his code is correct and your suggestion isn't.  The compiler sees values between commas as separate, so you cannot break bytes in a word as you've shown otherwise the first will get an additional byte added to it.

I have asked Parallax to add the "_" as a numeric separator in the BASIC Stamp Editor as they do in the Propeller tool.  That would make the line easier to read like this:

DATA Word %00100000_00000000  

Jon McPhalen
EFX-TEK Hollywood Office

bsnut

Jon,
Thanks for pointing it out my mistake. From what I saw the code was some what hard to uderstand.

I am glad you have our friends at Parallax to make the change in the BASIC Stamp Editor for something like this "DATA Word %00100000_00000000" .
William Stefan
The Basic Stamp Nut

JonnyMac

Don't get too excited about me having friends at Parallax... I've asked for many things -- that they acknowledge others have asked for -- but have yet to be implemented.
Jon McPhalen
EFX-TEK Hollywood Office

PDoyle

November 16, 2010, 09:46:57 PM #6 Last Edit: November 16, 2010, 09:49:48 PM by PDoyle
Quote from: JonnyMac on November 15, 2010, 07:55:21 AM
Transmit:
 READ Pointer, Word Showpins
 SEROUT Aux, Baud, ["!DC16", Addr, "S", ShowpinsLo, ShowpinsHi]
 SEROUT Aux, Baud, ["!DC16", Addr, "P",  6, Showpins.BIT5]
 SEROUT Aux, Baud, ["!DC16", Addr, "P", 14, Showpins.BIT13]

 Pointer = Pointer + 2
 RETURN


Adding the red lines will take care of that bit when your output value is in the affected range.

Thanks Jon, I'll give it a try.

PDoyle

I added the two lines (and the definition for Aux), but I'm getting a momentary flash on Pin 6 rather than a steady on.

JonnyMac

I think it could be something to do with you address trickery in the code, not the serial update.  What are trying to accomplish, specifically?  There may be a cleaner solution in PBASIC.
Jon McPhalen
EFX-TEK Hollywood Office

PDoyle

I'm trying to collapse a large script into a series of data tables.  The tables control the pins of the Prop 2 and of 3 different DC 16's.  The controlling scripts look like this.

Showpins VAR Word
  ShowpinsLo     VAR     Showpins.HIGHBYTE
  ShowpinsHi     VAR     Showpins.LOWBYTE
Pointer VAR Word
Runshow VAR Word
  Newpins        VAR     Byte
  Delay          VAR     Word
Pointer2 VAR Word
Runserout VAR Word
  Addr           VAR     Nib
  Delay2         VAR     Word
Pointer3 VAR Word

Aux PIN 14                      'For communications to extensions

Baud CON 6



'============================= Run Show Routine =============================================

Run_Show:
  READ Pointer2, Word Runshow
  Newpins.BIT0 = Runshow.BIT0
  Newpins.BIT1 = Runshow.BIT1
  Newpins.BIT2 = Runshow.BIT2
  Delay = Runshow - Newpins
  OUTL = Newpins
  PAUSE Delay
  Pointer2 = Pointer2 + 2
  IF Delay = 0 THEN RETURN ELSE GOTO Run_Show


'============================== Serout Routines =============================================

Run_Serout:
  READ Pointer3, Word Runserout
  Addr.BIT0 = Runserout.BIT0
  Addr.BIT1 = Runserout.BIT1
  Delay2 = Runserout - Addr
  GOSUB Transmit
  Pointer3 = Pointer3 + 2
  PAUSE Delay2
  IF Delay2 = 0 THEN RETURN ELSE GOTO Run_Serout

Transmit:
  READ Pointer, Word Showpins
  SEROUT Aux, Baud, ["!DC16", Addr, "S", ShowpinsLo, ShowpinsHi]
  SEROUT Aux, Baud, ["!DC16", Addr, "P",  6, Showpins.BIT5]
  SEROUT Aux, Baud, ["!DC16", Addr, "P", 14, Showpins.BIT13]
  Pointer = Pointer + 2
  RETURN

These are accompanied by a brief program and 3 Data Tables.

JonnyMac

November 21, 2010, 10:34:46 PM #10 Last Edit: November 21, 2010, 10:57:12 PM by JonnyMac
As styles make boxing matches, they make programs, too.  I think, stylistically, you'll find my version a little cleaner, as well as being easier to read and update.  Give it a try.  You obviously know enough about programming to modify it to your exact requirements.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Sio             PIN     15                      ' no ULN, SETUP = UP


' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0

#SELECT $STAMP
 #CASE BS2, BS2E, BS2PE
   T1200       CON     813
   T2400       CON     396
   T4800       CON     188
   T9600       CON     84
   T19K2       CON     32
   T38K4       CON     6
 #CASE BS2SX, BS2P
   T1200       CON     2063
   T2400       CON     1021
   T4800       CON     500
   T9600       CON     240
   T19K2       CON     110
   T38K4       CON     45
 #CASE BS2PX
   T1200       CON     3313
   T2400       CON     1646
   T4800       CON     813
   T9600       CON     396
   T19K2       CON     188
   T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000

Baud            CON     Open | T38K4            ' fast baud for EFX-TEK


' -----[ Variables ]-------------------------------------------------------

addr            VAR     Byte                    ' DC-16 address
cycles          VAR     Byte
idx             VAR     Byte

pntr            VAR     Word                    ' table pointer

showBits        VAR     Word                    ' DC-16 output bits
showBitsLo     VAR     showBits.BYTE0
showBitsHi     VAR     showBits.BYTE1

delay           VAR     Word                    ' step delay in ms


' -----[ Initialization ]--------------------------------------------------

Reset:
 OUTH = %00000000 : OUTL = %00000000           ' clear all
 DIRH = %00001111 : DIRL = %11111111           ' set outputs


' -----[ Program Code ]----------------------------------------------------

Main:
 FOR addr = %00 TO %10                         ' loop through DC-16s
   FOR cycles = 1 TO 5                         ' do it 5x per board
     FOR idx = 0 TO 1                          ' play two segments
       LOOKUP idx, [Seg1, Seg2], pntr          ' load segment pointer
       GOSUB Play_Segment                      ' play it
     NEXT
   NEXT
 NEXT
 GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Plays data table at "pntr"
' -- each record is 5 bytes

Play_Segment:
 READ pntr, OUTL, Word showBits, Word delay   ' read record
 SEROUT Sio, Baud, ["!DC16", addr, "S", showBitsLo, showBitsHi]
 SEROUT Sio, Baud, ["!DC16", addr, "P",  6, showBits.BIT5]
 SEROUT Sio, Baud, ["!DC16", addr, "P", 14, showBits.BIT13]
 IF (delay > 0) THEN
   IF (delay > 7) THEN
     delay = delay - 7                         ' remove serial timing
     PAUSE delay                               ' do the delay
   ENDIF
   pntr = pntr + 5                             ' next record
   GOTO Play_Segment
 ENDIF
 RETURN


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

'                       OUTL            DC-16                    timing (ms)

Seg1            DATA    %00000001, Word %0000000000000001, Word  100
               DATA    %00000010, Word %0000000000000010, Word  100
               DATA    %00000100, Word %0000000000000100, Word  100
               DATA    %00000000, Word %0000000000000000, Word    0

Seg2            DATA    %00001000, Word %0000000000001000, Word  100
               DATA    %00000100, Word %0000000000000100, Word  100
               DATA    %00000010, Word %0000000000000010, Word  100
               DATA    %00000000, Word %0000000000000000, Word    0
Jon McPhalen
EFX-TEK Hollywood Office

PDoyle

I like the arrangement of your program.  I'll give it a try.

As it turns out, the error arose in the way I stored the pins in the data table.  Because I defined

ShowpinsLo    VAR     Showpins.HIGHBYTE
ShowpinsHi     VAR     Showpins.LOWBYTE

(backwards, I agree, but a pain in the rear to reverse once I'd written it backwards)
the pins of the code have to be reversed:

SEROUT Aux, Baud, ["!DC16", Addr, "P",  6, Showpins.BIT13]
SEROUT Aux, Baud, ["!DC16", Addr, "P", 14, Showpins.BIT5].

Thanks again for your help.

JonnyMac

Jon McPhalen
EFX-TEK Hollywood Office