Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:52 03 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Using VAL with PWM

Author Message
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 11:59pm 16 Dec 2014
Copy link to clipboard 
Print this post

Hi

I posted a question about Lookup tables earlier this is not a Bump but a code question

I am sort of getting somewhere with generating tones using the table, I have converted this

{ 1,15, 9}, { 1,15,10}, { 1,15,11}, { 1,15,12}, { 1,15,13}, { 1,15,14}, { 1,15,15}, { 2, 8, 8} to this

DIM A(8) AS STRING
DATA "1,15, 9"," 1,15,10","1,15,11","1,15,12","1,15,13","1,15,14","1,15,15"," 2, 8, 8"
FOR B = 0 TO 7
READ (A)B
NEXT B

What I need to do is use the 3 numbers in each element ie: "1,15,9" to generate sequential tones, then add a fixed delay before moving onto the next element, this is what I have tried

DO
FOR B= 0 TO 7
PWM 1, 2500, VAL(A(B))*5
PAUSE 64
NEXT B

My initial problem is that only reads the first character in the sequence not all three

And maybe a bigger problem is that I cannot DIM the complete array which is 256 elements

Thanks

Jed
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10189
Posted: 12:27am 17 Dec 2014
Copy link to clipboard 
Print this post

Your first problem is the READ statement - it should be READ A(B)

Then you need to parse the strings to extract the three numbers. Have a look at the INSTR function. Use it to find the commas and then use LEFT$, MID$ and RIGHT$ to get the individual numbers for the VAL function.

I could give you the code but it is better if you try yourself and ask for more help if needed Edited by matherp 2014-12-18
 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 12:35am 17 Dec 2014
Copy link to clipboard 
Print this post

  matherp said   Your first problem is the READ statement - it should be READ A(B)

Then you need to parse the strings to extract the three numbers. Have a look at the INSTR function. Use it to find the commas and then use LEFT$, MID$ and RIGHT$ to get the individual numbers for the VAL function.

I could give you the code but it is better if you try yourself and ask for more help if needed


Thanks matherp

My sentiments exactly I don't want it done for me that achieves 0
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10189
Posted: 12:49am 17 Dec 2014
Copy link to clipboard 
Print this post

Actually looking at your data again if you used leading spaces in the strings (as in the C code) to make all the strings the same length you wouldn't need INSTR and could just use LEFT$, MID$ and RIGHT$ because you would know where the commas are.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:35am 17 Dec 2014
Copy link to clipboard 
Print this post

Also look at LENGTH when dimensioning an array.
Now each string will reserved 256 bytes using too much memory
A length of 8 would be sufficient.

Microblocks. Build with logic.
 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 02:38am 17 Dec 2014
Copy link to clipboard 
Print this post

Ok maybe a bit untidy but it works

do
for B = 1 to 120
vcode1$ = LEFT$(mid$(A(B), 1), 2)
vcode2$ = left$(mid$(A(B), 4), 2)
vcode3$ = right$(mid$(A(B), 1), 2)
pwm 1, 50000, val(vcode1$)*6
pause 64
pwm 1, 50000, val(vcode2$)*6
pause 64
pwm 1, 50000, val(vcode3$)*6
pause 64
next B
loop

Now to sort the arrays out

Ill will have to do that TZAdvantage
 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 02:48am 17 Dec 2014
Copy link to clipboard 
Print this post

Tried Dimensioning the array with

DIM A(256) LENGTH 8

Error: Not Enough Memory
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10189
Posted: 02:54am 17 Dec 2014
Copy link to clipboard 
Print this post

Try: DIM STRING A(256) LENGTH 8

works for me uses 3K memory as expectedEdited by matherp 2014-12-18
 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 03:16am 17 Dec 2014
Copy link to clipboard 
Print this post

  matherp said   Try: DIM STRING A(256) LENGTH 8

works for me uses 3K memory as expected


That worked :)
 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 03:18am 17 Dec 2014
Copy link to clipboard 
Print this post

  edu001 said  
  matherp said   Try: DIM STRING A(256) LENGTH 8

works for me uses 3K memory as expected


That worked :)


Actually I was trying DIM A(256) AS STRING LENGTH 8

That didd'nt work
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4033
Posted: 03:48am 17 Dec 2014
Copy link to clipboard 
Print this post

If you took the quotes out of the DATAs you could simply use READ and drop all the strings.

