Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Hserout baud rate problem.

Status
Not open for further replies.

Roger Harrold

New Member
Hello, I'm new to the forum.

Code:
'    PIC18F2520, 16MHz crystal clock
 
    Define CLOCK_FREQUENCY = 16
   
    Dim b0 As Byte
    Dim b1 As Byte
    Dim b2 As Byte
    Dim b3 As Byte
    Dim b4 As Byte
   
    Hseropen 1200
    Break
    Hserout b0,b1,b2,b3,b4
    Break
 
    End

I have a problem using the simulator with the Hserout statement.
If I run my code on the simulator, transmitting 1, 2, 3, 4 or 5 bytes always results in the same Real Time Duration
value regardless of the Baud rate set in the Hseropen statement. I've tried 1200, 9600 & 19200.
The times between the two Break statements are as follows:
No. of Bytes.........Time (uS)

1...........Effectively zero
2...........Effectively zero
3...........1000
4.......... 2000
5.......... 3000
I understand the first two very short times, as the Tx hardware is buffering & transmitting without holding up the software.
But as I increase the number of bytes, the extra time taken is always about 1mS per byte, regardless of Baud rate.
It seems as if the Baud rate is always about 9600. The simulator is set to 16MHz.
The SPBRG register contains the following values for each of the 3 Baud rates tried:


Baud ..........SPBRG
1200 ..........CF
9600 ..........19
19200 ........0C
If I run the code on the hardware, my comms. analyser tells me the baud rates are correct.
I'm obviously missing something, but I can't work out what it is.
Does anyone have any ideas, please?


(Sorry if some of the above formatting above looks a bit amateurish)
 
hi Roger,
The Oshonsoft runs the simulated UART at a fixed rate, you may have seen that the UART pins on the PIC tool do not show the switching states of the pins when 'transmitting' data.

Try using the Tools Scope to see the waveforms on the TXD pin.

Your correct baud rates will apply in a programmed PIC

E
 
hi Roger,
The Oshonsoft runs the simulated UART at a fixed rate, you may have seen that the UART pins on the PIC tool do not show the switching states of the pins when 'transmitting' data.

Try using the Tools Scope to see the waveforms on the TXD pin.

Your correct baud rates will apply in a programmed PIC

E

Many thanks. I thought it might be something along those lines, but I couldn't find it written down anywhere.
Cheers,
Roger
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top