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 CCS Technical Support

Troubles configuring pins and INT_EXT

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



Joined: 04 Feb 2014
Posts: 26

View user's profile Send private message

Troubles configuring pins and INT_EXT
PostPosted: Fri Jun 13, 2014 6:13 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 13, 2014 6:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 13, 2014 8:54 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 16, 2014 1:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 12:16 am     Reply with quote

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 ;)
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