Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550


+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598

    Question Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550

    Code on 16F877:

    Code:
    #CONFIG
        __config _HS_OSC & _WDT_OFF & _WRT_OFF & _BOREN_ON & _LVP_OFF  & _CPD_OFF & _PWRTE_ON & _DEBUG_OFF
    #ENDCONFIG
    
    DEFINE  OSC 20
    
    INCLUDE "ALLDIGITAL.pbp"        ; Set all pins as digital
    
    TRISD = %00000000
    PORTD = %00000000
    
    PAUSE   1000      
    
    START:  PORTD = %10101010
            PAUSE   1000      
            PORTD = %01010101
            PAUSE   1000      
    
            GOTO    START
    Finish: end

    Code on 18F4550:

    Code:
    #CONFIG
        CONFIG    PLLDIV=5, CPUDIV=OSC1_PLL2, USBDIV=2, FOSC=HSPLL_HS
        CONFIG    PWRT=ON, BOR=ON, BORV=1, VREGEN=ON, WDT=OFF
        CONFIG    CCP2MX=ON, PBADEN=OFF, LPT1OSC=OFF, MCLRE=ON
        CONFIG    STVREN=ON, LVP=OFF, ICPRT=OFF, XINST=OFF
    #ENDCONFIG
    
    DEFINE OSC 48
    
    INCLUDE "ALLDIGITAL.pbp"        ; Set all pins as digital
    
    TRISD = %00000000
    PORTD = %00000000
    
    PAUSE   1000      
    
    START:  PORTD = %10101010
            PAUSE   1000      
            PORTD = %01010101
            PAUSE   1000      
    
            GOTO    START
    Finish: end

    Close-up of jumpers on Lab-X1:

    Name:  Blinky 16F877 vs 18F4550.jpg
Views: 2706
Size:  49.4 KB


    Lab-X1 oscillator jumpers:

    Name:  Lab X1 osc settings.png
Views: 2567
Size:  25.8 KB


    The only difference between the 2 MCUs are the CONFIG and DEFINE OSC statements.


    I'm at a loss to explain what I'm doing wrong here. Whatever I'm doing wrong, I've been doing it for a very long time.

    Robert
    I can't see the forest with all those trees standing in the way.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550

    Test 1, slow 16F877 to 4 MHz:

    Code:
    #CONFIG
        __config _XT_OSC & _WDT_OFF & _WRT_OFF & _BOREN_ON & _LVP_OFF  & _CPD_OFF & _PWRTE_ON & _DEBUG_OFF
    #ENDCONFIG
    
    DEFINE  OSC 4
    Lab-X1 jumper A=23

    Nothing...


    Go back to HS @ 20MHz with jumper A=12:

    Back to twice as fast as it should...

    Really puzzled, I expected it to run perfectly at 4 MHz.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550

    Report here of some old PICs having been issued with 4 MHz max rating here:

    https://www.embeddedrelated.com/show...ist/2282-1.php


    I checked, mine are all ...-20.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550

    Test 2, set all ports on 16F877 as output:

    Code:
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %00000000
    TRISD = %00000000
    TRISE = %00000000
    
    PORTA = %00000000
    PORTB = %00000000
    PORTC = %00000000
    PORTD = %00000000
    PORTE = %00000000
    No difference, still blinking at twice the expected rate...


    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550

    Do you have any means to check the real frequency oscillator output that is going to the PIC?

    Also, JP3 does no look that is is correctly connected. PIC should be on the midle pin and the jumper select either 4MHz or the CLK output of the chip U2.

    If Y1A out pin is the PIC clock input, then this pin will always get 4MHz as the diagram shows no matter what the other jumpers are at.

    Correct me if I am wrong, but on that diagram seems to me that way.

    Ioannis
    Last edited by Ioannis; - 5th May 2023 at 07:10.

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550

    Quote Originally Posted by Ioannis View Post
    ... Also, JP3 does no look that is is correctly connected. PIC should be on the midle pin and the jumper select either 4MHz or the CLK output of the chip U2.

    If Y1A out pin is the PIC clock input, then this pin will always get 4MHz as the diagram shows no matter what the other jumpers are at.

    Correct me if I am wrong, but on that diagram seems to me that way.

    Ioannis

    Y1A is not populated on the Lab-X1. You can add an IC if you wish to replace the default setup. Taken fron LABX1.TXT:

    ... To select a 20MHz clock, jumpers A and B should be on pins 1 and 2 and jumper C should be on pins 2 and 3.

    Jumper JP3 (not populated) allows a crystal or TTL or CMOS oscillator to be used directly without the ISC502M clock generator. A TTL or CMOS oscillator, Y1A, may be used in place of crystal Y1 and the 2 capacitors, C5 and C6.

    Having the jumper on the top 2 pins completes the circuit from ICS502M towards OSC1 (referred to as O1).

    Robert

  7. #7
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550

    Quote Originally Posted by Demon View Post
    Test 2, set all ports on 16F877 as output:

    Code:
    TRISA = 000000
    TRISB = 000000
    TRISC = 000000
    TRISD = 000000
    TRISE = 000000
    
    PORTA = 000000
    PORTB = 000000
    PORTC = 000000
    PORTD = 000000
    PORTE = 000000
    No difference, still blinking at twice the expected rate...


    Robert
    Don't you have to make one of the External Oscillator pins an Input in the TRISx Register? I'm on the road and can't look at the Data Sheet.

  8. #8
    Join Date
    Aug 2011
    Posts
    412


    Did you find this post helpful? Yes | No

    Default Re: Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550

    On those old chips like the 16F877, OSC1 and OSC2 aren't part of PORTA.

  9. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550

    Quote Originally Posted by mpgmike View Post
    Don't you have to make one of the External Oscillator pins an Input in the TRISx Register? I'm on the road and can't look at the Data Sheet.

    Pretty sure I saw that on USART pins.

    Robert

Similar Threads

  1. 4 x 4 Keypad on Port B (18F4550 with Lab X1)
    By Demon in forum Code Examples
    Replies: 7
    Last Post: - 21st April 2015, 07:08
  2. 50mS counter on Timer0 (18F4550 on Lab X1)
    By Demon in forum Code Examples
    Replies: 0
    Last Post: - 16th April 2015, 03:07
  3. convert from 16F877 to 18F4550
    By starwick in forum General
    Replies: 4
    Last Post: - 15th May 2013, 18:36
  4. Lab X1 and 16F877 examples for beginners
    By Demon in forum Code Examples
    Replies: 6
    Last Post: - 8th January 2012, 04:19
  5. A/D on 16F877. How fast can I go?
    By atomski in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th April 2004, 06:51

Members who have read this thread : 9

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts