News:

Let's find out together what makes a PIC Tick!

Main Menu

Serout random characters at the beginning

Started by JackB, Jan 01, 2025, 01:04 AM

Previous topic - Next topic

JackB

Hello everyone,

just a simple question about 'serout' command,

power up the PIC,clear the terminal buffer press a button to start the program first data received is
PPPPPcá

2nd button press follow with AAAAA

3rd button press AAAAA

and son on for the rest

I read about 'serin' were I can clear before receiving, but in the case of serout I wonder is there

a command or a sending procedure to ensure not random data is send when the program start.

Thanks to all.

; Port reading writing test
;

Device = 18F14K22   
Declare Xtal = 64
Config_Start
  FOSC = IRC                           ' Internal RC oscillator
  PLLEN = On                           ' PLL is under software control
  MCLRE = OFF
  LVP = OFF  'OFF:PORTC.3 I/O
Config_End

ANSEL = 0
ANSELH= 0
OSCCON = $70                           ' 16Mhz for PLLEN:64Mhz / p:17
DelayUS 100                           

TRISA = %00001000 ' 0:Out 1:In
TRISB = %00100000
TRISC = %00000000

MAIN:                                  ' Main Routine

While PORTA.3 = 1: Wend                ' Button Press
DelayMS 100                            ' Bounce delay
While PORTA.3 = 0: Wend                ' Button release
DelayMS 100                            ' Bounce delay

SerOut PORTB.6,84, ["AAAAA",13,10]  ' Send to terminal   

GoTo MAIN


normnet

Perhaps a delay on start-up to ensure the PIC is stable?

JackB

Hello Normnet,

I added 1ms before the button loop, but still same random data.

from your sugestion, I used "SerOut PORTB.6,84, [13,10]" before the button loop

after the PIC is power ON I cleared the terminal buffer then after pressing

the button the received data look's alright.

Thanks for the tip.


trastikata

Hello JackB,

is it an USB-to-COM device you are using? If yes, it could be that the problem is there. Or you can try another serial terminal program.

top204

Another recommendation is to use pull-up resistors of approx 150K Ohms to 180K Ohms on the TX and RX lines, so that the pins are never floating when the microcontroller first powers up, and the higher value resistors do not cause an excessive load on the pins.

Any floating on the RX or TX pins will be seen as a faulty receive or transmit, and produce random values.

JackB

Thanks Les,

I'll put a resistor on the RX TX  line , and see the results.

JackB

I Added 2 resistors of 150k from RX,TX pins to VCC on the FT232RL module

Power on the PIC, clear the terminal,

with the SerOut PORTB.6,84, ["Serout : AAAAA",13,10] still get random data

but with the 'HRSOutLn "HRSOutLn : AAAAA"' no random data

by using a SerOut PORTB.6,84, [13,10] before the MAIN: label the Serout command has no more

random data after pressing the button.

Theses two functions are similar but internaly work with different parameters

I'm guessing this could explain two different result.

Device = 18F14K22 
Declare Xtal = 64
Config_Start
  FOSC = IRC                          ' Internal RC oscillator
  PLLEN = On                          ' PLL is under software control
  MCLRE = OFF
  LVP = OFF  'OFF:PORTC.3 I/O
Config_End

ANSEL = 0
ANSELH= 0
OSCCON = $70                          ' 16Mhz for PLLEN:64Mhz / p:17
Declare Hserial_Baud = 9600            ' USART 1 Baudrate
Declare HRSOut1_Pin = PORTB.7          ' USART 1 out pin

TRISA = %00001000 ' 0:Out 1:In
TRISB = %00100000
TRISC = %00000000

SerOut PORTB.6,84, [13,10]            ' Send to terminal   
 
MAIN:                                  ' Main Routine

While PORTA.3 = 1: Wend                ' Button Press
DelayMS 100                            ' Bounce delay
While PORTA.3 = 0: Wend                ' Button release
DelayMS 100                            ' Bounce delay


HRSOutLn "HRSOutLn : AAAAA"
SerOut PORTB.6,84, ["Serout : AAAAA",13,10]  ' Send to terminal   

GoTo MAIN





Pepe

#7
add this High PORTB.6

Device = 18F14K22
Declare Xtal = 64
Config_Start
  FOSC = IRC                          ' Internal RC oscillator
  PLLEN = On                          ' PLL is under software control
  MCLRE = OFF
  LVP = OFF  'OFF:PORTC.3 I/O
Config_End

ANSEL = 0
ANSELH= 0
OSCCON = $70                          ' 16Mhz for PLLEN:64Mhz / p:17
Declare Hserial_Baud = 9600            ' USART 1 Baudrate
Declare HRSOut1_Pin = PORTB.7          ' USART 1 out pin

TRISA = %00001000 ' 0:Out 1:In
TRISB = %00100000
TRISC = %00000000

High PORTB.6                          ' <------ add this

SerOut PORTB.6,84, [13,10]            ' Send to terminal 
 
MAIN:                                  ' Main Routine

While PORTA.3 = 1: Wend                ' Button Press
DelayMS 100                            ' Bounce delay
While PORTA.3 = 0: Wend                ' Button release
DelayMS 100                            ' Bounce delay


HRSOutLn "HRSOutLn : AAAAA"
SerOut PORTB.6,84, ["Serout : AAAAA",13,10]  ' Send to terminal 

GoTo MAIN


trastikata

#8
Hello JackB,

I think there's something with the USB to COM converter - it looks like it needs two sync bits or for some other reason the first two bits after power on are not shifted correctly in the buffer.

A bit stream PPPP (as the wrong one in your example) is actually AAAA with first bits shifted and carried.

ERR.jpg

Edit:

I just saw you don't see the same issue if hardware UART is used instead of the software, which suggest a possibility of an anomaly in how the bits are shifted and rotated in the software loops. To be sure one must analyze the resulting assembler code for software UART, but that's quite a few lines.

trastikata

#9
@Pepe

Is it possible to configure the terminal window in your simulation to display the value of the received byte instead of the ASCII representation?



JackB

Hello Pepe, trastikata

many thanks for your help,

by adding a 'High PORTB.6' before MAIN not using the 'SerOut PORTB.6,84, [13,10] line

when switching power on, the terminal doesn't receive any random data.


Thanks again to all.


High PORTB.6  'condition Port to avoid random data
'SerOut PORTB.6,84, [13,10]             ' Send to terminal   
  
MAIN:                                  ' Main Routine

While PORTA.3 = 1: Wend                ' Button Press
DelayMS 100                            ' Bounce delay
While PORTA.3 = 0: Wend                ' Button release
DelayMS 100                            ' Bounce delay


HRSOutLn "HRSOutLn : AAAAA"
SerOut PORTB.6,84, ["Serout : AAAAA",13,10]  ' Send to terminal   











JackB

Hello  trastikata

here's the hex received, from power on to button press for the Serout.


Pepe

Program with Proteus terminal in hex

JackB

#13
Hello Pepe,

and thank you for the info's

Also I'd like to share this digital analyzer scan (ASCII), that show the relation

for the Serout output signal with PORTB.6 = Low & High versus of the HRSout.

by default the  Serout start at LOW, thus inducting random data from the start.

when PORTB.6 = high the Serout send only the program data without any random characters

similar to the HRSout function by default the state of PORTB.7 = HIGH and send the

program data with no random data.


Update: Jan 3 2025   PIC18F14K22  Serout

another test show when using other output PIN like Porta.0 whitout setting the pin to high

the serout signal start at high after a power on, and not at low as for the portb.6 example

this suggess each PIN state could be different at start up.









Thanks to all for helping.