Sign in

username:

password:



Not a member?

Search basicx



Search tips

Subscribe to basicx



basicx by Keywords

Accelerometer | ADC | ADXL | Adxl20 | AVR | BasicStamp | BX-35 | BX28 | BX35 | COM3 | Compiler | Downloader | EEPROM | Electromagnet | GetADC | GP2D1 | GPS | I2C | IDE | Keypad | LCD | LCD+ | MIDI | Motors | Multitasking | Netmedia | Networking | PCB | PID | PlaySound | PWM | Relays | RTC | Servo | ShiftOut | SitePlayer | SPI | Stack | Timer | USB

Ads

Discussion Groups

Discussion Groups | BasicX | Program problem

Discussion forum for the BasicX family of microcontroller chips.

Program problem - Victor Fraenckel - Jan 4 4:46:00 1980

I have found a strange problem that I hope that someone in this group can explain to me. Below is a program 'adxlcalibrate.bas' and its map file from the last compile.

The program runs down through the lines:

debug.print "CAL X: ";CSStr(gx,2)
debug.print "CAL Y: ";CSStr(gy,2)

The output from the debug.print statements display on the output screen. However the next debug.print statement:

x=asin(gx)
y=asin(gy) 'compute roll in radians
debug.print "return from ASin"
pitch=RadToDeg(x) 'convert pitch to degs

never appears. RadToDeg is a function I wrote and have confidence in as I have used it many times in the past. This is also true of CSStr().

debug.print "PITCH: ";CSStr(x,2)
debug.print "ROLL: ";CSStr(y,2)

never appear on the output screen. In fact, the program is hung APPARENTLY executing the statement x=ASin(gx) or y=ASin(gy). I am at a loss to explain this. Is there some problems with some of the floating point routines? I find this hard to believe in light of the fact that a small program that I wrote and only containing several simple assignment statements as well as calls to ASin() works OK. In light of the information in the .mpp file, what is the basis for the program crashing at or around the calls to ASin()? Perhaps the better question is "Does the .MPP file reveal any basis for the problem?" Any enlightenment would be appreciated.

Also, as the .MPP file shows, I have the optimizer turned on and strict syntax mode turned off, but I have verified that in the project window for this project, I have checked both optimize and strict syntax. Why this apparent discrepency?

TIA

Vic
___________________________________________________________

Victor Fraenckel - The Windman
KC2GUI www.windsway.com

Home of the WindReader Electronic Theodolite
Read the WIND
'**********************************************************
'
' Copyright: May 24, 2001 by Windsway Instrument Company
'
' Module Name: adxlcalibrate.bas - version 0.9
'
'**********************************************************

'**********************************************************
'
' Version History
'
'Date What Who
'
'05/24/2001 module written
'
'**********************************************************

'**********************************************************
'
' compile this module with:
'
' v2x_adxl.bas
' miscsubs.bas
' serialport_WR.bas
'
'**********************************************************

public const debugging as boolean=True 'debugging

'getpin(calpin)=0 if pressed
public const calpin as byte = 9 'calibration button pin

'persistent variables
public CalFlag as new PersistentByte 'System is calibrated
public V2XxCal as new PersistentSingle 'VX2 x axis calibration
public V2XyCal as new PersistentSingle 'V2X y axis calibration
public ADXLoffset as new persistentSingle 'ADXL x axis offset
public ADXLfs as new persistentSingle 'ADXL x scale factor

'**********************************************************
'
' Subroutine main
'
'**********************************************************

sub main()

const places as integer=2

dim offset as single
dim fs as single

dim pitch as single
dim roll as single
dim gx as single
dim gy as single
dim x as single
dim y as single

call sleep(2.0) 'wait a bit

debug.print "program started"

'calibrate the accelerometer
call ADXLCalibrate()

'get the calibration constants
offset=ADXLoffset
fs=ADXLfs

debug.print "OFFSET: ";CSStr(offset,places)
debug.print "FS: " ;CSStr(fs,places)

do while (getpin(CALPIN) = unpressed) 'keep doing

call GetADXLData(gx,gy) 'get raw heading

debug.print "Gx: ";CSStr(gx,2)
debug.print "Gy: ";CSStr(gy,2)

gx=(gx+offset)/fs 'apply xcals to avg
gy=(gy+offset)/fs 'apply ycals to avg

debug.print "CAL X: ";CSStr(gx,2)
debug.print "CAL Y: ";CSStr(gy,2)

x=asin(gx) 'compute pitch in radians
y=asin(gy) 'compute roll in radians
debug.print "return from ASin"
pitch=RadToDeg(x) 'convert pitch to degs
roll=RadToDeg(y) 'convert roll to degs

debug.print "PITCH: ";CSStr(x,2)
debug.print "ROLL: ";CSStr(y,2)

'call NormalizeVector(ax,ay) 'convert to unit vectors
'elevation=UnitVectorAngle(ax,ay) 'compute elevation vector
'elevation=RadToDeg(elevation) 'convert to decimal degrees
'debug.print "ELEVATION: ";CSStr(elevation,places)

debug.print

loop end sub 'sub main
--------------------------------------------------------------------------------

|==========|
| MAP FILE |
|==========|

Project file: D:\Bx24 Stuff\My Projects\New WindReader\adxlcalibrate.bxp
Date: 2001/06/02 14:45:24
DLL version: 1.48.2
Optimizer: On
Max variable length string: 32 characters
Strict syntax mode: Off

Processor type: BX-24

Code memory available: 32768 bytes
Code memory allocated: 5499 bytes

RAM available: 401 bytes
RAM allocated: 98 bytes
Main stack size: 303 bytes

Persistent memory available: 480 bytes
Persistent memory allocated: 17 bytes

--------------------------------------------------------------------------------

MODULE-LEVEL (STATIC) RAM VARIABLES
-----------------------------------

Size Variable
Address (Bytes) Name

207 49 serialport_wr.inbuf_3
256 49 serialport_wr.outbuf_3

--------------------------------------------------------------------------------

PERSISTENT VARIABLES
--------------------

Size Variable
Address (Bytes) Name

32 1 adxlcalibrate.calflag
33 4 adxlcalibrate.v2xxcal
37 4 adxlcalibrate.v2xycal
41 4 adxlcalibrate.adxloffset
45 4 adxlcalibrate.adxlfs

--------------------------------------------------------------------------------

SUBPROGRAM LOCAL DATA
---------------------

FORMAL PARAMETERS

Size Variable
Address (Bytes) Name

9 4 serialport_wr.openserialport_3.baudrate
9 4 serialport_wr.reopenserialport_3.baudrate
9 2 serialport_wr.switchcom3.inpin
11 2 serialport_wr.switchcom3.outpin
13 4 serialport_wr.switchcom3.baudrate
17 2 serialport_wr.switchcom3.parms
9 2 serialport_wr.putbyte_3.value
9 2 serialport_wr.getbyte_3.value
11 2 serialport_wr.getbyte_3.success
9 2 serialport_wr.putline_3.tx
9 2 serialport_wr.putstr_3.tx
9 2 serialport_wr.putb_3.value
9 2 serialport_wr.puti_3.value
9 4 serialport_wr.putl_3.operand
9 4 miscsubs.csstr.number
13 2 miscsubs.csstr.places
9 4 miscsubs.cfrac.num
13 2 miscsubs.cfrac.places
9 2 miscsubs.cssng.astring
9 4 miscsubs.modulus.x
13 4 miscsubs.modulus.y
9 2 miscsubs.modelevation.el
9 2 miscsubs.modazimuth.az
9 4 miscsubs.atan2.sina
13 4 miscsubs.atan2.cosa
17 2 miscsubs.atan2.isok
9 4 miscsubs.radtodeg.rad
9 4 miscsubs.degtorad.deg
9 4 miscsubs.recip.angle
9 2 miscsubs.clearflagbit.sflag
11 2 miscsubs.clearflagbit.bitnum
13 2 miscsubs.clearflagbit.bits
9 2 miscsubs.setflagbit.sflag
11 2 miscsubs.setflagbit.flag
9 2 miscsubs.checkflagbit.sflag
11 2 miscsubs.checkflagbit.flag
9 4 miscsubs.fracx.x
9 4 miscsubs.intx.x
9 4 miscsubs.signx.x
9 4 miscsubs.truncx.x
9 4 miscsubs.ceiling.x
9 4 miscsubs.floor.x
9 2 miscsubs.normalizevector.xvect
11 2 miscsubs.normalizevector.yvect
9 4 miscsubs.unitvectorangle.xvect
13 4 miscsubs.unitvectorangle.yvect
9 2 v2x_adxl.getadxldata.gax
11 2 v2x_adxl.getadxldata.gay
9 2 v2x_adxl.getv2xdata.x
11 2 v2x_adxl.getv2xdata.y
9 4 serialport_wr.insertzeros_3.x

