Thursday, October 8, 2020

Accessing the internal 8 MHz oscillator of PIC16F887 in MikroC

Overview Of The Internal Oscillator of PIC16F887

One of the extended features of PIC16F887 over the previous PIC16F887A is the internal calibrated RC oscillator. Using this internal oscillator, the clocking module inside works statically, mostly prevented from the noisy environment creates by the external RF signal. 

Furthermore, there're many options with internal clock. The external clock pins - RA6 and RA7 could be selected as a digital input output pin when the MCU clock is configured as internal oscillator with digital I/O.

The internal oscillator is divided into two blocks - LFINTOSC and HFINTOSC. The LFINTOSC in a lower frequency clock below 31 kHz. The HFINTOSC is a higher frequency ranges from 125 kHz to 8 MHz.

The internal clock setup must be done in the configuration bits and the OSCCON register. Another register OSCTUNE give a steady tuning to any frequency while the program is running, without any interruption.

PIC MCU clock source block diagram

In MikroC the configuration of the MCU must be done in the MCU property window. In this IDE press Shift + Ctrl + E to get this window.


The OSCTUNE (Oscillator Tuning Register) 

The OSCCON (Oscillator Controller Register)


Programming in MikroC

In this example, I use the internal oscillator to clock the CPU up to 8 MHz. PORTA displays a shifting data repeatedly.

Accessing the internal 8 MHz oscillator of PIC16F887 in MikroC
Schematic Diagram

The C source code in MikroC setup the internal oscillator one-by-on.

  1. void main() {
  2. char LED;
  3. PORTA=0x00; // CLEAR ALL PORTA
  4. TRISA=0x00; // ALL PORTA AS OUTPUT
  5. OSCCON.IRCF0=1; // Set IRCF=0b111
  6. OSCCON.IRCF1=1; // to select 8MHz
  7. OSCCON.IRCF2=1;
  8. while(1)
  9. {
  10. LED=0x01;
  11. while(LED!=0x00) {
  12. PORTA=LED;
  13. delay_ms(100);
  14. LED<<=1;
  15. }
  16. }
  17. }

2 comments:

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)