Project Code Problems
SamW
Posts: 27
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**************************************************************
·
·
·
·
·
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**************************************************************
·
·
·
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
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