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.

stopwatch between two pins

Status
Not open for further replies.

hobby_85

Junior Member level 2
Joined
Aug 17, 2009
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,586
Hey, I am trying to determine the time difference between two pins going HIGH. More specifically, Im using a PIC 16F690, and the two pins in question are PINC1 and PINC5.

Basically, PINC1 goes high, and a very short time later, PINC5 goes high. The time difference should be less than 0.5 seconds, maybe milliseconds .

Below is a code I have written, and it works to an extent. It captures C1 going high, but not C5. Ive checked the code several times, but if anyone can point me in the right direction, id appreciate it.

Im using a different compiler (CCS), but most commands should make sense.

Code:
#include <16F690.h>

#fuses INTRC, NOWDT, NOPROTECT, BROWNOUT, PUT 
#use delay(clock = 4000000)
#use rs232(baud=19200, xmit=PIN_B7, rcv=PIN_B5)

   int16 ctr;
   int16 ctr1;
   int tripped=0;
   int tripped1=0;
   int16 value=0;
 
 void main()
{

   
//my compiler sets the IO itself
 
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

         
   for(;;){                                        //forever
   
      contact_slave3();                 //After this, PINC1 should go high, followed closely by PINC5. This should happen about 500 micro seconds later. Can be changed to anything though.
   
      for (ctr=0;ctr<32000;ctr++) {     //Wait for PINC1 to go high until timeout
         if(input(PIN_C1)) {
            set_timer1(0);
            tripped=1;
            break;
         }
      }
                 
      while (tripped == 1 ){   //at this point, C1 went high, start timer and wait for C5 to go high
   
         for (ctr1=0;ctr1<64000;ctr1++) {     //Wait for PINC5 to go high until timeout
         
            if(input(PIN_C5)) {
             tripped1=1;//PINC1 went high, set ctr=0, break
             tripped=0;
               break;
            }
         
         }
         
         if (tripped1==1 && tripped == 0){
            
            value = get_timer0();
            printf("\r\nValue is: %Lu\r\n",value); 
            tripped=0;
            
         }else{
            printf("\r\nC5 didnt go high\r\n");
            tripped=0;
            tripped1=1;
         }
         
      }
      
       if (tripped==0 && tripped1==0){
       printf("\r\n C1 didnt go high\r\n");

       }
tripped1=0;
tripped=0;
delay_ms(2000);
blink_led();  //function to blink led  
   
 }   

}

ok, so when i run it, C1 goes high like it should, but i keep getting 'c5 didnt go high'. its doesnt even go into the if statement where it should blink the leds. but i know c5 goes high from the osc. I think it has something to do with the timing. I might either be capturing it too early or too late. but when i change the timeout loop to something higher than 64000, my compiler doesnt like it. i have no idea why. is there something about the clock/timer i need to know?

can anyone help me with this? thanks in advance

ps. I have posted something similar in another forum, so if anyone reads this twice, my apologize. Im trying my best to get this sorted out by tonight, so any any any help would be great.

if you need any other info, let me know

Thanks all.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top