PDA

View Full Version : Blinky on Lab-X1 twice as fast on 16F877 as on a 18F4550



Demon
- 3rd May 2023, 20:12
Code on 16F877:


#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:


#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:

9381


Lab-X1 oscillator jumpers:

9382


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.

Demon
- 3rd May 2023, 21:15
Test 1, slow 16F877 to 4 MHz:


#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.

Demon
- 3rd May 2023, 21:18
Report here of some old PICs having been issued with 4 MHz max rating here:

https://www.embeddedrelated.com/showthread/piclist/2282-1.php


I checked, mine are all ...-20.

Demon
- 3rd May 2023, 22:42
Test 2, set all ports on 16F877 as output:


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

Ioannis
- 5th May 2023, 07:02
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

Demon
- 5th May 2023, 19:07
... 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

mpgmike
- 5th May 2023, 19:47
Test 2, set all ports on 16F877 as output:


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.

tumbleweed
- 5th May 2023, 20:57
On those old chips like the 16F877, OSC1 and OSC2 aren't part of PORTA.

Demon
- 5th May 2023, 21:35
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