Shop OBEX P1 Docs P2 Docs Learn Events
Project Code Problems — Parallax Forums

Project Code Problems

SamWSamW Posts: 27
edited 2009-05-23 18:37 in BASIC Stamp
All right, I need some help fixing my code.· I have four buttons that currently generate four different tones using the FREQOUT command.· (This will eventually be the signal source for the large vibrating solenoid.· You can see the breadboard, it serves as the control for the solenoid) Additionally, there are four buttons.· Currently I only have three programmed the fourth’s function is yet to be determined.·· These buttons perform specific functions when pressed, button 1 on the extreme left takes a temperature reading. Button 2 takes a reading from the accelerometer and button three takes a reading from a flexi force sensor.· (look at the pics below)
·
The problem is that when the buttons are pushed the FREQOUT command is interrupted in order to take the reading.· I need the FREQOUT signal to be uninterrupted and play continuously while I take readings from the sensors.
·
The link below is to a quick 6-second video on you tube that shows the problem.· Listen for the tone and watch what happens when I push the buttons.· It is a quick video so you may need to play it a few times.
·

·
Here is just a small slice of my code.· The nested subs have been omitted.


Attached is a word doc that has the entire code.
·
'
[noparse][[/noparse] I/O Definitions ]

·
'Temp I/0
Reset······· CON···· 8
Alarm······· CON···· 9
Sensor······ CON···· 10
TX··· ·······PIN···· 11············· ' serial output to LCD
T9600······· CON···· 240
·
' Vibration I/0
·
Dio········· PIN···· 15············· ' data to/from module
Clk········· PIN···· 14············· ' clock output
CS·········· PIN···· 13············· ' active-low chip select
·
' Flex force I/0
sensorPin··· CON···· 12············· ' Flexiforce sensor circuit
·
·
'
[noparse][[/noparse] Variables ]

·
·
' temp variables
temperature· VAR··· Word
tempL······· VAR··· temperature.LOWBYTE
tempH······· VAR··· temperature.HIGHBYTE
pec········· VAR··· Byte
·
Celsius····· VAR··· Byte··········· 'Word
CelsiusDec·· VAR··· Byte··········· 'Word
Fahrnheit··· VAR··· Byte··········· 'Word
FahrnheitDec VAR··· Byte··········· 'Word
w··········· VAR· ··Byte
x··········· VAR··· Byte
y··········· VAR··· Byte
z··········· VAR··· Byte
·
·
' Vibration
axis········ VAR··· Nib············ ' axis selection
rvCount····· VAR··· Word··········· ' ref voltage adc counts
axCount····· VAR··· Word··········· ' axis voltage adc counts
mVolts······ VAR··· Word··········· ' millivolts
gForce······ VAR··· Word··········· ' axis g-force
dValue······ VAR··· Word··········· ' display value
dPad········ VAR··· Nib············ ' display pad
·
'Flexiforce
·rawForce···· VAR···· Word·········· ' Stores raw output
·
·
'
[noparse][[/noparse] Main· ]