LOCAL VARIABLES

9 4 adxlcalibrate.main.offset
13 4 adxlcalibrate.main.fs
17 4 adxlcalibrate.main.pitch
21 4 adxlcalibrate.main.roll
25 4 adxlcalibrate.main.gx
29 4 adxlcalibrate.main.gy
33 4 adxlcalibrate.main.x
37 4 adxlcalibrate.main.y
41 2 adxlcalibrate.main.tmp~0009
11 2 serialport_wr.putstr_3.length
13 3 serialport_wr.putstr_3.ch
16 1 serialport_wr.putstr_3.bch
17 2 serialport_wr.putstr_3.i
19 2 serialport_wr.putstr_3.tmp~0010
11 4 serialport_wr.putb_3.l
11 4 serialport_wr.puti_3.l
13 10 serialport_wr.putl_3.digit
23 4 serialport_wr.putl_3.tmp
27 2 serialport_wr.putl_3.ndigits
29 2 serialport_wr.putl_3.i
31 2 serialport_wr.putl_3.tmp~0011
13 2 serialport_wr.insertzeros_3.numzeros
15 2 serialport_wr.insertzeros_3.i
17 2 serialport_wr.insertzeros_3.tmp~0012
15 34 miscsubs.csstr.tstr
49 34 miscsubs.csstr.trmstr
83 4 miscsubs.csstr.num
87 4 miscsubs.csstr.whole
91 4 miscsubs.csstr.decimal
95 4 miscsubs.csstr.p
99 4 miscsubs.csstr.ps
15 4 miscsubs.cfrac.wpart
19 4 miscsubs.cfrac.decpart
23 2 miscsubs.cfrac.i
25 2 miscsubs.cfrac.tmp~0013
11 1 miscsubs.cssng.isneg
12 1 miscsubs.cssng.decdone
13 34 miscsubs.cssng.ss
47 3 miscsubs.cssng.schar
50 1 miscsubs.cssng.nextchar
51 1 miscsubs.cssng.nextnum
52 2 miscsubs.cssng.ct
54 2 miscsubs.cssng.sct
56 2 miscsubs.cssng.l
58 4 miscsubs.cssng.sng
62 4 miscsubs.cssng.dsng
66 4 miscsubs.cssng.dv
70 2 miscsubs.cssng.tmp~0014
72 1 miscsubs.cssng.tmp~0015
19 4 miscsubs.atan2.x
15 1 miscsubs.clearflagbit.i
16 1 miscsubs.clearflagbit.tmp~0016
13 2 miscsubs.intx.a
13 4 miscsubs.ceiling.fx
13 4 miscsubs.floor.fx
13 4 miscsubs.normalizevector.length
17 4 miscsubs.unitvectorangle.absx
21 4 miscsubs.unitvectorangle.absy
25 1 miscsubs.unitvectorangle.steep
26 4 miscsubs.unitvectorangle.angle
13 4 v2x_adxl.getadxldata.t1x
17 4 v2x_adxl.getadxldata.t3x
21 4 v2x_adxl.getadxldata.t1y
25 4 v2x_adxl.getadxldata.t3y
29 2 v2x_adxl.getadxldata.i
31 4 v2x_adxl.getadxldata.period
35 4 v2x_adxl.getadxldata.sum1
39 4 v2x_adxl.getadxldata.sum3
43 4 v2x_adxl.getadxldata.temp1
47 4 v2x_adxl.getadxldata.temp3
51 2 v2x_adxl.getadxldata.tmp~0017
9 4 v2x_adxl.adxlcalibrate.gx
13 4 v2x_adxl.adxlcalibrate.gy
17 4 v2x_adxl.adxlcalibrate.gxup
21 4 v2x_adxl.adxlcalibrate.gxdn
25 2 v2x_adxl.adxlcalibrate.ct
27 2 v2x_adxl.adxlcalibrate.tmp~0018
29 2 v2x_adxl.adxlcalibrate.tmp~0019
13 2 v2x_adxl.getv2xdata.hx
15 2 v2x_adxl.getv2xdata.hy
17 2 v2x_adxl.getv2xdata.headingx
19 2 v2x_adxl.getv2xdata.headingy
21 2 v2x_adxl.getv2xdata.ct
23 2 v2x_adxl.getv2xdata.tmp~0020
9 2 v2x_adxl.v2xcalibrate.ct
11 4 v2x_adxl.v2xcalibrate.x1
15 4 v2x_adxl.v2xcalibrate.y1
19 4 v2x_adxl.v2xcalibrate.x2
23 4 v2x_adxl.v2xcalibrate.y2
27 4 v2x_adxl.v2xcalibrate.x
31 4 v2x_adxl.v2xcalibrate.y
35 2 v2x_adxl.v2xcalibrate.tmp~0021
37 2 v2x_adxl.v2xcalibrate.tmp~0022

