Shop OBEX P1 Docs P2 Docs Learn Events
Program Doesn't run stand alone on dev board — Parallax Forums

Program Doesn't run stand alone on dev board

nige66nige66 Posts: 12
edited 2007-05-10 21:52 in General Discussion
Using professional development board, with sx key,to program SX, program works well with SX key attached, when I try to run standalone, it doesn't seem to run.

I had a break from this programming so I would imagine a fairly straight forward fix.

Using Pulse gen on Development board for input frequency to count, displays freq on LCD

thanks

nige

' Reads a frequency and countspulses then converts to display on serial backlit LCD

'
' Device Settings
'

DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ 4_000_000
ID "SEROUT"


'
' IO Pins
'

PotPin VAR RA.0 ' I/O pin for RCTIME
Sout VAR RA.1 ' output to 2x16
freqin VAR RA.3 ' frequency input
'
' Constants
'

Baud CON "N9600"

LcdI CON $FE ' instruction
LcdCls CON $01 ' clear the LCD
LcdHome CON $02 ' move cursor home
LcdCrsrL CON $10 ' move cursor left
LcdCrsrR CON $14 ' move cursor right
LcdDispL CON $18 ' shift chars left
LcdDispR CON $1C ' shift chars right
LcdDDRam CON $80 ' Display Data RAM control
LcdCGRam CON $40 ' Character Generator RAM
LcdLine1 CON $80 ' DDRAM address of line 1
LcdLine2 CON $C0 ' DDRAM address of line 2
duration CON 900 ' sample count duration
Backlite CON $FD ' back lite command
'
' Variables
'

analog VAR word '
anathou var word
anahun var word
anaten var word
anaone var word
anacalc var word
char VAR Byte ' character to send
idx VAR Byte ' loop counter lcd buffe
idxs VAR Byte ' loop counter speed
line1 VAR Byte(16) ' line 1 buffer
line2 VAR Byte(16) ' line 2 buffer

spd VAR Byte(4) ' speed array
thou VAR spd(0) ' thou
hund VAR spd(1) ' hund
tens VAR spd(2) ' tens
units VAR spd(3) ' units

tmpB1 VAR byte ' subroutine work vars
tmpB2 VAR Byte
tmpW1 VAR Word

' =========================================================================
PROGRAM Start
' =========================================================================

'
' Subroutine DECLARATIONS
'

TX_BYTE SUB 1, 2 ' transmit a byte
DELAY_US SUB 1, 2 ' delay in microseconds
DELAY SUB 1, 2 ' delay in milliseconds
UPDATE_L1 SUB 0 ' update line 1 of LCD
UPDATE_L2 SUB 0 ' update line 2 of LCD
UPDATE_LCD SUB 0 ' update both lines

'
' Program Code
'

Start:
DELAY 750 ' let LCD initialize
TX_BYTE LcdI ' clear screen, home cursor
TX_BYTE LcdCls
pause 50
TX_BYTE LcdI ' clear screen, home cursor
TX_BYTE Backlite ' back light on
DELAY 1
put line1, "RPM: " ' initialize LCD buffer
PUT line2, " "

Main:

count freqin,duration,analog ' read freq (10 us units)

anathou = analog / 1000 ' freq in / 1000 if > 1000 then 1000's will be in anathou LSB
anahun =__wremainder ' anahundred word contains remainder

thou=anathou_lsb ' convert to single byte for use in TXBYTE


anahun= anahun/100 ' anahund / 100 if > 100 then will be in anahun LSB
anaten=__wremainder


hund=anahun_lsb

anaten = anaten/10
anaone=__wremainder

tens=anaten_lsb
units=anaone_lsb

thou = thou + "0" ' convert 1000s to ASCII
PUT line1(6), thou ' move to LCD buffer, in position 6

hund = hund + "0" ' convert 100s to ASCII
PUT line1(7), hund ' move to LCD buffer in position 7

tens = tens + "0" ' convert 10s to ASCII
PUT line1(8), tens ' move to LCD buffer

units = units + "0" ' convert 1s to ASCII
PUT line1(9), units ' move to LCD buffer


UPDATE_L1 ' update LCD
UPDATE_L2

GOTO Main ' do it over

'
' Subroutines Code
'
' Use: TX_BYTE theByte {, repeats }
' -- first parameter is byte to transmit
' -- second (optional) parameter is number of times to send

TX_BYTE:
tmpB1 = __PARAM1 ' char to send
IF __PARAMCNT = 1 THEN ' if no repeats specified
tmpB2 = 1 ' - set to 1
ELSE
tmpB2 = __PARAM2 ' - save repeats
ENDIF
DO WHILE tmpB2 > 0
SEROUT Sout, Baud, tmpB1 ' send the character
DEC tmpB2
LOOP
RETURN


'

' Use: DELAY_US us
' -- 'us' is delay in microseconds, 1 - 65535

DELAY_US:
IF __PARAMCNT = 1 THEN
tmpW1 = __PARAM1 ' save byte value
ELSE
tmpW1 = __WPARAM12 ' save word value
ENDIF
PAUSEUS tmpW1
RETURN

'

' Use: DELAY ms
' -- 'ms' is delay in milliseconds, 1 - 65535

DELAY:
IF __PARAMCNT = 1 THEN
tmpW1 = __PARAM1 ' save byte value
ELSE
tmpW1 = __WPARAM12 ' save word value
ENDIF
PAUSE tmpW1
RETURN

'

' Transfers line 1 buffer to LCD
' -- makes no change in LCD screen position

UPDATE_L1:
TX_BYTE LcdI ' cursor to line 1, col 0
TX_BYTE LcdLine1
DELAY 1
FOR idx = 0 TO 15
TX_BYTE line1(idx) ' transfer buffer
NEXT
RETURN

'

' Transfers line 2 buffer to LCD
' -- makes no change in LCD screen position

UPDATE_L2:
TX_BYTE LcdI ' cursor to line 2, col 0
TX_BYTE LcdLine2
DELAY 1
FOR idx = 0 TO 15
TX_BYTE line2(idx) ' transfer buffer
NEXT
RETURN

'

' Updates the LCD with both line buffers

UPDATE_LCD:
TX_BYTE LcdI
TX_BYTE LcdHome
DELAY 1
UPDATE_L1
UPDATE_L2
RETURN
confused.gifconfused.gif

Comments

  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-05-10 07:07
    Did you try removing the sx-key and reinstalling the resonator
  • nige66nige66 Posts: 12
    edited 2007-05-10 07:30
    You are fast, thankyou. I tried removing the sx key, and cycle power, no change.
    Then tried witha resonator in socket and after power cycled o.k.

    Seems to operate the backlite on first cycle of power switch, but no RPM(freq display), then on second cycle of power works fine display reads RPM freq o.k, change freq changes display, any lines of code that standout that would cause that?

    I some how thought it could operate on an internal resonator, so looks like thats where I made an error.

    looks o.k

    nige
  • nige66nige66 Posts: 12
    edited 2007-05-10 08:12
    TRied a few more cycles of power all o.k, resonator fixed it thanks, code looks o.k.

    nige
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-05-10 20:21
    Nige,

    If you want to use the internal oscillator change the “OSCXT2” entry in the DEVICE line to “OSC4MHZ”. Be aware that the internal oscillator will not be as accurate as an external resonator.

    - Sparks
  • nige66nige66 Posts: 12
    edited 2007-05-10 21:52
    Sparks

    o.k thanks for the info on oscillator
Sign In or Register to comment.