CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

software uart on 115200 baud

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
overmindx



Joined: 06 Oct 2008
Posts: 43

View user's profile Send private message

software uart on 115200 baud
PostPosted: Tue Dec 02, 2014 4:56 am     Reply with quote

hi,
I am using an pic18f67k22 mcu on 16 MHz clock speed. I have a sensor that operates on 115200 baud. When i connect to it using hardware uart, i can communicate to it perfectly. However when i connect to it using the software uart pins, it doesn't reply. Now, my question is, is this a limitation of the software uart capability or there is a way to tweak it on the firmware code. Thanks..
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 02, 2014 6:59 am     Reply with quote

timing is 'everything' and SW UARTS are 'slow' and need to poll/time every bit that comes in.That's one reason why HW UARTS are far superior.Also they provide an interrupt for even faster performance.
IF you are fixed with that PIC, use the HW UART for the sensor.Assuming the PIC needs to talk to a PC or other serial device you might use the SW UART for that,esp. if 9600 baud or less.
These days I use the 18F46K22 for the 2 HW UARTS in it but other possible options include..
1) adding an I2C UART.....more pins and code....
2) tie serial to INT pin...works but need the I/O pin and code
3) replace PIC with one with 2 HW UARTS...layout/cost issues?

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Tue Dec 02, 2014 7:51 am     Reply with quote

Agree wholeheartedly. Timing is _everything_.

The software UART should be able to 'handle' 115200bps (I have used 50000bps at 4MHz),, but you have to understand that the software UART is half duplex only, and that the receive code needs to actually be sitting 'waiting' to receive. This latter is almost certainly where the problem lies. There is no margin. The hardware UART will start receiving automatically when the falling edge is seen. The software UART has to be in the getc, waiting for this edge to arrive. With low baud rates relative to the CPU clock rate there is just enough time for something like an interrupt to be used to trigger the getc, but at 115200bps, at 4mips there are only 34.7 instructions per bit. The receive code needs to be actually starting to sample _before_ the middle of the bit, so the time needed to get into an ISR, rules this out, and rules out doing anything much in the code, except sitting waiting for the character to arrive.

You need to think of changing to a chip with a second hardware UART, or operating at a lower baud rate, or designing the code so you know exactly when the reply is to start.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: software uart on 115200 baud
PostPosted: Tue Dec 02, 2014 5:54 pm     Reply with quote

overmindx wrote:
hi,
I am using an pic18f67k22 mcu on 16 MHz clock speed. I have a sensor that operates on 115200 baud. When i connect to it using hardware uart, i can communicate to it perfectly. However when i connect to it using the software uart pins, it doesn't reply. Now, my question is, is this a limitation of the software uart capability or there is a way to tweak it on the firmware code. Thanks..


The chip you are using has a second hardware UART. I guess you have not used it because you have used the PINs for something else.

If you are using a 16MHz crystal or external clock input then you could enable the PLL and run the PIC at 64MHz giving the PIC a greater probability of handling the software UART. Another option is to use your own software UART based on timer interrupts using the high priority interrupt vector. It is possible to implement a full duplex software UART at 115200 baud using this technique.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Wed Dec 03, 2014 1:10 am     Reply with quote

I have done timer based software full duplex UART's. 115200bps, I'd say is 'pushing' this even at 64MHz, but it does depend on what else the chip is doing. It might just about be possible, but requires careful programming. Into the 'you need to actually fully understand the chip' area, rather than basic programming.....
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Dec 03, 2014 1:26 am     Reply with quote

Ttelmah wrote:
I have done timer based software full duplex UART's. 115200bps, I'd say is 'pushing' this even at 64MHz, but it does depend on what else the chip is doing. It might just about be possible, but requires careful programming. Into the 'you need to actually fully understand the chip' area, rather than basic programming.....


Yes you absolutely must understand the chip architecture as well as how to optimize the interrupt handler. It is possible to run multiple 115200 baud full duplex serial ports simultaneously on a PIC18F4620 class controller running at 40MHz. I have done this with 3 software serial ports however there are tricks to implementing this. Only one timer interrupt is required to support multiple software uarts. In my case I coded the interrupt handler in assembler and the compiler was not aware that HP interrupts were enabled. This saved cycles by avoiding the need to push and pop registers than were not manipulated. All paths through the handler were the same length (same number of CPU cycles) to avoid introducing jitter.

Having said that, I would not do it again with this class processor. It is easier to use a more powerful PIC with multiple serial ports or add an SPI to UART chip to a design.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Wed Dec 03, 2014 1:35 am     Reply with quote

Absolutely.

I suspect you used tricks like 'byte syncing', so that the transmitted channels were all transmitting at the same time. This makes it not that much harder to transmit multiple channels than one. However 'pushing to limit' begins to apply...

Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group