Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

16F628A - internal clock precision? Or maybe the scope...

Status
Not open for further replies.

Garyl

Full Member level 5
Full Member level 5
Joined
Mar 28, 2017
Messages
253
Helped
6
Reputation
12
Reaction score
7
Trophy points
18
Visit site
Activity points
2,633
Hey.
I have setup my 16F628A with INTOSC and CLKOUT function:
Code:
//  Precision internal 4 MHz oscillator factory calibrated to ±1%
void main() {

  TRISA = 0;           // set direction to be output
  TRISB = 0;           // set direction to be output
            PCON.OSCF = 1;   // Set internal oscillator frequency to 4 MHz
           PCON = 0x08;
  do {
  PORTA = 0;
  PORTB = 0;
    Delay_ms(1000);    // 1 second delay
            PORTA = 0xff;
            PORTB = 0xff;
    Delay_ms(1000);    // 1 second delay
  } while(1);          // Endless loop
}

I have setup the circuit on the breadboard and added 100nF capacitor between VCC and VDD.
I have also setup "intosc + CLKOUT" config bit in mikroC PRO for PIC.

Now, I have measured the output waveform with the old analogue scope, and it shows a correct shape but period is 4.7 divs at 0.1uS time base, which means 0.47uS period, which is around 2.12MHz!
Even rounding to 5 divs - 0.5uS period gives 2MHz.

So now, my question is, am I mistaken with PIC configuration and it's infact generating the 2MHz square wave instead of 4MHz, or is there something wrong with my measurement?
 

CLKOUT option provides Fosc/4, so for internal 4MHz expect 1MHz on CLKOUT pin. (14.2.7 of the datasheet)

This equates to 1uS period, or 0.5uS low and 0.5uS high.
 

Also note that the program is high level source code, the actual code being executed will add extra delays which may be hard to predict. It would therefore not be reliable to use the port bits toggling as a method of measurement.

Hexreader correctly quotes 0.5uS low and 0.5uS high on the CLKOUT pin which would correspond with 4MHz system clock. It would be difficult to take an exact reading from an analog scope so I suspect the inaccuracy is in the scope rather than the PIC. I have a project using a 16F628A on my work bench at the moment so I'll temporarily configure it to produce CLKOUT and let you know exactly what it produces. I have accurate measurement equipment here! It's late at night here so I'll reply tomorrow.

Brian.
 

CLKOUT option provides Fosc/4, so for internal 4MHz expect 1MHz on CLKOUT pin. (14.2.7 of the datasheet)

This equates to 1uS period, or 0.5uS low and 0.5uS high.

Good point, but it still does not explain the 100% measurement error. (now 2MHz instead of 1MHz).. I will try again tomorrow, and recheck everything.


Also note that the program is high level source code, the actual code being executed will add extra delays which may be hard to predict. It would therefore not be reliable to use the port bits toggling as a method of measurement.
Are you sure that CLKOUT output has anything to do with the code executed in the main loop?

Hexreader correctly quotes 0.5uS low and 0.5uS high on the CLKOUT pin which would correspond with 4MHz system clock. It would be difficult to take an exact reading from an analog scope so I suspect the inaccuracy is in the scope rather than the PIC. I have a project using a 16F628A on my work bench at the moment so I'll temporarily configure it to produce CLKOUT and let you know exactly what it produces. I have accurate measurement equipment here! It's late at night here so I'll reply tomorrow.
I've never had so much big measurement error with that scope, I am using 10x probe



EDIT: Okay, now it seems that 1MHz output is the correct one. So hexreader answer explained everything. I was relying too much on the intuition that "CLKOUT" means "clock frequency out". Thanks!
 
Last edited:

This is what my 628A is showing on CLKOUT. It is a well used PIC date coded 2009 running from 5.05V VDD at 19C.

628ACLKOUT.png

The frequency implies 3.994MHz internal clock which is an error of only about 0.57%
There is quite a lot of jitter on the clock, hence the high deviation figure which is quite noticeable if I beat CLKOUT against my local AM radio station on 990KHz but it confirms the central frequency is accurate.

The program doesn't change CLKOUT but using it as a way of assessing the speed is unreliable of course.

Brian.
 
  • Like
Reactions: Garyl

    Garyl

    Points: 2
    Helpful Answer Positive Rating
Check out Table 17-5 in the data sheet for the precision of the internal oscillator and also Figure 17-5 (just below it) for the relationship between the oscillator and CLKOUT.
Susan
 
  • Like
Reactions: Garyl

    Garyl

    Points: 2
    Helpful Answer Positive Rating
This is what my 628A is showing on CLKOUT. It is a well used PIC date coded 2009 running from 5.05V VDD at 19C.

View attachment 143075

The frequency implies 3.994MHz internal clock which is an error of only about 0.57%
There is quite a lot of jitter on the clock, hence the high deviation figure which is quite noticeable if I beat CLKOUT against my local AM radio station on 990KHz but it confirms the central frequency is accurate.

The program doesn't change CLKOUT but using it as a way of assessing the speed is unreliable of course.

Brian.

Thx, just out of curiousity, can you check how much this frequency can be pulled by adding capacitance to this pin?
 

I tried it and as expected, there was absolutely no change in frequency when a 2.2nF capacitor was connected from CLKOUT to VSS.
The CLKOUT signal must pass through some digital buffering to allow the pin can be reassigned as I/O so in internal oscillator mode it isn't directly connected to the oscillator circuit.

The overshoot in the picture is caused by the wiring to an LCD module by the way, it isn't coming out of the PIC. in normal operation, that pin is driving the 'E' pin on the LCD module and I left it connected for the test.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top