PDA

View Full Version : creating arrays



hitsware
04-06-2007, 05:54 AM
what would be the most elegant way (pbasic)
to do this (qbasic):

(# elements in array statement(I forget right now))
for x=0 to 7
read n(x)
next x
data 24,27,30,32,36,40,45,48

TechnoRobbo
04-06-2007, 08:00 AM
Study the READ command and the DATA directive in the Stamp Editor's Help File. They're just what the doctor ordered.






▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun


TR

hitsware
04-06-2007, 08:18 AM
And besides that....
How do you get rid of the annoying 'pop'
At the end of the loop?

loop
freqout 0,1000,1000
goto loop

That's why I want to find a way to have one pin
connected to one of the '3' timers
Can the other 2 do the 'pulsout' et. al. ?
That way you can fire an external envelope generator
AFTER!
The annoying pop ..... (

TechnoRobbo
04-06-2007, 10:04 AM
?
you lost me

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun


TR

Mike Green
04-06-2007, 10:19 AM
The program fragment you wrote is not valid PBasic. If you're using the old (default) syntax, then "loop" requires a colon after it to make it a valid label. If you're using the version 2.5 syntax, "loop" becomes a reserved word (along with DO to make a looping construct) and the goto would be invalid.

Regarding the "pop" ... Read the section of the PBasic manual on the FREQOUT statement. It discusses the need for a low pass filter on the output pin of the Stamp. If the values in the filter are suitable for the frequencies involved, the "pop" should be well attenuated.

As I mentioned before, there is no way to get access to the timers. The Stamp is a "single threaded" processor and can only do one thing at a time. Some functions, such as controlling a servo, can be combined with others only because there's time between servo pulses to do other things.

hitsware
04-06-2007, 10:43 AM
>you lost me

if you listen (though an amplifier) to pin 0 in the example you'll hear a 'pop' every 1000 'duration units'

hitsware
04-06-2007, 10:49 AM
>The program fragment you wrote is not valid PBasic.

It runs on my system.

>If you're using the old (default) syntax, then "loop"
>requires a colon after it to make it a valid label. If
>you're using the version 2.5 syntax, "loop" becomes
>a reserved word (along with DO to make a looping
>construct) and the goto would be invalid.

I use the stamp2.exe with the most popular stamp.

Mike Green
04-06-2007, 10:54 AM
That's part of why you need a low-pass filter. The FREQOUT statement is not intended to be used without some kind of filtering. It says so right in the documentation. The way you get rid of the "pop" is to have a filter.

It sounds like you're unhappy with how the Stamp works. Some things it does superbly and some things it does barely adequately. Some things (like multitasking) it doesn't do at all even though sometimes you can "fake it".

Maybe for your project you need a different microcontroller. Parallax does sell two other kinds, the SX and the Propeller. Both do multitasking, the Propeller particularly well. As I noted in your other thread, there are already several very sophisticated sound processing / synthesis programs already written, one for vocal tract synthesis that's particularly impressive.

hitsware
04-06-2007, 11:00 AM
>As I mentioned before, there is no way
>to get access to the timers. The Stamp is
>a "single threaded" processor and can only
>do one thing at a time. Some functions,
>such as controlling a servo, can be combined
>with others only because there's time
>between servo pulses to do other things.

Doe any one make someting like the 'BU8763'
chip in a dip package?
Or a 'BU8763' on a dip header?

Mike Green
04-06-2007, 11:06 AM
SparkFun makes an adapter (www.sparkfun.com/commerce/product_info.php?products_id=498 (http://www.sparkfun.com/commerce/product_info.php?products_id=498)) for SSOP-16 devices like the BU8763. You'd have to solder the BU8763 to the adapter, but then you could use it in breadboards and various project boards like it was a DIP device.

hitsware
04-06-2007, 11:17 AM
>It sounds like you're unhappy with how the Stamp works.

Not at all. I may have been wishing for more, but I can't knock success.
The 'freqout' with 2 possible notes is pretty powerfull.
I've ran into the 'pop' before
(when you hear a sudden change in frequency (+ the glitch while the channel updates))
Finally pretty well cured it on the opl3 .....
The envelope needs to start after the frequency shift.
I have the LP filter. Plus a HP to keep DC shifts out of
the signal.

Mike Green
04-06-2007, 06:55 PM
The FREQOUT statement was probably added to support both single tones and DTMF signalling.

I hope the adapter works for you. DigiKey also has some similar adapters in their catalog. They're on a much thinner PCB. The SparkFun ones are physically stronger and more suitable for breadboard use.

hitsware
04-06-2007, 09:36 PM
Mike Green said...
The FREQOUT statement was probably added to support both single tones and DTMF signalling.

I hope the adapter works for you. DigiKey also has some similar adapters in their catalog. They're on a much thinner PCB. The SparkFun ones are physically stronger and more suitable for breadboard use.
I don't think I could handle the soldering for the adaptor. (nor do I want to invest in the equipment)
Would one of the 6 (or 8) pin Microchip chips be able to do the 'freqout' command? or at least a 'sound' (squarewave)?
If I could attach 3 or 4 of those to 3 or 4 pins on the stamp that might do the trick.....

Mike Green
04-06-2007, 10:06 PM
Please keep in mind that this is a Parallax support forum and that, if you want advice or support on using Microchip processors, you'd have to get that from somewhere else.

I'm sure any of the Microchip processors can handle putting out a sequence of pulses or a squarewave signal anywhere in the audio range. If you're familiar with their programming, have at it. There are a number of 3rd parties that use PIC processors for various peripheral tasks for Stamps and other similar microcontrollers.

hitsware
04-07-2007, 08:08 AM
qbasic:
10 dim n(4) ' gives the note 4 possibilities
20 for x=0 to 3 ' x is automaticly a variable
30 read n(x) ' n has been declared
40 next x
50 data: 1,2,3,4 ' maybe you don't number the 'data' lines?

Anyways .......

Bruce Bates
04-07-2007, 10:35 AM
Hitsware -

Is this what you were lookubg for?

PBASIC

n VAR BYTE(4) ' gives the note 4 possibilities
x VAR NIB

for x=0 to 3 ' x is automaticly a variable
read n(x) ' n has been declared
next
data: 1,2,3,4
END

Regards,

Bruce Bates

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

hitsware
04-07-2007, 10:46 PM
Bruce,
I would think so, but I get a "expected ' , ' " (expected comma)
error after the read statement ?

n var byte(4)
x var nib
for x=0 to 3
read n(x)
next
data: 1,2,3,4

Zoot
04-07-2007, 11:11 PM
hitsware -- you need to READ the data into some variable. See the Pbasic Stamp manual under READ and DATA for more details:




n var byte(4)
x var nib

DATA 1,2,3,4

for x=0 to 3
read x, n(x) 'read from data (byte) location x (0..3) into variable n(x)
next

end



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

Mike Green
04-07-2007, 11:11 PM
The read statement requires at least two parameters. The first is always the EEPROM address to start at and subsequent parameters are the variables to read into. Also, you can't have a colon after the DATA (and that's a reserved word too). Try this:


tbl data 1,2,3,4
n var byte(4)
x var nib
for x = 0 to 3
read tbl+x,n(x)
next

Bruce Bates
04-07-2007, 11:14 PM
Hitsware -

Sorry, I don't have the Stamp Editor or any of my Stamp documentation on this particular computer. It was my error, however. It should have read something like the following, but check the syntax in the PBASIC Help Fle:

n var byte(4)
x var nib
for x=0 to 3
n(x) = read x
next
data: 1,2,3,4
END

Regards,

Bruce Bates

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

TechnoRobbo
04-07-2007, 11:17 PM
I think the the QBasic Read and Data statements are from the old days when we used Hollerith cards.
LOOKUP is much more efficient because it's indexed; therefore the data it doesn't need to be loaded into an array.
PBasic's READ and DATA statements are also an indexing systems good for really large multidimensional tables and arrays.

The problem with the old QBASIC command is that there isn't that much memory to make it useful in larger programming tasks.

As for your freqout problem let me point out that :


freqout 0,1000,1000


May differ with your processor and you may have to adjust your durations to be a multiple of your frequency units.

http://forums.parallax.com/attachment.php?attachmentid=73752
·a 440 hZ tone would have a wavelength of 2.272727..... milliseconds. A BS2 loop of:


do

freqout 0,1000,440

loop



would pop & click but a loop of


do

freqout 0,1314,440

loop



would not as much - if filtered properly. see Freqout in the help file. Due to the inaccuracy of the BS2 the actual number should be 1320·but its not.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun


TR

Post Edited (TechnoRobbo) : 4/7/2007 5:55:00 PM GMT

hitsware
04-08-2007, 09:11 AM
>a 440 hZ tone would have a wavelength of 2.272727..... milliseconds.
>A BS2 loop of:

do
freqout 0,1000,440
loop

>would pop & click but a loop of

do
freqout 0,1314,440
loop

.....yea .... thanks ...... i think i ran into something like that on an Amiga :)

hitsware
04-08-2007, 11:40 PM
cx data 8,6,9,6:nx data 2,4,3,4
c var nib (4):n var nib(4):x var nib:y var nib
for x=0 to 3:read cx+x,c(x):read nx+x,n(x):next
play:for x=0 to 3:for y=0 to 3
freqout 0,400,c(x)*n(y)*8,c(x)*n(y)*16
next:next:goto play

' Thanks everybody. This is going to work :)
' Listen to pin 0