|
|
View previous topic :: View next topic |
Author |
Message |
LiLou
Joined: 04 Feb 2014 Posts: 26
|
Troubles configuring pins and INT_EXT |
Posted: Fri Jun 13, 2014 6:13 am |
|
|
Hi,
I want to use an INT_EXT with an 18F44K22.
Code: | void main()
{
enable_interrupts(INT_EXT_L2H); //interruption triggers when the pin goes from LOW to HIGH
enable_interrupts(INT_EXT2_L2H);
//more config
setup_adc(adc_clock_internal);
setup_adc_ports(san0|san1|san3);
enable_interrupts(int_rda);
enable_interrupts(global);
//...
set_tris_a(...);
set_tris_b(0b00000101); //setting pins B0 and B2 as inputs. These are the pins of the INT_EXT
set_tris_c(...);
set_tris_d(...);
set_tris_e(...);
output_a(0);
output_b(0);
output_c(0);
output_d(0);
output_e(0);
//...
}
|
header file
Code: |
#include <18f44k22.h>
#device adc=10
//fuses...
#use delay(internal=4Mhz)
#use rs232( baud = 9600, parity = N, xmit = PIN_C6, rcv = PIN_C7, bits = 8 )
#use fast_io(ALL)
//PORTB
#bit PB0 = 0xf81.0 //a fast way to access them, just checking if they are 0 or 1 (LOW/HIGH)
#bit PB2 = 0xf81.2
|
interruption functions
Code: |
#INT_EXT
void PB0_isr()
{
if(PB2==0) //problem: it's never true
{
//TODO
}
}
#INT_EXT2
void PB2_isr()
{
//similar to PB0_isr()
} |
So I want to do something when PB0 is high and PB2 is low (and vice versa), but when I do PB2==0, it's always false, I checked the value of PB2 with ISIS and it shows me strange numbers, not 0 or 1, what I'm expecting. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Jun 13, 2014 6:49 am |
|
|
some things to consider....
First, you'll have to wire up a REAL PIC onto a breadboard or PCB
Then, confirm it physically works using the classic '1Hz LED' program.
Then, code for your ISR.
You should know that ISIS is FULL of bugs,errors and faulty DRC and should NOT be used for 'simulating' PICs.
no one here has the time or inclination to fix or repair ISIS !
also
you do NOT need to use fast_io() or tris() for your projects. If you miscode, your PIC will NOT run as expected. let the compiler do it for you(properly !)
also
when using rs232(...), add 'errors' to the options.it will prevent the PICs hardware UART from 'hanging'.
also
it's best to clear any interrupt before enabling it...chicken/egg situation
also
you should post your entire program as written NOT code 'snippets' so others can copy/paste/test.
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Jun 13, 2014 8:54 am |
|
|
and as a general comment, why do people never read the data sheet about 'ADC_CLOCK_INTERNAL'?.
Is your device running faster than 1MHz?.
If so, this note from the data sheet applies:
"When the device frequency is greater than 1 MHz, the FRC clock source is only recommended if the conversion will be performed during Sleep."
Are you performing the conversion during sleep?.
Then you show INT_RDA enabled, but don't show a handler for this.
Having an interrupt enabled without a handler, will hang the chip. |
|
|
ftrax
Joined: 24 Sep 2013 Posts: 22 Location: EspaƱa
|
|
Posted: Mon Jun 16, 2014 1:42 am |
|
|
Hi LiLou,
As temtronic says, ISIS is full of bugs (like CCS...), but if you know this bugs and you learn how to work with ISIS properly, this might be a useful tool to test your projects. Although you can't visualize the value of PB2 as a variable because its a bit from a memory direction. You must visualize the byte and see if the bit.0 and bit.2 change between 0-1.
If you want a better help, you must give us more information about your code in order to know what you want to do. |
|
|
LiLou
Joined: 04 Feb 2014 Posts: 26
|
|
Posted: Wed Jun 18, 2014 12:16 am |
|
|
Hi,
1. The trouble was that my program logic was upside down (PB0_isr <-> PB2_isr)
2. Configuration of pins was fine, and yes, to check the value of a #bit in ISIS, I must check the entire byte where is located.
Thx ftrax ;) |
|
|
|
|
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
|