1
\$\begingroup\$

I have the following config values for 18F452 on my code;

#pragma config  FOSC=HS
#pragma config  PWRT = OFF
#pragma config  BOR = OFF
#pragma config  BORV = 3
#pragma config  WDT = OFF
#pragma config  WDTPS = 128
#pragma config  CCP2MX = OFF
#pragma config  STVREN = OFF
#pragma config  LVP = OFF
#pragma config  DEBUG = OFF

Now, I want to switch to the 18F4550, but my code is executed too fast compared to the 18f452. I have the same hardware setup (basically I replace the PICs on breadboard). And my config values for 18F4550 is;

#pragma config PLLDIV   = 5         // 20Mhz external oscillator
#pragma config CPUDIV   = OSC1_PLL2   
#pragma config USBDIV   = 2         // Clock source from 96MHz PLL/2
#pragma config FOSC     = HSPLL_HS
#pragma config IESO     = OFF
#pragma config PWRT     = OFF
#pragma config BOR      = OFF
#pragma config BORV     = 3
#pragma config VREGEN   = ON
#pragma config WDT      = OFF
#pragma config WDTPS    = 128
#pragma config MCLRE    = ON
#pragma config LPT1OSC  = OFF
#pragma config PBADEN   = OFF
#pragma config CCP2MX   = ON
#pragma config STVREN   = ON
#pragma config LVP      = OFF
#pragma config ICPRT    = OFF
#pragma config XINST    = OFF
#pragma config CP0      = OFF
#pragma config CP1      = OFF
#pragma config CP2      = OFF
#pragma config CP3      = OFF
#pragma config CPB      = OFF
#pragma config CPD      = OFF
#pragma config WRT0     = OFF
#pragma config WRT1     = OFF
#pragma config WRT2     = OFF
#pragma config WRT3     = OFF
#pragma config WRTB     = OFF
#pragma config WRTC     = OFF
#pragma config WRTD     = OFF
#pragma config EBTR0    = OFF
#pragma config EBTR1    = OFF
#pragma config EBTR2    = OFF
#pragma config EBTR3    = OFF
#pragma config EBTRB    = OFF

To be honest, one might think this is a good thing because of the increased speed. But I've implemented a software UART and the required delays for my baud rate is based on clock cycles. This speed increase messed up my whole serial communication. Any ideas to synchronize two scenarios ? Thanks in advance,

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

If you just want to run the '4550 the same way as the '452, then use the same oscillator settings. Apparently you were using a 20 MHz crystal, which would have been without the PLL since that would have made it out of spec. You can do the same with the '4550. Use the HS oscillator mode without PLL. That part has a more complicated clock chain due to needing to support the USB peripheral, but you can make it run the same way as a '452 from the same crystal.

Why switch to the '4550 if you're not going to use its new features? The older '452 is still in production and likely will be for quite a while. Microchip has a very good track record not obsoleting parts.

These chips have a hardware UART. Why do it in firmware?

Even if you are using a soft UART, you should be able to change the clock speed, change a assembly constant accordingly, and have the soft UART code configure itself to the new clock speed automatically.

Too many things don't make sense in your question.

\$\endgroup\$
3
  • \$\begingroup\$ I'm sorry, I'm new to the PIC programming. The reason that I'm using software UART is, I've established a serial connection for my Parallax ColorPAL sensor which has only 1 pin for signals and I've failed to do that with usual RX/TX pins. I'm switching to 4550 because I wanted to command the sensor through a USB interface. I'm agreeing with you on the defining a constant for the delay mechanisms, to be honest I've seen an example on this subject and I've chosen the lazy path. I will overhaul my entire delay functions tonight. \$\endgroup\$
    – JuniorDev
    Commented Mar 8, 2012 at 14:49
  • \$\begingroup\$ One last question though, there areonly USB-HS and HS+PLL options on the OSC settings, there is no "HS" option like the older 16F or 18F series, which one should I pick. And thank you for your response. \$\endgroup\$
    – JuniorDev
    Commented Mar 8, 2012 at 14:50
  • \$\begingroup\$ @Ismail: Like I said, the 4550 has more fancy clock options than usual because it has to support USB. This is all carefully spelled out in the datasheet, including a diagram of the whole clock chain. Howwever, if you want to connect to the USB, only certain clock frequencies are available. Again, see the datasheet. \$\endgroup\$ Commented Mar 8, 2012 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.