Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Internal Clock and output frequency

chopnhack

New Member
Hello all, I am investigating the use of a PIC12F675 to produce various frequencies on one of its GPIO's. I am aware and have experimentally confirmed that the INTRCCLK will output a ~1MHz signal on pin 3. I wanted to see if I could get a range of frequencies by simply toggling a port on and off. I got some unusual results that I wanted to see if anyone knows why they would occur. It seems as if there is a ceiling of ~187KHz. Results are in the table below:
XTAL 40000001ms1.1KHz
0.1ms9.69KHz
0.01ms64.2KHz
0.001ms158KHz
XTAL 80000000.001ms136.8KHz
XTAL 10000000.01ms187KHz
XTAL 5000000.1ms58KHz
0.01ms158KHz
0.001ms187KHz

The code used is below, the define _XTAL_FREQ line was changed for each set of runs:

C:
// CONFIG
#pragma config FOSC = INTRCCLK  // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-Up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // GP3/MCLR pin function select (GP3/MCLR pin function is MCLR)
#pragma config BOREN = OFF      // Brown-out Detect Enable bit (BOD disabled)
#pragma config CP = OFF         // Code Protection bit (Program Memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)

#include <xc.h>

#define _XTAL_FREQ 500000

 void main (void)
 {
  // SET UP
  TRISIO = 0b000010;          //Only AN1 is a input all else are outputs.
    
  while(1){
      GPIO = 0b000000;        //Off 
      //__delay_ms(1);
      GPIO = 0b100000;        //GP5 On 
      __delay_ms(0.001);
  }

The scaling from 1ms to 0.1ms is nearly perfect with 4MHz intrcckl - 1 to almost 10KHz, but it seems to fall off from there. Any thoughts? Thank you all in advance.
 
There are ARM processors that have onchip 24 and 32 bit DDS's .....

What is range of Fout, resolution of Fout, accuracy of Fout do you need ?

Waveform you need output, just square of sine or .....?
 
Because you've got the overhead time spent looping (and calling subroutines), and this is more significant the higher you try and go. Better off using a hardware timer for such purposes, and the higher the clock speed the better.
Thank you for that idea Nigel! I will have a look at doing that in assembly this coming week.
 
There are ARM processors that have onchip 24 and 32 bit DDS's .....

What is range of Fout, resolution of Fout, accuracy of Fout do you need ?

Waveform you need output, just square of sine or .....?
Hi danadak, not sure yet - its all experimental. From some literature I read that between 5-150MHz is a more ideal range, but other literature has shown experiments done as low as 32KHz for Frequency Domain Reflectometry.

Since I have the 12F675 on hand, I wanted to try and use it with whatever frequencies I can create. I will need to be able to read changes in the frequency caused by changes in probe capacitance. I have not come across any information on whether this is better accomplished with square vs sine waves. I don't have a proper o-scope, just a cheapo DSO from which the measured waveform is quite erratic for lack of a better term. I have been using my DMM for getting frequency measurements. As for accuracy of Fout, this will depend I assume on how much frequency attenuation is exerted by the probe capacitance changes. I read that I can expect a range of 30pF in dry soil to between 200-400pF in wet soil.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top