·
' Three major subs and Four different states.· Buttons 0 - 2 will serve
'for readout of data such as temperature, acceleration, and force.
'Buttons 3-6 will put the device in four different frequency states
'50Hz, 60Hz, 70Hz, 90Hz.
·
·
·
DO
·
IF IN4=0 THEN
AUXIO
HIGH 8
MAINIO
GOSUB FortyHz
·
ELSEIF IN5=0 THEN
AUXIO
HIGH 8
MAINIO
GOSUB FiftyHZ
·
ELSEIF IN6=0 THEN
AUXIO
HIGH 8
MAINIO
GOSUB SixtyHZ
·
ELSEIF IN7=0 THEN
AUXIO
HIGH 8
MAINIO
GOSUB SeventyHZ
·
ELSE
·
AUXIO
LOW 8
MAINIO
PAUSE 50
·
ENDIF
·
LOOP
·
·
'subs =======================================================
·
FortyHz:
·
DO· WHILE IN4=0
AUXIO
FREQOUT 9 , 5000 , 40
MAINIO
· IF (IN0 =0)THEN··················· 'Temp
AUXIO
HIGH 10
MAINIO
GOSUB TempReadOut
·
ELSEIF (IN1 =0)THEN················· 'Accel
AUXIO
HIGH 10
MAINIO
GOSUB Accelerometer
·
ELSEIF (IN2 = 0) THEN··············· 'flex
AUXIO
HIGH 10
MAINIO
GOSUB WeitghMesurement
·
·
ELSE
·
AUXIO
LOW 10
MAINIO
PAUSE 100
·
ENDIF
·
LOOP
·
RETURN
·
'========================================================================
·
FiftyHz:
·
DO WHILE IN5 =0
AUXIO
FREQOUT 9, 5000, 50
MAINIO
·IF (IN0 =0)THEN··················· 'Temp
AUXIO
HIGH 10
MAINIO
GOSUB TempReadOut
·
ELSEIF (IN1 =0)THEN··· ··············'Accel
AUXIO
HIGH 10
MAINIO
GOSUB Accelerometer
·
ELSEIF (IN2 = 0) THEN··············· 'flex
AUXIO
HIGH 10
MAINIO
GOSUB WeitghMesurement
·
ELSE
·
AUXIO
LOW 10
MAINIO
PAUSE 100
·
ENDIF
·
LOOP
·
RETURN
·
'==========================================================================
·
SixtyHz:
·
DO WHILE IN6 =0
AUXIO
FREQOUT 9, 5000, 60
MAINIO
·· IF (IN0 =0)THEN················· 'Temp
AUXIO
HIGH 10
MAINIO
GOSUB TempReadOut
·
ELSEIF (IN1 =0)THEN················· 'Accel
AUXIO
HIGH 10
MAINIO
GOSUB Accelerometer
·
ELSEIF (IN2 = 0) THEN··············· 'flex
AUXIO
HIGH 10
MAINIO
GOSUB WeitghMesurement
·
ELSE
·
AUXIO
LOW 10
MAINIO
PAUSE 100
·
ENDIF
·
·LOOP
·
RETURN
·
'============================================================================
·
SeventyHz:
·
DO WHILE IN7 =0
AUXIO
FREQOUT 9, 5000, 70
MAINIO
· IF (IN0 =0)THEN·················· 'Temp
AUXIO
HIGH 10
MAINIO
GOSUB TempReadOut
·
ELSEIF (IN1 =0)THEN················ 'Accel
AUXIO
HIGH 10
MAINIO
GOSUB Accelerometer
·
ELSEIF (IN2 = 0) THEN·············· 'flex
AUXIO
HIGH 10
MAINIO
GOSUB WeitghMesurement
·
ELSE
·
AUXIO
LOW 10
MAINIO
PAUSE 100
·
ENDIF
·
LOOP
·
RETURN
'================================================================
·
'Nested Subs**************************************************************
·
·
·
·
2592 x 1944 - 2M
2102 x 1205 - 2M
1766 x 1847 - 2M
2592 x 1944 - 2M

Comments

  • SamWSamW Posts: 27
    edited 2009-05-22 14:45
    Sorry about how large the pics are when opened!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-05-22 15:24
    It is recommended to attach entire programs rather than pasting them into the message. When attached they can be easily opened in the editor whereas in the message there is no syntax highlighting and often formatting is lost. Not only that but you must copy/paste all the data to test it. Just some thoughts to help you to help others help you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • SamWSamW Posts: 27
    edited 2009-05-22 19:46
    Attached is the code!· Thank for the advice Chris.
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-05-23 18:37
    SamW
    in a nutshell - FREQOUT "command"·behaves as·a subroutine of programmed· duration.
    In other words - the processor is "stuck" in this subroutine for this·duration.

    Unfortunately it also means the opposite - the subroutine needs to be terminated·for processor to· perform other tasks. In your case to·read button state. ·Hence the desired audio will be briefly interrupted.

    BASIC is a friendly language but has limitations.

    Cheers Vaclav

    PS How about generating a confirmation tone when you press the button? That way the user will know that the button was pushed (feature!) and the tone interruption will be masked (workaround the languange limitataion). .·



    Post Edited (vaclav_sal) : 5/23/2009 6:49:32 PM GMT
Sign In or Register to comment.