View previous topic :: View next topic |
Author |
Message |
raptorman
Joined: 08 Mar 2008 Posts: 12
|
Trying to get the Ext INT working |
Posted: Tue Nov 17, 2009 7:13 pm |
|
|
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
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 17, 2009 8:32 pm |
|
|
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 ? |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Nov 17, 2009 9:40 pm |
|
|
No its running a crystal at 4mhz. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 17, 2009 9:42 pm |
|
|
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 ? |
|
![](templates/subSilver/images/spacer.gif) |
raptorman
Joined: 08 Mar 2008 Posts: 12
|
|
Posted: Tue Nov 17, 2009 9:44 pm |
|
|
No its running a crystal at 4Mhz, real hardware. Would that only effect my delay loops? 5 volts, V4.099. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 17, 2009 9:50 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
raptorman
Joined: 08 Mar 2008 Posts: 12
|
|
Posted: Tue Nov 17, 2009 10:36 pm |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
|