serin/serout turn around time

jims

Senior Member
I'm running PE6 on a 20x2 with an Emic2 TTS Module. I believe that I'm having a "turn around timing" problem with this code. Things work OK when the Emic2 module sends it's response after the "speaking" message sent with the Sxxx command. This takes over 1 second and everything works OK. However, when I send the Lx command (which responds in about 0.2 Mseconds), the responses are "garbled' and there doesn't seem to be a pattern to the responses. Seems to me that part of the response from Emic2 has been sent before the 20x2 serin is ready to receive. Any comments about what may be happening? Jims
Code:
[color=Green]'* 20x2 running Emic 2 text to speech module.
'* Transmit message to Emic2 with "serout",
'* use "serin" to wait for response, then
'* display the response on serial terminal.[/color]

[color=Blue]symbol [/color][color=Black]xmit_out[/color][color=DarkCyan]=[/color][color=Blue]C.0    [/color][color=Green]'pin 10  green wire[/color]
[color=Blue]symbol [/color][color=Black]rcv_in[/color][color=DarkCyan]=[/color][color=Blue]B.6     [/color][color=Green]'pin 12  white wire[/color]


[color=Navy]#Picaxe [/color][color=Black]20x2[/color]
[color=Navy]#Terminal 9600[/color]


[color=Green]' Use these values when simulating with serin ( 13 58 ) raw.[/color]
[color=Black]init:[/color]
[color=Blue]pause [/color][color=Navy]3000   [/color][color=Green]'Module takes 3 seconds to initialize on power-up.[/color]
[color=Blue]high C.0    [/color][color=Green]'Put xmit line into true state.
'serout xmit_out,T9600 ,("V16",cr)    'Set volume loud, 16 decibles.[/color]
[color=Blue]pause [/color][color=Navy]50
 [/color]

