PDA

View Full Version : 16F648 and 115200 at 4 Mhz doesn't work...



boban
- 24th January 2007, 00:19
Hello,
I stared to be frustrated from the fact, that my 16F648 doesn't work at 4 Mhz clock speed with HSERIN/HSEROUT commands.
Please see this code:

DEFINE OSC 20
'hserin definition
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 115200
DEFINE HSER_CLROERR 1

while 1
if (PIR1.5==1) then
goSUB manageSerialByte
endif
wend
end

manageSerialByte:
HSERIN 1,Jump,[SERIALBYTE]

If SERIALBYTE = "p" Then
HSEROUT ["hello",10]
end if
Jump:
return

This code is working perfectly, please see that OSC is 20 and I am using 20Mhz crystal resonator.

But due to the fact, that I want to operate the circuit on 3V, I need to use 4Mhz crystal and OSC 4.

So only what I did in my code I changed the first line:
DEFINE OSC 4

But I cannot manage to make serin and serout working. And the controller is working, because I am using in the code tmr0 interrupt, which is blinking LED and the LED is blinking, it means, that the PIC is working and processing the code, but the problem is, that this SERIN/SEROUT simply not work!!!
Thanks for feedback, what do you think about this strange problem...

Darrel Taylor
- 24th January 2007, 00:46
While the USART can go that fast at 4mhz, the closest to 115,200 you can get is 125,000, which is an 8.5% error.

If you use a 3.579mhz colorburst crystal. You can get 111,243 baud which is only 2.9% error.

Also there are a couple problems in your code. They may just be typo's, but...

The SERIALBYTE variable is missing. and...
just before JUMP: the "END IF" should be ENDIF.

HTH,

boban
- 24th January 2007, 09:55
Cus Darrel,
OK, thanks for the answer. These typo is OK, I have just copy paste the parts of my code to get the idea to the others, what I am doing :))))) So what you wrote is, that it is not possible to use this PIC at 4 Mhz with 115200. So you are suggesting to change tje crystal and to use 3.579 Mhz crystal, and in that case, it should work? I am now wondering, what will happen with PIC basic, because this is I think not supported. In manual for PIC basic is written that only supported values are 4, 8, 20 Mhz. Am I right? If not, what should be the OSC?

Darrel Taylor
- 24th January 2007, 11:53
OSC 3 is for 3.579mhz. (PBP manual page 170)

All the timing (pauses etc.) should work fine.
<br>

boban
- 11th February 2007, 18:36
Hello, I've just returned from holiday. I've just tested the 3 Mhz crystal and it is working well. So thanks a lot for valueable hints and answers!!!

Darrel Taylor
- 12th February 2007, 00:55
Excellent!

That's the first time I've seen a need to use OSC 3.
I always wondered why it was an option. Now we know. :)

Regards,