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.

[SOLVED] Timer1 in 16F1938 with wrong interrupt time

Status
Not open for further replies.

Rtk89

Newbie level 6
Joined
Nov 15, 2013
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
85
A would like to generate interrupts every 250ms with Timer1, but I get interrupts with more than 1 sec using the code below (I am writing it in MikroC PRO for PIC).
I set frequency to 8MHz with internal oscillator.
What is the problem?
Thank you for helping.

Code:
void InitTimer1(){
  T1CON	 = 0x31;
  TMR1IF_bit	 = 0;
  TMR1H	 = 0x0B;
  TMR1L	 = 0xDC;
  TMR1IE_bit	 = 1;
  INTCON	 = 0xC0;
}


void Interrupt(){
  if (TMR1IF_bit){
    TMR1H	 = 0x0B;
    TMR1L	 = 0xDC;
    PORTC.F0 = ~PORTC.F0;  
    TMR1IF_bit = 0;
  }
}


void main() {
TRISA = 1;
TRISB = 0;
TRISC = 0;

ANSELA = 0;
ANSELB = 1;

C1ON_bit = 0;      // Disable comparators
C2ON_bit = 0;
ADON_bit     = 1;  // ADC on
ADNREF_bit   = 0;  // -VREF = VSS
ADPREF0_bit  = 1;  //VREF+ is connected to internal Fixed Voltage Reference (FVR) module(1)
ADPREF1_bit  = 1;


ADC_Init();        // Initialize ADC module with default settings

InitTimer1();
  
do{

}while(1);
 

xenos

Full Member level 4
Joined
May 9, 2015
Messages
212
Helped
82
Reputation
164
Reaction score
81
Trophy points
28
Location
127.0.0.1
Activity points
1,182
This mC can run with INTOSC from 32KHz to 32MHz.
You have not configured OSCCON, so you run (by default) at 500KHz.
Try to add
Code:
OSCCON = 0x72; //OSC=1110 = 8MHz
during init of IC (before setting timer1).
 
  • Like
Reactions: Rtk89

    Rtk89

    Points: 2
    Helpful Answer Positive Rating

Rtk89

Newbie level 6
Joined
Nov 15, 2013
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
85
Thank you for your help. I will try it.
Otherwise, this screen in MikroC doesn't set the frequency of the mC ?

Névtelen.png
 

xenos

Full Member level 4
Joined
May 9, 2015
Messages
212
Helped
82
Reputation
164
Reaction score
81
Trophy points
28
Location
127.0.0.1
Activity points
1,182
No. This is just for the configuration word. It forces mC to use Internal Oscillator. But what frequency to use?
 
  • Like
Reactions: Rtk89

    Rtk89

    Points: 2
    Helpful Answer Positive Rating

Rtk89

Newbie level 6
Joined
Nov 15, 2013
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
85
I thought that I can set frequency with the "MCU Clock Frequency[MHz]" field in the right part of the window.
Thank you very much for helping.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top