PDA

View Full Version : 16F777 at 115200 baud



cpayne
- 22nd March 2011, 19:37
I am trying to get a 16F777 with a 20MHz external oscillator running at 115200 baud. There is no parity and it is true. My math for those conditions gives me -11.

I need to use the hardware serial port for something else and need to use SEROUT2.

What should the mode actually be when a negative number is calculated?

Thanks

aratti
- 22nd March 2011, 20:24
I don't use SERIN/SEROUT very often, but I think you should read the formula as :
((Fosc/4)/Bauds)-20 so, since you are using a 20 MHz external oscillator you should end up with 23. Try it and post the result, so I can verify if my understanding is correct.

Cheers

Al.

cpayne
- 22nd March 2011, 23:13
the forumula they have in the maual is (1000000/baud)-20, which results in -11. I tried 23 with no luck, or atlest the motor controller I was communicating with acts dumb. works fine with hyperterminal 8N1, 115k no flow control

cpayne
- 23rd March 2011, 00:12
this is what i come up with the varrious values to set the baud value
No Parity, True Parity, True No Parity, Inverted Parity, Inverted
115200 -11 8181 16373 24565


I have tried all the values, except -11, which is what i need I am pretty sure...

HSEROUT ["!M ", dec Motor_Val_R," ", dec Motor_Val_L, 13]'command motors ***THIS WORKS!!!!!!

SEROUT2 portB.4, 23, ["!M ", dec Motor_Val_R," ", dec Motor_Val_L, 13]'command motors, this does not....

I am snooping the packages, there is nothing when i run the serout2 line. the hserout2 works fine and looks fine on hyperterminal with the snooping...

Any ideas, Unfortunatly I can not change the baud rate of the motor controller to something slower... Have to get 115k working and i can't use the hardware port for the final configuration...

Charles Linquis
- 23rd March 2011, 01:50
You will not be able to run serout at more than about 19.2K baud with a 20Mhz Xtal

But, you MAY be able use DEBUGOUT at that rate. I have done it at 40Mhz on an 18F part.

BrianT
- 24th March 2011, 00:19
I routinely run 115,200 on a PIC18F4620 at 20 MHz.
Works a treat. I always set char_pacing to 20 or more to give some more time for the receiving side to process the character.

HTH
BrianT

HenrikOlsson
- 24th March 2011, 06:11
The forumula they have in the maual is (1000000/baud)-20, which results in -11.
As Al pointed out (but didn't really spell out) the 1000000 comes from Fosc/4 and since you're running at 20MHz the formula becomes (5000000/115200) - 20 = 23. I don't know if 115200 "should" work at 20MHz but if you can't get it going try DEBUG instead.

/Henrik.

cpayne
- 24th March 2011, 11:16
Thanks for all the help. I understand fosc/4, but i am not sure Serout2 or serin2 uses that. I define the osc speed up top. I have to use 10000000 to get 19200 or 38400 to work with no issue. the debug may work for outgoing, but eventually i will need incoming... I am currently laying out another board with a 2 UART chip since hserin and hserout work fine at 115k and a 20mhz osc, but i would really prefer to use my existing chip.

-Charlie

HenrikOlsson
- 24th March 2011, 12:48
OK, you're probably correct then, sounds a bit strange though.... Anyway, if DEBUG does indeed work for the output then DEBUGIN will most likely work for the input - as long as you don't need to change pin or baudrate at runtime.

/Henrik.

Charles Linquis
- 24th March 2011, 12:55
Debug is much more "light weight", since the parameters are calculated at compile time, not every time the routine is called.

It works fast in both directions.