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.

Need Help in Timer Interrupts, CCS C and PIC16F628A

Status
Not open for further replies.

glenjoy

Banned
Joined
Jan 1, 2004
Messages
962
Helped
72
Reputation
146
Reaction score
20
Trophy points
1,298
Location
Philippines
Activity points
0
ccs timer interrupt

I am making a speed measurement device.

Speed ranges from 250 fps to 800 fps, so timing is really critical.

I tried using this kind of loop but seems creates some kind of delay, attached is my original code.

Code:
include "C:\Documents and Settings\Glenjoy\My Documents\Chronograph 2\Chronograph.h"
#include <LCD.C>

long micro_S;
long milli_S;

long speed;

void main()
{



   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   lcd_init();
   setup_oscillator(False);

   speed = 0;

   set_tris_a(0x03);
 //  set_tris_b(0x00);

   output_b(0x00);

   lcd_putc("\f");
   lcd_putc("S: ");

   for(;;)
   {



      while(input(PIN_A0)==0);

      lcd_putc("\f");
      lcd_putc("S: ");


        do

         {
         delay_us(1);
         micro_S++;
         }while(!input(PIN_A1));

      speed = 328080/micro_S;

      milli_S = micro_S;

      micro_S = 0;


      printf(LCD_PUTC, "%Lu",speed);

   }
}

I need your help in editing this code by using interrupts, the code creates a delay in display of lcd.

Thanks.

Glenjoy
 

ccs timer

hi
i edited your code,and display on lcd perform in interrupt routin.
Code:
include "C:\Documents and Settings\Glenjoy\My Documents\Chronograph 2\Chronograph.h" 
#include <LCD.C> 

long micro_S; 
long milli_S; 

long speed; 

#int_rtcc
rtcc_isr()
{
printf(LCD_PUTC, "\f s:%Lu",speed);

}
void main() 
{ 



   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128); 
   setup_timer_1(T1_DISABLED); 
   setup_timer_2(T2_DISABLED,0,1); 
   setup_comparator(NC_NC_NC_NC); 
   enable_interrupts(int_rtcc);
   enable_interrupts(GLOBAL);
   setup_vref(FALSE); 
   lcd_init(); 
   setup_oscillator(False); 

   speed = 0; 

   set_tris_a(0x03); 
 //  set_tris_b(0x00); 

   output_b(0x00); 

   //lcd_putc("\f"); 
   //lcd_putc("S: "); 
   printf(lcd_putc,"\f s:");

   for(;;) 
   { 



      while(input(PIN_A0)==0); 

     // lcd_putc("\f"); 
      //lcd_putc("S: "); 


        do 

         { 
         delay_us(1); 
         micro_S++; 
         }while(!input(PIN_A1)); 

      speed = 328080/micro_S; 

      milli_S = micro_S; 

      micro_S = 0; 


      //printf(LCD_PUTC, "%Lu",speed); 

   } 
}
 

    glenjoy

    Points: 2
    Helpful Answer Positive Rating
ccs interrupt

Can we use interrupt routines to make counting of time more accurate?

Thanks.

Glenjoy
 

timer ccs c

yes you can.you can use timer 2 ,because it has more Reliability than other timer's in pic,it's similar to interrupt routin of timer0 .
 

interrupt ccs

first of all it is a mistake to put a IN/OUT trasnfer in an interrupt routine, because can couse to block the program flow.
The solution is to set a bit in interrupt routine and to clear in the main loop.
Another think, it is also a mistake to put an delay in the loop.
If you need to create an delay you need to use the timer, hardware independet from software.

unsigned char bit_set=0;
void ISR_timer0()
{
bit_set=1;
Acknolige interrupt;
}
void main(void)
{
Start_timer0();
while(1)
{
if (bit_set)
{
disable_interrupts();
//here IN/OUT transfer
enable_interrupts();
bit_set=0;
}
}
}
 

timer interrupts ccs

glenjoy said:
Can we use interrupt routines to make counting of time more accurate?
Sure, but too fast timer interrupt will bring heavy loading in execution.
Of course, to measure time by code delay could be very exact,
but use inline assembly for it code will be better to avoid some compiler dependent issues.

Since you chose the PIC16F628A, you can consider its CCP (Capture/Compare/PWM) module
to capture signal and measure time for more exact with a bit of loading.

FYR
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top