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

Interrupt on A2 pin

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



Joined: 15 Sep 2003
Posts: 9

View user's profile Send private message

Interrupt on A2 pin
PostPosted: Fri Apr 16, 2021 5:13 am     Reply with quote

Hello,

CCS: PCWHD 5,084
PIC 16F15323

I have problem with IOC on A2 pin. Other pins (C0,C1,C2) works fine. Well except it is triggered on both edges.

Code:

#include <16F15323.h>

#fuses WDT_SW,  LVP, PROTECT

#device ADC=10
#use delay(internal=32M)

int16 lToken;

#define Timer1s 3036
#define LED_LIVE PIN_C5
#define OUT PIN_C4

void main(void)


   int16 lAdc;
   
   setup_oscillator(OSC_HFINTRC_32MHZ | OSC_HFINTRC_ENABLED);
 
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_adc_ports(sAN4 );     
   setup_wdt(WDT_ON | WDT_WINDOW_100_PERCENT | WDT_4S);
   
   setup_Timer_1( T1_INTERNAL | T1_DIV_BY_4 );
   enable_interrupts(INT_TIMER1);
   set_timer1(2840);
   
   set_adc_channel(4);
   int_count=INTS_PER_SECOND;
       
   restart_wdt();
 
   
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_IOC_C0 | INT_IOC_C1 | INT_IOC_C2 | INT_IOC_A2 );

.....


Code:

#INT_IOC
void  IOC_isr(void)
{
    if (interrupt_active(INT_IOC_C1_H2L)) //
    {
      clear_interrupt(INT_IOC_C1_H2L);
      lToken+=50;
   
    }
    if (interrupt_active(INT_IOC_C2_H2L)) //
    {
      clear_interrupt(INT_IOC_C2_H2L);
      lToken+=20;
   
    }
    if (interrupt_active(INT_IOC_A2_H2L)) //
    {
      clear_interrupt(INT_IOC_A2_H2L);
      lToken+=10;
      output_low(LED_LIVE);
   
    }
    if (interrupt_active(INT_IOC_C0_H2L)) //
    {
      clear_interrupt(INT_IOC_C0_H2L);
      lToken+=5;

   
    }
}


Hardware is ok because if I make test like
Code:

if (input(PIN_A2)==0)
  output_low(LED_LIVE);
else
  output_high(LED_LIVE);


it works fine.

I assume I missed some register settings.

Thanks for help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Interrupt on A2 pin
PostPosted: Fri Apr 16, 2021 1:10 pm     Reply with quote

Bieli wrote:

enable_interrupts(INT_IOC_C0 | INT_IOC_C1 | INT_IOC_C2 | INT_IOC_A2 );


Or'ing of parameters is not supported. You can get away with it
sometimes, if the pins are all on the same port. But you're mixing
ports, so in the statement above, there is a conflict.

The most correct way is to use four separate statements.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Fri Apr 16, 2021 11:55 pm     Reply with quote

Just to explain slightly further. A lot of the settings for a single setup,
can be or'ed. And the .h file then says that you can or these together. But
if you look at the enable_interrupt (and the other interrupt settings), there
is no mention here of using or. It is a common error to try to use or for
these, and as PCM says, in some cases this will work. However it is
not how you are meant to do it. Sad
Bieli



Joined: 15 Sep 2003
Posts: 9

View user's profile Send private message

PostPosted: Sat Apr 17, 2021 2:58 pm     Reply with quote

Hi,

You are right I have split and it work.

Thanks for help.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Apr 18, 2021 6:06 am     Reply with quote

The good thing about having individual enables (1 per statement or line), is that you can EASILY disable using the // . Also it quickly SHOWS you which is enabled or disabled. If it was just one long statement, it'd be real easy to delete 'ioc_c1 when you meant ioc_c2' and wonder WHY the program failed....

The older I get, the more I like easy to see stuff !

The same as 'expanding' a long 'math' statement into individual terms or smaller segments. Easier to check the 'math' to figure out why it doesn't work as expected.
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