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

external interrupt as an input source

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



Joined: 02 Mar 2006
Posts: 11

View user's profile Send private message

external interrupt as an input source
PostPosted: Sun Jun 11, 2006 1:50 pm     Reply with quote

Hi, I am trying to measure a pusewidth with an interrupts service because I need it.
I am displaying an led`s display and when the interrupt arrives the PIC refesh the display with the new value.
All the information cames by a serial wire direct to the B0 pin, the external interrupt pin. Can I use this pin also as an input pin, to measure the pusewidth of the serial information?

The code is something like this... I am working with this an it doesnt work.
I dont know if it's possible to use the PIN B0(external interrupt) as an input pin inside of the interrupt routine.
Code:

#int_EXT
EXT_isr() {         

x=input(PIN_B0);
   for (i=0;i<50;i++)
      {
         if (x==1) pulsewidth++;
      }
}



void main() {
   
   enable_interrupts(INT_EXT);
   enable_interrupts(global);
   etc...



Thanks...
Ttelmah
Guest







PostPosted: Sun Jun 11, 2006 4:04 pm     Reply with quote

Yes, you can read the pin in the interrupt.
What you show, will not as far as I can see, have any relationship to the input pulse width, since you read the input just once at the start of the interrupt, and then increment (or not) the pulsewidth value fifty times, based on this single reading...

Best Wishes
SuMa



Joined: 02 Mar 2006
Posts: 11

View user's profile Send private message

PostPosted: Mon Jun 12, 2006 12:52 am     Reply with quote

Thanks Ttelmah

The correct code will be something like this:
Code:

#int_EXT  //external interrupt on PIN B0
EXT_isr() {         


   for (i=0;i<50;i++)    //cheking the pulsewidth of the serial data on B0
      {
         x=input(PIN_B0);
         if (x==1) pulsewidth++;
      }
}



void main() {
   
   enable_interrupts(INT_EXT);
   enable_interrupts(global);
   etc...

I am trying to make it works but I dont get it, I dont know why...
Ttelmah
Guest







PostPosted: Mon Jun 12, 2006 2:26 am     Reply with quote

It is important perhaps to understand the timings involved.
It takes about 30 instruction times (depends on the PIC), to actually arrive in the handler. Then your 'loop', will take perhaps 10 instruction times, and another couple if the signal if high. So the 'effect', will be to ignore the first perhaps 35 instruction times of the pulse width, and then during the next 500 instruction times, if it is high at any point when tested, pulsewidth will increment, otherwise it will stay the same.
So, repeated pulses will still give the same increment of the count, and the first few uSec (depending on your clock rate), will be ignored.
I'd perhaps suggest:
Code:

#int_EXT
void EXT_isr(void) {
    int i=0; //you do not show the declaration of this. Try to keep things
    //That are only used locally, 'local', not global.
    //PulseWidth, is presumably a 'global' variable. It needs to be zeroed,
    //Or it'll just get larger every time.
    pulsewidth=0;
    while (input(PIN_B0) {
        pulsewidth++;
        if (++i==50) break;
    }
}

This will still ignore the first few uSec, since this is an unavoidable implication of using interrupts. If you want accurate timing in this part of the pulse, external hardware will be needed.
However, this stops counting, as soon as the pulse drops, or when a maximum of 50 counts have occurred. Note that you don't need to add a seperate variable, and then test this, to test the pin.

Best Wishes
SuMa



Joined: 02 Mar 2006
Posts: 11

View user's profile Send private message

PostPosted: Mon Jun 12, 2006 7:56 am     Reply with quote

Thanks Ttelmah, I will try it this evening...
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