(In effect it's like using INPUT but the value comes from DATA.)

John
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 05:15am 17 Dec 2014
Copy link to clipboard 
Print this post

That would work good too. Storing it would use more space as each value is then at least 4 bytes in memory.
Combining the 3 values into one would save some.
[code]
READ A
READ B
READ C
Values(count) = A + B * 16 + C * 256
[/code]
But going through that exercise is only worth it when memory gets scarce or speed of execution is not fast enough.
Maybe use DIM STRING A(256,3) LENGTH 1. That will use only about 1200 bytes of memory and might be easier to work with as it has the same structure.
Each value can then be stored with CHAR() and retrieved with ASC().

In the newest version arrays can be initialized directly. That would save even more as no more data statements are necessary.

Another solution would be to treat the DATA statements as the storage and use READ statements in the loop, and then use RESTORE to reset reading from the top.
This would be the most memory efficient as it will not be stored in RAM (is stored along the program in flash) with some sacrifice in speed and usability.




Edited by TZAdvantage 2014-12-18
Microblocks. Build with logic.
 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 12:03pm 17 Dec 2014
Copy link to clipboard 
Print this post

  JohnS said   If you took the quotes out of the DATAs you could simply use READ and drop all the strings.

(In effect it's like using INPUT but the value comes from DATA.)

John


Thanks JohnS

The way DominoEX16 (earlier post) works means that the array must stay intact as each character consists of 3 nibbles ie: the character < ASCII 60 is "0,8, 10"
 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 09:30am 18 Dec 2014
Copy link to clipboard 
Print this post

  TZAdvantage said   That would work good too. Storing it would use more space as each value is then at least 4 bytes in memory.
Combining the 3 values into one would save some.
[code]
READ A
READ B
READ C
Values(count) = A + B * 16 + C * 256
[/code]
But going through that exercise is only worth it when memory gets scarce or speed of execution is not fast enough.
Maybe use DIM STRING A(256,3) LENGTH 1. That will use only about 1200 bytes of memory and might be easier to work with as it has the same structure.
Each value can then be stored with CHAR() and retrieved with ASC().

In the newest version arrays can be initialized directly. That would save even more as no more data statements are necessary.

Another solution would be to treat the DATA statements as the storage and use READ statements in the loop, and then use RESTORE to reset reading from the top.
This would be the most memory efficient as it will not be stored in RAM (is stored along the program in flash) with some sacrifice in speed and usability.




 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 09:37am 18 Dec 2014
Copy link to clipboard 
Print this post

  edu001 said  
  TZAdvantage said   That would work good too. Storing it would use more space as each value is then at least 4 bytes in memory.
Combining the 3 values into one would save some.
[code]
READ A
READ B
READ C
Values(count) = A + B * 16 + C * 256
[/code]
But going through that exercise is only worth it when memory gets scarce or speed of execution is not fast enough.
Maybe use DIM STRING A(256,3) LENGTH 1. That will use only about 1200 bytes of memory and might be easier to work with as it has the same structure.
Each value can then be stored with CHAR() and retrieved with ASC().

In the newest version arrays can be initialized directly. That would save even more as no more data statements are necessary.

Another solution would be to treat the DATA statements as the storage and use READ statements in the loop, and then use RESTORE to reset reading from the top.

This would be the most memory efficient as it will not be stored in RAM (is stored along the program in flash) with some sacrifice in speed and usability.



Should DIM STRING A(512,3) LENGTH 1 work as the arrays need to be indexed together

I am getting an error on this line

FOR B = 0 TO 511
READ A(B) the error occurs here "error number of dimensions"
NEXT B

 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6266
Posted: 10:18am 18 Dec 2014
Copy link to clipboard 
Print this post

If you create a multidimensional array, you need to specify all dimensions each time.


OPTION BASE 0
DIM STRING A(512,3) LENGTH 1

FOR B = 0 TO 511
READ A(B,0)
READ A(B,1)
READ A(B,2)
NEXT B


AS you are using a string array, the data statements need to be single length strings, which could be difficult, or you need to convert the data from decimal to strings with chr$()

something like:

OPTION BASE 0
DIM STRING A(512,3) LENGTH 1

FOR B = 0 TO 511
READ X, Y, Z
A(B,0) = CHR$(X)
A(B,1) = CHR$(Y)
A(B,2) = CHR$(Z)
NEXT B


Jim



Edited by TassyJim 2014-12-19
VK7JH
MMedit
 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 09:51pm 18 Dec 2014
Copy link to clipboard 
Print this post

Ok I am a little stuck at this point

So far I have sorted out sending the tones using PWM, and I have extracted the ASCII values from my string that I need to transmit

I think the table DIM is going to work

The next step is to match my ASCII value to the varicode table and send the three tones with a 64ms delay, here is a reference http://www.qsl.net/zl1bpu/MFSK/DominoEX%20Varicode%20Table.p df

Is it possible for instance to count the segments according to the ASCII value ie: E = 69 so count 68 then 256
so that the 2 tables are read then another 64ms delay and so on

Jed

 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 06:48am 19 Dec 2014
Copy link to clipboard 
Print this post

I have made some progress:)

I can successfully read the tables in the correct sequence

The problem I am having now is that when I read the nibbles 3,8,0

like this

syma = val(LEFT$(mid$(A(txtchr), 1), 2))
symb = val(left$(mid$(A(txtchr), 4), 2))
symc = val(right$(mid$(A(txtchr), 1), 2))

It retains the trailing 0 likewise for 0,10,8 It retains the leading 0

Is there a way I can read the table and remove any single 0's
 
edu001
Regular Member

Joined: 14/07/2014
Location: United Kingdom
Posts: 82
Posted: 07:04am 19 Dec 2014
Copy link to clipboard 
Print this post

  edu001 said   I have made some progress:)

I can successfully read the tables in the correct sequence

The problem I am having now is that when I read the nibbles 3,8,0

like this

syma = val(LEFT$(mid$(A(txtchr), 1), 2))
symb = val(left$(mid$(A(txtchr), 4), 2))
symc = val(right$(mid$(A(txtchr), 1), 2))

It retains the trailing 0 likewise for 0,10,8 It retains the leading 0

Is there a way I can read the table and remove any single 0's


Just reading up on DominoEX16 if the 0 is the first of the 3 nibbles it has to stay
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025