|
|
View previous topic :: View next topic |
Author |
Message |
coderchick
Joined: 12 Jun 2008 Posts: 25
|
|
Posted: Mon Nov 03, 2008 1:56 pm |
|
|
alright, so the fuses were something I hadn't modified yet, so now that those are in place, most everything seems to be working...but now i'm having issues with my external interrupt. it's pretty much the same thing as before, whether the pin is high or low the debugger acts as if the interrupt was triggered, even if it wasn't. According to my multimeter and the debuggers peripheral i/o port window, the line is high, yet the interrupt is triggered as if the line was pulled low. everything else seems to be working fine _________________ KMoe
~We the willing, led by the unknowing, are doing the impossible for the ungrateful. We have done so much, for so long, with so little. We are now qualified to do anything with nothing -M. Theresa |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 03, 2008 2:05 pm |
|
|
1. Post a short program that demonstrates the problem. The program
must be compilable with no errors. The entire program should fill no
more than one screen on your monitor. (We don't want to look at a lot of
code). The program must have the #include, #fuses, #use delay(), etc.,
and a main().
2. Describe in detail the external circuit that is connected to the INT_EXT
pin. Give component values. |
|
|
coderchick
Joined: 12 Jun 2008 Posts: 25
|
|
Posted: Mon Nov 03, 2008 7:29 pm |
|
|
below is my code, what it does is (at least this portion) is to flash between a red and green LED and sound a buzzer upon start up. after the start up count down is over, it's supposed to leave the LED green until it detects a leak which it again flashes the LEDs and sounds the buzzer. The way I have the interrupt configured is to trigger when the line goes low ( ext_int_edge(H_TO_L);). According to both my multimeter (reads 4.60V) and the debuggers I/O port Perieral window (reads a 1 for B0), the LED should remain green and the buzzer silent, but the system flashes and sounds off.
The circuit for the external interrupt is very simple, it's just a 10K ohm resistor between Vdd and B0. to trigger the interrupt is to short B0 to ground, but I haven't even been able to test that part yet because the whole thing is going off when the line is high.
very frustrating
Code: |
#include <16F887.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PUT //Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV40 //Brownout reset at 4.0V
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
short int leak_alert = FALSE;
int flash_counter = 0;
int start_up = 7;
#int_EXT
void EXT_isr(void)
{
leak_alert = TRUE;
enable_interrupts(INT_TIMER0);
}
#int_TIMER0
void TIMER0_isr(void)
{
if (leak_alert || start_up > 0)
{
if (flash_counter == 0 && start_up != 0)
{
start_up--;
}
flash_counter++;
}
else
{
disable_interrupts(INT_TIMER0);
}
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); //~65ms
setup_timer_2(T2_DIV_BY_16,255,1);
enable_interrupts(INT_EXT);
ext_int_edge(H_TO_L);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while (TRUE)
{
if (leak_alert || start_up != 0)
{
if (flash_counter > 0 && flash_counter <= 2)//flash green at start up and on leak detection
{
output_low(PIN_B2); //red off
output_high(PIN_B1); //green on
setup_ccp1(CCP_PWM_H_H); //buzzer pins high
set_pwm1_duty(128-77);
setup_ccp2(CCP_PWM);
set_pwm2_duty(77);
}
else if (flash_counter <= 4) //flash red
{
output_low(PIN_B1); //green off
output_high(PIN_B2); //red on
setup_ccp1(CCP_OFF); //buzzer pins low
setup_ccp2(CCP_OFF);
}
else if (flash_counter > 4)
{
flash_counter = 0;
}
}
else //for all other reasons be green
{
output_low(PIN_B2); //red off
output_high(PIN_B1);//green on
}
}
} |
_________________ KMoe
~We the willing, led by the unknowing, are doing the impossible for the ungrateful. We have done so much, for so long, with so little. We are now qualified to do anything with nothing -M. Theresa |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 03, 2008 11:05 pm |
|
|
Make a test program that tests only the External interrupt. Get rid of 90%
of your code. Prove that you can make the External interrupt work
before doing anything else. Make a program that will toggle an LED
on or off every time you get an external interrupt. |
|
|
coderchick
Joined: 12 Jun 2008 Posts: 25
|
|
Posted: Tue Nov 04, 2008 12:00 pm |
|
|
Here is a simpler version. if the interrupt is triggered, LED is red, otherwise LED is green (instead of off). The LED turns red right off the bat. according to the watch windows, the leak_alert is flagged as true which only happens when the interrupt is triggered and pulled low, however, the multimeter and peripheral window says that pin is high, so what could possibly be going wrong? I don't know if the code can get any more simple than this....?
Code: |
#include <16F887.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PUT //Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV40 //Brownout reset at 4.0V
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
short int leak_alert = FALSE;
#int_EXT
void EXT_isr(void)
{
leak_alert = TRUE;
}
void main()
{
enable_interrupts(INT_EXT);
ext_int_edge(H_TO_L);
enable_interrupts(GLOBAL);
while (TRUE)
{
if (leak_alert) //when ext int is triggered turn led red
{
output_low(PIN_B1); //green off
output_high(PIN_B2); //red on
}
else //otherwise be green
{
output_low(PIN_B2); //red off
output_high(PIN_B1);//green on
}
}
} |
_________________ KMoe
~We the willing, led by the unknowing, are doing the impossible for the ungrateful. We have done so much, for so long, with so little. We are now qualified to do anything with nothing -M. Theresa |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Tue Nov 04, 2008 1:02 pm |
|
|
On the 16F887, PORTA and some of PORTB default at power up as ADC inputs.
setup_adc_ports(NO_ANALOGS); _________________ David |
|
|
coderchick
Joined: 12 Jun 2008 Posts: 25
|
|
Posted: Tue Nov 04, 2008 1:16 pm |
|
|
Thanks all, I added a clear_interrupt(INT_EXT) in the main start up...
Code: |
enable_interrupts(INT_EXT);
ext_int_edge(H_TO_L);
clear_interrupt(INT_EXT);
enable_interrupts(GLOBAL);
|
and that seems to have worked. I'll try the setup_adc_ports() as well, but in the larger portion of my code I have A0 set up as an ADC, so I don't know if setting it to NO_ANALOGS will have fixed the issue or not.
Thanks again to everyone, hopefully everything will go smoothly from here on out. _________________ KMoe
~We the willing, led by the unknowing, are doing the impossible for the ungrateful. We have done so much, for so long, with so little. We are now qualified to do anything with nothing -M. Theresa |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 04, 2008 1:30 pm |
|
|
Quote: | On the 16F887, PORTA and some of PORTB default at power up as ADC inputs. |
That's true, but CCS puts in initialization code to configure those pins as
digital pins. This is sort of an un-written standard for CCS. Here's the
code for a 16F887 for vs. 4.081:
Code: |
... void main()
... {
0038: CLRF FSR
0039: BCF STATUS.IRP
003A: MOVLW 1F
003B: ANDWF STATUS,F
003C: BSF STATUS.RP0
003D: BSF STATUS.RP1
003E: MOVF ANSELH,W
003F: ANDLW C0
0040: MOVWF ANSELH // Set AN8-13 as digital i/o pins
0041: BCF STATUS.RP1
0042: BCF ADCON1.VCFG0 // Disable Vcfg
0043: BCF ADCON1.VCFG1
0044: MOVLW 00
0045: BSF STATUS.RP1
0046: MOVWF ANSEL // Set AN0-7 as digital i/o pins
0047: BCF STATUS.RP0
0048: CLRF CM1CON0 // Disable comparators
0049: CLRF CM2CON0
004A: CLRF CM2CON1
|
|
|
|
|
|
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
|