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

Input Capture Problem with pic24FJ128FB110

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



Joined: 03 Dec 2016
Posts: 3

View user's profile Send private message

Input Capture Problem with pic24FJ128FB110
PostPosted: Sat Dec 03, 2016 3:06 am     Reply with quote

Hi Everyone, I have a problem with pic24FJ128GB110 on Input capture interrupt(INT_ICx). I want to use this function to measure the period of PWM.
So, I have set following EX_PinSelect2.c by using Input Capture channel 5 (IC5) but when I inject a pulse to IC5 Pin the controller not jump to #INT_IC5 loop.

Is it correct? If it not correct how can I do?

This is my code.
Code:
#include <24FJ128GB110.h>
#fuses HS,NOWDT,NOPROTECT,PR
#use delay(clock=8000000)

#pin_select U1TX=PIN_B2
#pin_select U1RX=PIN_E9

#pin_select INT1 = PIN_B0   // Setup External Interrupt INT_EXT1
#pin_select IC5 =  PIN_C1  // setup Input Capture  INT_IC4

#use rs232(baud=9600, UART1)


#INT_EXT1
void external_interrupt1(void)
{
   printf("\n\r EXT1 Trigger");
}


#INT_IC5
void Input_Capture1(void)
{
   printf("\n\r IC5 Trigger");
}
void main()
{

   printf("\n\rRESET");
   // Following setup required for Input Capture
   setup_timer2(TMR_INTERNAL|TMR_DIV_BY_1);    // Start timer 2
   setup_capture(5,CAPTURE_EE|CAPTURE_TIMER2);   
   
   enable_interrupts(INT_EXT1);
   enable_interrupts(INT_IC5);
   enable_interrupts(INTR_GLOBAL);
   
    while(1)
    {
    delay_ms(1000);
    }
}


Thank you.
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Sat Dec 03, 2016 4:21 am     Reply with quote

There are a few little 'bewares' in what you have posted:

1) When using the hardware UART, you should always have 'ERRORS' in the #USE RS232, unless you are adding your own error handler code. CCS (unfortunately) don't do this in a lot of their examples....
2) On a PIC24, 8MHz, requires the XT oscillator, not HS. You'll probably be over-driving the oscillator a bit. Minimum for HS is 10Mhz. Same comment applies here about the CCS example!....

However none of these should prevent the test working.
What is your compiler version?. (You should _always_ tell us this, for any problem like this, since we can then compile the code and see if the compiler is setting the registers correctly).
Does INT_EXT1 work correctly?.

How old is your chip?. Devrev?.
There was an issue in the first release chips with input capture. 2008 erratum sheet.
How are you testing this?.
MPLAB SIM has an issue with these chips on some versions and some capture channels.

Tell us the compiler version, and we can then have a look at the code being generated and see if the compiler is doing something wrong.
temtronic



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

View user's profile Send private message

PostPosted: Sat Dec 03, 2016 6:37 am     Reply with quote

query...

is this...

enable_interrupts(INTR_GLOBAL);

correct ?

I don't use that PIC, so curious as to the syntax...

enable_interrupts(GLOBAL);

is what I've always used .

Jay
siripot12



Joined: 03 Dec 2016
Posts: 3

View user's profile Send private message

PostPosted: Sat Dec 03, 2016 7:11 am     Reply with quote

Ttelmah wrote:
There are a few little 'bewares' in what you have posted:

1) When using the hardware UART, you should always have 'ERRORS' in the #USE RS232, unless you are adding your own error handler code. CCS (unfortunately) don't do this in a lot of their examples....
2) On a PIC24, 8MHz, requires the XT oscillator, not HS. You'll probably be over-driving the oscillator a bit. Minimum for HS is 10Mhz. Same comment applies here about the CCS example!....

However none of these should prevent the test working.
What is your compiler version?. (You should _always_ tell us this, for any problem like this, since we can then compile the code and see if the compiler is setting the registers correctly).
Does INT_EXT1 work correctly?.

How old is your chip?. Devrev?.
There was an issue in the first release chips with input capture. 2008 erratum sheet.
How are you testing this?.
MPLAB SIM has an issue with these chips on some versions and some capture channels.

Tell us the compiler version, and we can then have a look at the code being generated and see if the compiler is doing something wrong.


Thank you for your reply.
-I have tried to change from HS to XT but it still not working.
-And the code that I posted for INT_EXT1 working properly but only input compare not working.
-And for the old of the chip I don't know for exact old because I bought from the shop 2 week ago.

my code is complied on CCS version 4.104.
siripot12



Joined: 03 Dec 2016
Posts: 3

View user's profile Send private message

PostPosted: Sat Dec 03, 2016 7:16 am     Reply with quote

temtronic wrote:
query...

is this...

enable_interrupts(INTR_GLOBAL);

correct ?

I don't use that PIC, so curious as to the syntax...

enable_interrupts(GLOBAL);

is what I've always used .

Jay


I think enable_interrupts(INTR_GLOBAL) already correct because in my header file of "24FJ128GB110.h" don't have "GLOBAL". Thank for your reply ^_^. I'm waiting for help T_T
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Sat Dec 03, 2016 7:41 am     Reply with quote

temtronic wrote:
query...

is this...

enable_interrupts(INTR_GLOBAL);

correct ?

I don't use that PIC, so curious as to the syntax...

enable_interrupts(GLOBAL);

is what I've always used .

Jay


INTR_GLOBAL, is really 'more correct'. The comment again 'GLOBAL' on PIC24's, says 'for reverse compatibility only'....

Ouch. Do you really mean 4.104!....

I'd suspect the #pin select might well not work right for anything but the most basic pins on a compiler this old.

Will try and see.
temtronic



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

View user's profile Send private message

PostPosted: Sat Dec 03, 2016 9:33 am     Reply with quote

It was the 'R' that caught my eye...

Seems all the other INTerrupt syntax is INT_xxx, so from a 'syntax' or 'visual' perspective, I'd have thought INT_GLOBAL would have been better ?

But it boils down to what's in the header that the compiler wants....

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Sat Dec 03, 2016 12:56 pm     Reply with quote

The standard 'level enables' for a PIC 24, are:
Code:

#define INTR_GLOBAL               0x400
#define INTR_NORMAL               0x100
#define INTR_ALTERNATE            0x200
#define INTR_LEVEL0               0x500
#define INTR_LEVEL1               0x501
#define INTR_LEVEL2               0x502
#define INTR_LEVEL3               0x503
#define INTR_LEVEL4               0x504
#define INTR_LEVEL5               0x505
#define INTR_LEVEL6               0x506
#define INTR_LEVEL7               0x507


The V5 compilers then add:

#define INT_GLOBAL INTR_GLOBAL //for reverse compatibility

On the V4 compilers, you always had to use INTR_GLOBAL for the global enable.

Anyway that is not the problem. I'd suspect the compiler version is.
I don't think that the #pin_select was fully working till about V5.020. Even more recently than that, there were problems on some chips with some interrupts.
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