CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Trying to get the Ext INT working

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
raptorman



Joined: 08 Mar 2008
Posts: 12

View user's profile Send private message

Trying to get the Ext INT working
PostPosted: Tue Nov 17, 2009 7:13 pm     Reply with quote

Just trying to measure a positive going pulse of 1.5ms, 0v to 3.2v using the Ext Int on RB0. I get one INT on the rising edge and thats it. At first I could not get any INT until I set RB0 to an input. I'm using a 16F819 at 4mhz. I can make this work using the PortB input change, but like the idea of changing the rising and falling edge and using the Ext Int. I'm using the 16F819 for prototyping, but will be using the 16F676, so I cant use CCP. Any Ideas? Thanks.

Code:

#include <16F819.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=40000000)

#define PULSE PIN_B0

int16 pulse_width[15]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};   //global pulse width, reduce size after testing

#INT_EXT
void ext_isr(void)
{
   static int index = 0;
   
   output_high(PIN_A3);         //just for testing
   //if pulse is high than its the rising edge   
   if (input(PULSE)) {
      set_timer1(0);            //start the timer
      ext_int_edge( H_TO_L );   //setup for the falling edge         
   }
   else {
      output_low(PIN_A3);
      pulse_width[index] = get_timer1();
      ext_int_edge( L_TO_H );   //setup for the rising edge
      index = index + 1;
      if (index == 15)
         index = 0;      
   }
}//End of edge int ISR

void init(void) {
   set_tris_b(0b00000001);      //needs to be a input
   ext_int_edge( L_TO_H );      //setup for low to high pulse  1ms to 2ms duration
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_1); // Start timer 1 with 1us intervals   
}

void main()
{
   init();
   
   enable_interrupts(INT_EXT);   // Setup interrupt on falling edge
   enable_interrupts(GLOBAL);

   while(TRUE) {                  //Use for testing
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 17, 2009 8:32 pm     Reply with quote

Quote:
#include <16F819.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=40000000)

This PIC doesn't run at 40 MHz. Are you running this in real hardware
or in a simulator ? If a simulator, which one ? (Always tell us if you're
running real hardware or a simulator).

What's the Vdd voltage of your PIC ?

What's your compiler version ?
Guest








PostPosted: Tue Nov 17, 2009 9:40 pm     Reply with quote

No its running a crystal at 4mhz.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 17, 2009 9:42 pm     Reply with quote

The #use delay() statement must be the same as the oscillator frequency.

Also, please answer these questions:

1. Are you running this in real hardware or in a simulator ? If a simulator, which one ?

2. What's the Vdd voltage of your PIC ?

3. What's your compiler version ?
raptorman



Joined: 08 Mar 2008
Posts: 12

View user's profile Send private message

PostPosted: Tue Nov 17, 2009 9:44 pm     Reply with quote

No its running a crystal at 4Mhz, real hardware. Would that only effect my delay loops? 5 volts, V4.099.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 17, 2009 9:50 pm     Reply with quote

If you set the #use delay() statement at an incorrect value compared
to your oscillator frequency it will affect delay_ms(), delay_us(),
and all library code that uses delays or that configures hardware
modules that are dependent upon the oscillator frequency. It MUST be
correct.

Quote:

Just trying to measure a positive going pulse of 1.5ms, 0v to 3.2v

2. What's the Vdd voltage of your PIC ?
5 volts

The Device Overview section of the PIC data sheet says the Ext Int
pin is a "ST" input pin (Schmitt Trigger). The Electrical Specifications
section of the data sheet says a Schmitt Trigger pin requires a high level
voltage (Vih) = 0.8 x Vdd. With a Vdd of 5v, the Vih is 4v. Therefore
your input voltage of 3.2v is too low.
raptorman



Joined: 08 Mar 2008
Posts: 12

View user's profile Send private message

PostPosted: Tue Nov 17, 2009 10:36 pm     Reply with quote

Well that makes sense where the portb int worked and its ttl and not st like the ext int. Ran it at 4v and it works like a charm. I also changed it to 4mhz in the #use delay. Thanks for your help!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group