SERINP$ routine does not function as expected...???

User avatar
RBSe
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California
Contact:

SERINP$ routine does not function as expected...???

Unread post by RBSe »

Greetings once again,

Thanks Andries for this code, but it does not work as expected.
It is suppose to wait for the speech module to finish speaking before sending a ":" but it sends it immediately, it does not wait.

Code: Select all


'wait for ACK from speech module...
talkACK:
	REPEAT ' loop until speech module is ready for a command...
	x$=SERINP$(1,1,ASCII(":"),670000) ' timeout = 13 seconds
	UNTIL x$=":"
RETURN

I thought it was the speech module because the code looks like it should work, so i sent it back for testing and it works fine on their controllers of 2 different types.
The speech module waits for the speech to finish before sending a ":" in response, so it was working fine.

So the the only answers are the code and/or the command does not function correctly.
It's turning out that my EzSBC1 is not so easy after all as delays are approaching a month now.

:?: Could someone look into this, Daniel, if you're not too busy...???

Enjoy!

Robert
.
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
Daniel
Posts: 133
Joined: Tue Nov 13, 2012 2:10 pm

Re: SERINP$ routine does not function as expected...???

Unread post by Daniel »

Hi Robert

I don't understand "...speaking before sending a ":" but it sends it immediately, it does not wait."
What does the 'send' refer to?

If the call to SERINP$ returns immediately and the test is good then there is probably a ":" waiting in the buffer of the serial port. The EzSBC1 serial IO has buffers of 64 bytes (at least) to make sure characters are not lost. So what you may want to do is to flush the buffer before waiting for the ":" character. You can empty the buffer before you give the command to the text to speech module by adding this line to your code.

Code: Select all

x$=SERINP$(1,-1,-1,1)    ' Clear the receive buffer
Also, the constant for roughly 13s delay should be roughly 5,000,000 not just 670,000 (remember, no commas in the code).

I hope this helps.

Daniel
User avatar
RBSe
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California
Contact:

Re: SERINP$ routine does not function as expected...???

Unread post by RBSe »

Thanks for getting back to me Daniel,

I just got back my text-to-speech module from the factory and it is a known-good module.
I took the code you gave me and used it in this test program below.
The EzSBC1 does not wait for the ":" to be transmitted by the module, or so it would seem.
Instead, it plows through all the print statements and ends immediately, and only speaking the first serial text input.
I've been stuck on this for 2 weeks and would like to move forward on this project, this is a critical sub-system that needs to work correctly.
Thanks for your help Daniel.

Robert
.

Code: Select all

'talk test

PINMODE 36, OUT ' set pin 36 as output for serial TX
PINMODE 37, IN  ' set pin 37 as input for serial RX
SERINIT 1,9600,8,1,0 ' port 1, 9600 bps, 8 data bits, 1 stop bit, no parity
CR$ = CHR$(13) ' for CR

x$=SERINP$(1,-1,-1,1)    ' Clear the receive buffer

REPEAT ' loop until speech module boots ready...
x=SEROUT(1,CR$)
x$=SERINP$(1,1,ASCII(":"),5000000)
UNTIL x$ = ":"

? "Booted... Input Command or [ENTER] to continue:"

INPUT setup$              ' get input from terminal
x=SEROUT(1,setup$+CR$)

x$=SERINP$(1,-1,-1,1)    ' Clear the receive buffer

REPEAT ' loop until speech module is ready for a command...
x$=SERINP$(1,1,ASCII(":"),5000000)
UNTIL x$=":"

TXtalk$ = "hello. blah-blah-blah..."

? "Speaking..."

SOUT$ = "s" + TXtalk$ + CR$ ' combine "s" for speak, text & CR
x = SEROUT (1, SOUT$) ' Sends SOUT$ to serial port 1 (pin 36)

x$=SERINP$(1,-1,-1,1)    ' Clear the receive buffer