[color=Black]main:
      [/color][color=Blue]do
      [/color][color=Purple]b0[/color][color=DarkCyan]=[/color][color=Navy]0[/color][color=Black]:[/color][color=Purple]b1[/color][color=DarkCyan]=[/color][color=Navy]0
      [/color][color=Blue]pause [/color][color=Navy]100
      [/color][color=Green]'serout xmit_out,T9600 , ("S"," I got your message. ",cr) 'Speak message.
      [/color][color=Blue]serout [/color][color=Black]xmit_out,[/color][color=Blue]T9600[/color][color=Black],[/color][color=Blue]([/color][color=Red]"L0"[/color][color=Black],[/color][color=Blue]cr)    [/color][color=Green]'Set language to English.
      [/color][color=Blue]SerIn [/color][color=Black]rcv_in, [/color][color=Blue]T9600 [/color][color=Black], [/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1  [/color][color=Green]'wait for response
      [/color][color=Blue]sertxd ([/color][color=Red]"Received "[/color][color=Black],#[/color][color=Purple]b0[/color][color=Black],[/color][color=Red]" "[/color][color=Black],#[/color][color=Purple]b1[/color][color=Black],[/color][color=Navy]13[/color][color=Black],[/color][color=Navy]10[/color][color=Blue])[/color][color=Green]'Display the 2 data bytes received.
      [/color][color=Blue]pause [/color][color=Navy]3000
      [/color][color=Blue]loop[/color]
 

Goeytex

Senior Member
It seems you are operating the 20X2 at the default 8Mhz since there is no setfreq command and since you are not using the suggested Serout Pin,T9600_X that sets the baud rate according to the processor speed.

It has been my experience that serin at 9600 baud with a processor clock of 8MHz is not a good combination. There has been lots of discussion about this. I suggest you set the processor speed to either 16 or 32 MHz and then use the suggested syntax for serin e.g, " serin, rev_in,T9600_16,b0,b1"

Try the code below and see if the received data is correct: If not, then set the processor to M32 and use serout/serin T9600_32

Code:
[color=Green]'* 20x2 running Emic 2 text to speech module.
'* Transmit message to Emic2 with "serout",
'* use "serin" to wait for response, then
'* display the response on serial terminal.[/color]

[color=Blue]symbol xmit_out[/color][color=DarkCyan]=[/color][color=Blue]C.0    [/color][color=Green]'pin 10  green wire[/color]
[color=Blue]symbol rcv_in[/color][color=DarkCyan]=[/color][color=Blue]B.6     [/color][color=Green]'pin 12  white wire[/color]


[color=Navy]#Picaxe [/color][color=Black]20x2[/color]
[color=Navy]#Terminal 19200[/color]
[color=Blue]setfreq M16    [/color][color=Green]'Processor speed = 16MHz 

' Use these values when simulating with serin ( 13 58 ) raw.[/color]
[color=Black]init:[/color]
[color=Blue]pause [/color][color=Navy]6000   [/color][color=Green]'Module takes 3 seconds to initialize on power-up.[/color]
[color=Blue]high C.0     [/color][color=Green]'Put xmit line into true state.
'serout xmit_out,T9600 ,("V16",cr)    'Set volume loud, 16 decibles.[/color]
[color=Blue]pause [/color][color=Navy]100
 [/color]

[color=Black]main:
      [/color][color=Blue]do
      [/color][color=Purple]b0[/color][color=DarkCyan]=[/color][color=Navy]0 [/color][color=Black]: [/color][color=Purple]b1[/color][color=DarkCyan]=[/color][color=Navy]0
      [/color][color=Blue]pause [/color][color=Navy]200
      [/color][color=Green]'serout xmit_out,T9600 , ("S"," I got your message. ",cr) 'Speak message.
      [/color][color=Blue]serout xmit_out[/color][color=Black],[/color][color=Blue]T9600_16[/color][color=Black],[/color][color=Blue]([/color][color=Red]"L0"[/color][color=Black],[/color][color=Blue]cr)    [/color][color=Green]'Set language to English.
      [/color][color=Blue]SerIn rcv_in[/color][color=Black], [/color][color=Blue]T9600_16 [/color][color=Black], [/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1  [/color][color=Green]'wait for response
      [/color][color=Blue]sertxd ([/color][color=Red]"Received "[/color][color=Black],#[/color][color=Purple]b0[/color][color=Black],[/color][color=Red]" "[/color][color=Black],#[/color][color=Purple]b1[/color][color=Black],[/color][color=Navy]13[/color][color=Black],[/color][color=Navy]10[/color][color=Blue])[/color][color=Green]'Display the 2 data bytes received.
      [/color][color=Blue]pause [/color][color=Navy]6000
      [/color][color=Blue]loop[/color]
 

hippy

Technical Support
Staff member
It could well be turnround speed and corruption with not being ready quickly enough for when a response is sent. I recall we got to that assessment in the earlier thread when trying to use an M2. Run faster as Goeytex says and I'd try M64 as the 20X2 supports that.

If that's still showing corruption on immediate responses but okay when there's a delayed response the options would be to go to background receive, pause for some time and assume an okay response, or just ignore the corruption and again assume an okay response.
 

jims

Senior Member
Thank you, Goeytext... I've got to leave for a few days & will try it when I return.
It seems you are operating the 20X2 at the default 8Mhz since there is no setfreq command and since you are not using the suggested Serout Pin,T9600_X that sets the baud rate according to the processor speed.

It has been my experience that serin at 9600 baud with a processor clock of 8MHz is not a good combination. There has been lots of discussion about this. I suggest you set the processor speed to either 16 or 32 MHz and then use the suggested syntax for serin e.g, " serin, rev_in,T9600_16,b0,b1"

Try the code below and see if the received data is correct: If not, then set the processor to M32 and use serout/serin T9600_32

Code:
[color=Green]'* 20x2 running Emic 2 text to speech module.
'* Transmit message to Emic2 with "serout",
'* use "serin" to wait for response, then
'* display the response on serial terminal.[/color]

[color=Blue]symbol xmit_out[/color][color=DarkCyan]=[/color][color=Blue]C.0    [/color][color=Green]'pin 10  green wire[/color]
[color=Blue]symbol rcv_in[/color][color=DarkCyan]=[/color][color=Blue]B.6     [/color][color=Green]'pin 12  white wire[/color]


[color=Navy]#Picaxe [/color][color=Black]20x2[/color]
[color=Navy]#Terminal 19200[/color]
[color=Blue]setfreq M16    [/color][color=Green]'Processor speed = 16MHz 

' Use these values when simulating with serin ( 13 58 ) raw.[/color]
[color=Black]init:[/color]
[color=Blue]pause [/color][color=Navy]6000   [/color][color=Green]'Module takes 3 seconds to initialize on power-up.[/color]
[color=Blue]high C.0     [/color][color=Green]'Put xmit line into true state.
'serout xmit_out,T9600 ,("V16",cr)    'Set volume loud, 16 decibles.[/color]
[color=Blue]pause [/color][color=Navy]100
 [/color]

[color=Black]main:
      [/color][color=Blue]do
      [/color][color=Purple]b0[/color][color=DarkCyan]=[/color][color=Navy]0 [/color][color=Black]: [/color][color=Purple]b1[/color][color=DarkCyan]=[/color][color=Navy]0
      [/color][color=Blue]pause [/color][color=Navy]200
      [/color][color=Green]'serout xmit_out,T9600 , ("S"," I got your message. ",cr) 'Speak message.
      [/color][color=Blue]serout xmit_out[/color][color=Black],[/color][color=Blue]T9600_16[/color][color=Black],[/color][color=Blue]([/color][color=Red]"L0"[/color][color=Black],[/color][color=Blue]cr)    [/color][color=Green]'Set language to English.
      [/color][color=Blue]SerIn rcv_in[/color][color=Black], [/color][color=Blue]T9600_16 [/color][color=Black], [/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1  [/color][color=Green]'wait for response
      [/color][color=Blue]sertxd ([/color][color=Red]"Received "[/color][color=Black],#[/color][color=Purple]b0[/color][color=Black],[/color][color=Red]" "[/color][color=Black],#[/color][color=Purple]b1[/color][color=Black],[/color][color=Navy]13[/color][color=Black],[/color][color=Navy]10[/color][color=Blue])[/color][color=Green]'Display the 2 data bytes received.
      [/color][color=Blue]pause [/color][color=Navy]6000
      [/color][color=Blue]loop[/color]
 

Goeytex

Senior Member
If the minimum response time of the EMIC2 is 100us, then you will probably need to use setfreq M64 and serin/serout T9600_64. Otherwise background receive will be necessary.

Another option is to not serial receive the data at all. Just use an input pin (with pullup) for an "interrupt on low" and connect that pin to the EMMIC2 TX. When the signal goes low, indicating a response (that is assumed to be good) the interrupt is triggered. Place a short delay (5- 10 ms) in the interrupt routine to make sure the EMIC is ready for the next command, then return from the interrupt routine back to the main program.
 
Top