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 support@ccsinfo.com

INT2 18F2331

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



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message

INT2 18F2331
PostPosted: Mon Jun 16, 2008 12:32 pm     Reply with quote

Hi,

In the code below, INT1 work, but INT2 not work,

anybode help-me ?

Orcino

Code:

#include <18F2331.h>
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV27                   //Brownout reset at 2.7V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOWINEN                  //WDT Timer Window Disabled
#FUSES T1LOWPOWER               //Timer1 low power operation when in sleep
#FUSES HPOL_HIGH                //High-Side Transistors Polarity is Active-High (PWM 1,3,5 and 7)
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPOL_HIGH                //Low-Side Transistors Polarity is Active-High (PWM 0,2,4 and 6
#FUSES PWMPIN                   //PWM outputs disabled upon Reset
#FUSES MCLR                     //Master Clear pin enabled

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#priority TIMER5,INT_EXT2,INT_EXT1


#ZERO_RAM

//******************************************************************************
//******************************************************************************


int16  RPM1=0,
       RPM2=0,
       RPM3=0,
       RPM4=0,
       TEMPERATURA=0,
       MEDIA_TEMP=0;
       
int8   ESTAGIO_1,       
       ESTAGIO_2,
       ESTAGIO_3;
       
//******************************************************************************
//
//******************************************************************************
#int_EXT2
void  EXT2_isr(void)
{
  ++RPM3;

}


//******************************************************************************
//
//******************************************************************************
#int_EXT1
void  EXT1_isr(void)
{
  ++RPM1;
}

//******************************************************************************
//
//******************************************************************************
#int_TIMER5
void  TIMER5_isr(void)
{

 RPM4=get_timer1();


}


//******************************************************************************
//
//******************************************************************************

void main()
{

   setup_adc_ports(sAN0|sAN1|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0|ADC_WHEN_INT0|ADC_INT_EVERY_OTHER);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   
   setup_power_pwm_pins(PWM_BOTH_ON,PWM_BOTH_ON,PWM_OFF,PWM_OFF);
   setup_power_pwm(PWM_CLOCK_DIV_64|PWM_FREE_RUN,1,0,200,0,1,0);

   //setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_4);
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_5(T5_INTERNAL|T5_DIV_BY_8); // 104 ms
   
   //enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT1);
   enable_interrupts(INT_EXT2);


   ext_int_edge( 2, L_TO_H);
   ext_int_edge( 1, L_TO_H);
 
   
   enable_interrupts(INT_TIMER5);
   enable_interrupts(GLOBAL);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 17, 2008 11:54 pm     Reply with quote

You need to think about why it doesn't work. It could fail if the voltage
level of the input signal was not high enough for a "logic high" level
as specified in the PIC data sheet. This voltage level (Vih) is given
in this section:
Quote:

25.3 DC Characteristics:
VIH Input High Voltage
with Schmitt Trigger buffer: 0.8 VDD minimum

If your Vdd voltage is +5v, the Vih minimum required level is 5v * .8
= 4.0v for the INT2 pin. You need to check the input signal with a scope.

Another reason for failure would be if the INT2 pin is not programmed
to be an input pin. You can look for this problem in the .LST file of
your program. You should always suspect the Wizard code. Most of
it is not needed, especially when it disables modules in the PIC.
These modules are disabled automatically when the PIC does a power-on
reset.

In the case of the Wizard code, this line causes a lot of problems:
Code:
setup_spi(SPI_SS_DISABLED); 


Here is the .LST file code for that line. Notice that it's doing many
things other than disabling the SSPEN bit. It's doing things to the TRIS
on Port C. This is where the problem is. It's making Pin C5 into an
output pin. That's why INT2 does not work.
Quote:
..... setup_spi(SPI_SS_DISABLED);
0016: BCF SSPCON.SSPEN
0018: BCF TRISC.7
001A: BSF TRISC.4
001C: BCF TRISC.5 // This makes Pin C5 be an output.
001E: MOVLW 01
0020: MOVWF SSPCON
0022: MOVLW 00
0024: MOVWF SSPSTAT

The solution is to delete that line of code.

And then, always be suspicious of the Wizard code. You don't normally
need code to disable the SPI module on power-up. It's disabled by
default when the PIC does a power-up.
Orcino



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message

PostPosted: Wed Jun 18, 2008 12:43 pm     Reply with quote

Very thanks

the line below was removed and WORKED.

Code:

  setup_spi(SPI_SS_DISABLED);


Orcino
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