REPEAT ' loop until speech module is ready for a command...
x$=SERINP$(1,1,ASCII(":"),5000000)
UNTIL x$=":"

'start=GETTICK ' 1 tick = 0.0001 seconds
'REPEAT ' timer for speech to finish...
'UNTIL GETTICK > (start+130000) ' 13 seconds

? "Speaking..."

RNDpass$=STR$(INT(RND(9000)+1000)) ' random number between 1000 & 9999
x=SEROUT(1,"s"+RNDpass$+". that's, "+RNDpass$+CR$)

x$=SERINP$(1,-1,-1,1)    ' Clear the receive buffer

REPEAT ' loop until speech module is ready for a command...
x$=SERINP$(1,1,ASCII(":"),5000000)
UNTIL x$=":"

'start=GETTICK
'REPEAT ' timer for speech to finish...
'UNTIL GETTICK > (start+50000) ' 5 seconds

?RNDpass$ ' print passcode to the terminal...

END
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
Andries Pretorius
Posts: 37
Joined: Thu Nov 01, 2012 10:57 am
Location: Johannesburg, South Africa

Re: SERINP$ routine does not function as expected...???

Unread post by Andries Pretorius »

Good morning Robert!

I also had a look at your program. It looks fine to me in terms of program flow and doing what it is supposed to programatically.

When I simulate your program in the console, it waits for the ":' character, as it is supposed to, and when I enter the ":" character via the keyboard, it exits the REPEAT....UNTIL loop and proceeds with the next program step. This happens correctly with each and every REPEAT....UNTIL loop in your program until the program ends.

So, my conclusion is that there are no obvious errors on your generic program flow and structure, and that the possible cause might be the interaction between EMIC2 and EZSBC1, probably timing.

EMIC2 interface requires a setting of 9600 bps, 8 data bits, no parity, 1 stop bit (8N1) and your setting of "SERINIT 1,9600,8,1,0" is therefore correct. the problem can't be here!

But, not having access to an EMIC2 module, I can only make the following additional suggestions:

* I would incorporate the routine to clear the receive buffer as the first step in the REPEAT....UNTIL loop, rather than before entering the loop.
* I would try and include a delay between the "x=SEROUT(1,CR$)" and the "x$=SERINP$(1,1,ASCII(":"),5000000)" to ensure that there is sufficient time fir the EMIC2 to complete its response to the EZSBC's SEROUT.

My suggested REPEAT....UNTIL loop looks like this:

Code: Select all

REPEAT
x$=SERINP$(1,-1,-1,1)   			           ' Clear the receive buffer
x=SEROUT(1, CHR$(13))                               ' Send a CR to Emic and
WAIT(20)                                                     ' Delay 20ms
x$= SERINP$(1, 1,ASCII(":"),5000000)            ' check if a ":" is returned
                                                                   ' to show Emic is ready to receive
UNTIL x$ = ":" 
I hope you find a solution soon.

Best regards

Andries
User avatar
RBSe
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California
Contact:

Re: SERINP$ routine does not function as expected...???

Unread post by RBSe »

Sorry Daniel,

That does not make sense to me.
Could you insert the corrections in my test code listed above.
I'll learn by seeing the changes in what I wrote.
Thanks,

Robert
.
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
Andries Pretorius
Posts: 37
Joined: Thu Nov 01, 2012 10:57 am
Location: Johannesburg, South Africa

Re: SERINP$ routine does not function as expected...???

Unread post by Andries Pretorius »

Here is the suggested changes to your code>

Code: Select all

'talk test

PINMODE 36, OUT ' set pin 36 as output for serial TX
PINMODE 37, IN  ' set pin 37 as input for serial RX
SERINIT 1,9600,8,1,0 ' port 1, 9600 bps, 8 data bits, 1 stop bit, no parity
CR$ = CHR$(13) ' for CR

REPEAT
        x$=SERINP$(1,-1,-1,1)   			 ' Clear the receive buffer
		x=SEROUT(1, CHR$(13))                ' Send a CR to Emic and
        WAIT(20) ' Delay 20ms
		x$= SERINP$(1, 1,ASCII(":"),5000000)   ' check if a ":" is returned
                                             ' to show Emic is ready to receive
UNTIL x$ = ":"

x$=SERINP$(1,-1,-1,1)  ' Clear the receive buffer of the previous ":"

? "Booted... Input Command or [ENTER] to continue:"

INPUT setup$              ' get input from terminal
x=SEROUT(1,setup$+CR$)

REPEAT
        WAIT(20) ' Delay 20ms to see if the EMIC responded with ":" to SEROUT
		x$= SERINP$(1, 1,ASCII(":"),5000000)   ' check if a ":" is returned
                                             ' to show Emic is ready to receive
UNTIL x$ = ":"
x$=SERINP$(1,-1,-1,1)  ' Clear the receive buffer of the previous ":"

TXtalk$ = "hello. blah-blah-blah..."

? "Speaking..."

SOUT$ = "s" + TXtalk$ + CR$ ' combine "s" for speak, text & CR
x = SEROUT (1, SOUT$) ' Sends SOUT$ to serial port 1 (pin 36)

REPEAT
        WAIT(20) ' Delay 20ms to see if the EMIC responded with ":" to SEROUT
		x$= SERINP$(1, 1,ASCII(":"),5000000)   ' check if a ":" is returned
                                             ' to show Emic is ready to receive
UNTIL x$ = ":"
x$=SERINP$(1,-1,-1,1)  ' Clear the receive buffer of the previous ":"

'start=GETTICK ' 1 tick = 0.0001 seconds
'REPEAT ' timer for speech to finish...
'UNTIL GETTICK > (start+5000000) ' 13 seconds

? "Speaking..."

RNDpass$=STR$(INT(RND(9000)+1000)) ' random number between 1000 & 9999
x=SEROUT(1,"s"+RNDpass$+". that's, "+RNDpass$+CR$)


REPEAT
        WAIT(20) ' Delay 20ms to see if the EMIC responded with a ":" to SEROUT
		x$= SERINP$(1, 1,ASCII(":"),5000000)   ' check if a ":" is returned
                                             ' to show Emic is ready to receive
UNTIL x$ = ":"

'start=GETTICK
'REPEAT ' timer for speech to finish...
'UNTIL GETTICK > (start+50000) ' 5 seconds

?RNDpass$ ' print passcode to the terminal...

END
I must again emphasize that there is no way that I can test the code on a real EMIC2. It is thus only completely untested suggestions which may or may not help.

Best regards

Andries
User avatar
RBSe
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California
Contact:

Re: SERINP$ routine does not function as expected...???

Unread post by RBSe »

Thanks Andries,

I appreciate you inserting the changes in my code, which is a known constant in my head, and that makes it easier for me to understand.
Let's put our thinking caps on and analyze what is happening here.
I added timers in the code to measure the time spent in a RX serial REPEAT/UNTIL loop.
Here is the code with the timers inserted, it is what you modified:

Code: Select all

'talk test

PINMODE 36, OUT ' set pin 36 as output for serial TX
PINMODE 37, IN  ' set pin 37 as input for serial RX
SERINIT 1,9600,8,1,0 ' port 1, 9600 bps, 8 data bits, 1 stop bit, no parity
CR$ = CHR$(13) ' for CR

'timer to measure loop time
looptime = GETTICK

REPEAT
        x$=SERINP$(1,-1,-1,1)             ' Clear the receive buffer
      x=SEROUT(1, CHR$(13))                ' Send a CR to Emic and
        WAIT(20) ' Delay 20ms
      x$= SERINP$(1, 1,ASCII(":"),5000000)   ' check if a ":" is returned
                                             ' to show Emic is ready to receive
UNTIL x$ = ":"

x$=SERINP$(1,-1,-1,1)  ' Clear the receive buffer of the previous ":"

'print loop time
? (GETTICK - looptime)/10 , " ms"

? "Booted... Input Command or [ENTER] to continue:"

INPUT setup$              ' get input from terminal
x=SEROUT(1,setup$+CR$)

'timer to measure loop time
looptime = GETTICK

REPEAT
        WAIT(20) ' Delay 20ms to see if the EMIC responded with ":" to SEROUT
      x$= SERINP$(1, 1,ASCII(":"),5000000)   ' check if a ":" is returned
                                             ' to show Emic is ready to receive
UNTIL x$ = ":"
x$=SERINP$(1,-1,-1,1)  ' Clear the receive buffer of the previous ":"

'print loop time
? (GETTICK - looptime)/10 , " ms"

        TXtalk$ = "hello. i am the emic 2 text 2 speech module being tested on the EzSBC1."

? "Speaking greeting..."

'timer to measure loop time
looptime = GETTICK

SOUT$ = "s" + TXtalk$ + CR$ ' combine "s" for speak, text & CR
x = SEROUT (1, SOUT$) ' Sends SOUT$ to serial port 1 (pin 36)

REPEAT
        WAIT(20) ' Delay 20ms to see if the EMIC responded with ":" to SEROUT
      x$= SERINP$(1, 1,ASCII(":"),5000000)   ' check if a ":" is returned
                                             ' to show Emic is ready to receive
UNTIL x$ = ":"
x$=SERINP$(1,-1,-1,1)  ' Clear the receive buffer of the previous ":"

'start=GETTICK ' 1 tick = 0.0001 seconds
'REPEAT ' timer for speech to finish...
'UNTIL GETTICK > (start+5000000) ' 13 seconds

'print loop time
? (GETTICK - looptime)/10 , " ms"

? "Speaking number..."

'timer to measure loop time
looptime = GETTICK

RNDpass$=STR$(INT(RND(9000)+1000)) ' random number between 1000 & 9999
x=SEROUT(1,"s"+RNDpass$+". that's, "+RNDpass$+CR$)


REPEAT
        WAIT(20) ' Delay 20ms to see if the EMIC responded with a ":" to SEROUT
      x$= SERINP$(1, 1,ASCII(":"),5000000)   ' check if a ":" is returned
                                             ' to show Emic is ready to receive
UNTIL x$ = ":"

'start=GETTICK
'REPEAT ' timer for speech to finish...
'UNTIL GETTICK > (start+50000) ' 5 seconds

'print loop time
? (GETTICK - looptime)/10 , " ms"

?RNDpass$ + " random number" ' print passcode to the terminal...

END
Here is the result of the program run:
Control BASIC v0.73
R-Run S-Step L-List E-Edit C-Configure B-Bank D-Download K-Reset T-Time & Date
Start program
42.2 ms
Booted... Input Command or [ENTER] to continue:

41.3 ms
Speaking greeting...
115.8 ms
Speaking number...
6247.4 ms
9201 random number

Program Ended.
Now let me describe what is happening in RED:

===
Start program
42.2 ms
Booted... Input Command or [ENTER] to continue:
--{ I hit {ENTER} and a CR is sent to the Emic 2 ]--
41.3 ms
Speaking greeting...
115.8 ms
Speaking number...
--[ speech starts and goes to here after 157.1 ms and waits for the greeting text to be spoken, passing over speaking the random number speech. ]--
6247.4 ms
--[ greeting speech has finished and only prints the random number ]--
9201 random number

Program Ended.
===

The second time i run this program it immediately says ",(random number 1 digit, something "what" like garbage)" and then displays the timer value in ms. it took to speak the garbage and it's ready receive an input from the terminal.
When you hit {ENTER} it proceeds the same as above, the 3rd and 4th time running and so on.

Progress has been made since it did wait for the speech to finish before printing the random number but it's still not right.
There should be enough data here to diagnose the problem if you study the code and it's responses.
If not, then a better code to test the problem should be written.

Thanks for your help,

Enjoy!

Robert
.
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
Andries Pretorius
Posts: 37
Joined: Thu Nov 01, 2012 10:57 am
Location: Johannesburg, South Africa

Re: SERINP$ routine does not function as expected...???

Unread post by Andries Pretorius »

Hi Robert.

I am looking at possible options. Will let you know if I find something.

Have a great say!

Andries
User avatar
RBSe
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California
Contact:

Re: SERINP$ routine does not function as expected...???

Unread post by RBSe »

In addition to the above "Talk Test" program code and report of operation, i am including the stereo recording of the 2 serial lines in real-time as the program ran, it lasts 7 seconds.'
Save this audio wav file, http://rbse.us/ezsbc1/emic2_ezsbc1_seri ... pture_.wav to your computer by right clicking and pick "Save Link/Target As" from the menu.
Now open that wav file in Audacity and use Audacity as a scope to zoom into different parts of the file to see the data waveform and timing.
This first image is the whole 7 seconds of the recording with marks to show a zoomed in area of handshaking, or lack there of, on the second image.
To see the full-size images and another link to the wav file, go to this page on my website: http://rbse.us/ezsbc1

First Image:
Image

Second Image:
Image

Now if that's not enough to figure this out, i don't know what is...
I've been stuck on this over a month now and that is unacceptable.
If i don't get an answer soon i will abandon my future plans for this microcontroller and move on to something that works.

Robert
.
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
Andries Pretorius
Posts: 37
Joined: Thu Nov 01, 2012 10:57 am
Location: Johannesburg, South Africa

Re: SERINP$ routine does not function as expected...???

Unread post by Andries Pretorius »

Apologies Robert, but the the information you provided means nothing to me unless I have access to an Emic2 module to simulate the problem and explore possible solutions. I truly wish I could help you, but I've run out of ideas, unless I can physically analyse the programmatic interaction between EZsbc1 and Emic2. I still believe that the solution lies in the way that the program talks to the Emic2 module, rather than with EZsbc1 or Control Basic. I have already successfully interfaced EZsbc1 to a large number peripherals using Control Basic.

However, if you are looking at other processor boards, there are possible alternatives such as Propeller, Basic Stamp and Arduino. For all of these boards there are excellent example programs available on the Parallax website which can be incorporated into your own program. I don't know about the comparative cost of Propeller and Basic Stamp, but Arduino is very reasonably priced, and there is virtually limitless sources of code available on the Web.

I can only wish you the best of luck with your project and I'm still available to assist in any way that is within my level of competency.

Best regards

Andries
Robert Stretton

Re: SERINP$ routine does not function as expected...???

Unread post by Robert Stretton »

Somehow i got dropped from the forum and my password didn't work, so this is my new forum ID.

Andries, I don't understand.
I have given you the actual real-time response from the Emic 2 and the EzSBC1 serial data lines, using the program above, in my last posts.
There is no need to have an Emic 2 for yourself because you can see the response for yourself in the wav file as the program ran.
Use the the free audio studio program Audacity as a scope to zoom in on the waveform produced by the Emic 2 and the EzSBC1 when the program ran.
By zooming in on the waveform you can see the time on the top rail and the data bits being sent at that time, and which channel, right or left.
(The serial out on pin 36 of the EzSBC1 is in the right channel of the recording and serial in is in the left, pin 37)
In comparing the program code, the report of what happened during execution, and the recording of the data-train, should be enough to see what is happening.
If that does not work for you then i suggest you try and write your own test program that would measure and test the serial responses.
I will run the code you created on my system and show you the waveform responses in real-time of the serial data-stream by storing it in a wav file to examine later.
I can't be more clear than that, and you certainly have the basic programming skills to figure out a test program to run, and so does Daniel...
If you guys don't want to help me with this problem then say so and i''l be on my way...

Robert Stretton
.
Post Reply