--------------------------------------------------------------------------------

CODE MEMORY
-----------

SUBPROGRAMS

Start Size Subprogram
Address (Bytes) Name

0 7 [Startup code]
7 1390 adxlcalibrate.main
1397 72 sys~library.sys~debugprint~
1469 71 sys~library.sys~transmitbyte~
1540 1031 v2x_adxl.adxlcalibrate
2571 472 miscsubs.csstr
3043 310 v2x_adxl.getadxldata
3353 53 sys~mathlibrary.sys~asin
3406 15 miscsubs.radtodeg
3421 13 serialport_wr.putbyte_3
3434 43 sys~library.sys~fix
3477 126 sys~library.sys~clng
3603 88 miscsubs.cfrac
3691 193 sys~mathlibrary.sys~cstringlong
3884 363 sys~mathlibrary.sys~trim
4247 42 sys~mathlibrary.sys~pow
4289 280 sys~mathlibrary.sys~sqr
4569 370 sys~mathlibrary.sys~atn
4939 72 sys~library.sys~fixul
5011 251 sys~mathlibrary.sys~log
5262 237 sys~mathlibrary.sys~exp
5498 -- [End code]

BLOCK DATA

(none)

--------------------------------------------------------------------------------
[Non-text portions of this message have been removed]





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )


Re: Program problem - Frank Manning - Jun 2 23:05:00 2001

From: Victor Fraenckel <>

> [...]
> In fact, the program is hung APPARENTLY executing the
> statement x=ASin(gx) or y=ASin(gy).
> [...]

What are the values of operands gx and gy? If they're outside the range -1.0
to +1.0, the results are undefined.

-- Frank Manning
-- NetMedia, Inc.




(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Program problem - Frank Manning - Jun 7 12:42:00 2001

"Victor Fraenckel" <>

> [...]
> Also, as the .MPP file shows, I have the optimizer turned on
> and strict syntax mode turned off, but I have verified that
> in the project window for this project, I have checked both
> optimize and strict syntax. Why this apparent discrepency?
> [...]

There is a bug in the editor/downloader that causes strict syntax checking
to be turned off. We will fix it.

-- Frank Manning
-- NetMedia, Inc.




(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )