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.

PIC12F675 Timer1 flactuation problem

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Activity points
8,254
Hello everyone,
I was trying to generate a timing pulse which is related with INT hardware interrupt. Like Timer0, Timer1 is not mask-able. That is why here I'm using a variable to count per 0.25mS. And that counter is compared with preset value. When there is a hardware interrupt, the counter is reset to zero.

Normally it works in circuit. But problem is very small fluctuation in timing. How can I improve this fluctuation ?

Here is the Video:


















Code:

Code:
#define   Trigger     GP4_bit

void InitTimer1()
{
  T1CON         = 0x01;
  TMR1IF_bit = 0;
  TMR1H         = 0xFF;
  TMR1L         = 0x06;
  TMR1IE_bit = 1;
  INTCON = 0xC0;
}

bit trigger_mask;
int Trigger_cnt=0;
int Firing_cnt=0;

void Interrupt() iv 0x0004 ics ICS_AUTO
{
   if(INTF_bit)
   {
      INTF_bit=0;
      Trigger_cnt=0;
      Trigger = 0;
      trigger_mask=0;
      INTEDG_bit=~INTEDG_bit;
   }
  
   if (TMR1IF_bit)
   {
      TMR1IF_bit = 0;
      TMR1H         = 0xFF;
      TMR1L         = 0x06;
      Trigger_cnt++;
      
      if(Trigger_cnt>=Firing_cnt && !trigger_mask)
      {
         Trigger = 1;
         Delay_us(100);
         Trigger = 0;
         trigger_mask = 1;
      }

   }
}



void main()
{
  TRISIO=0b00001100;
  GPIO=0x00;
  ANSEL=0x00;
  ADCON0=0x00;
  CMCON=0x07;
 
  InitTimer1();
  GIE_bit = 1;
  PEIE_bit = 1;
  INTE_bit = 1;
  INTF_bit=0;
  INTEDG_bit=0;
 
  while(1)
  {

 
  }
}


Proteus file: Please check attachment.


MikroC file: Please check attachment.
--- Updated ---

Attachments. Proteus file and mikroC file.
 

Attachments

  • PIC12F675 Timer1 test.zip
    17.8 KB · Views: 128
  • Timer 1 test of PIC12F675.zip
    13.5 KB · Views: 75

hello,


it seems your FOSC is only 1Mhz
so any change inside other interrupt than TMR1 will affect the result of TMR1 counting
because add somme instruction

TMR1 count 240x 250µS to achive 1mS
if you miss one interrupt du to Int_F interrupt treatment
at leat you get 1mS +- any 250µS

put TMR1_IF at the top place into the interrupts treatment
or better is to increase FOSC to 8 or 16MHz

No real time at all .. it is an illusion
one step after one step ...

on other PIC18F you can choose High priority and low priority
it is better in some case , but never Perfect.
 

    Mithun_K_Das

    Points: 2
    Helpful Answer Positive Rating
OK. That is one kind of increasing resolution. But each time the INT is triggered, a little change is happening in TMR1 timing. Maybe increasing timer1 speed may result little better.
 

Putting a delay inside an ISR is always going to create problems.

I suggest two things:
1. put the TMR1 interrupt check first and the INT second, this will give priority to the timer.
2. Just set a bit/flag in the ISR, reset the timer then exit as soon as possible, move all the processing code inside the 'while()' loop.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top