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

Problem using INT_EXT to measure pulse width

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







Problem using INT_EXT to measure pulse width
PostPosted: Sat Dec 08, 2007 3:38 am     Reply with quote

Hi, I am making this motor driver that reads pulse widths from a futaba receiver that generates servo pulses. Thus, i need to measure the pulse width and then generate PWM with the appropriate duty cycle. However, I cannot measure the pulse width of the servo pulses using the INT_EXT interrupt handler.

Here's part of the code:
Code:

#define HTOL 0
#define LTOH 1

int1 ext0intedge;

void init()
{
   ext_int_edge(0,L_TO_H);
   ext0intedge = LTOH;
   enable_interrupts(INT_EXT2);
   enable_interrupts(GLOBAL);
}

#INT_EXT
void ext0_isr()
{
   if (ext0intedge == LTOH)
   {
      ext0start = get_timer3();
      ext_int_edge(0,H_TO_L);
      ext0intedge = HTOL;
   }
   else
   {
      ext0stop = get_timer3();
      if(ext0start < ext0stop)
         ext0hightime = ext0stop - ext0start;
      else
         ext0hightime = (65535 - ext0start) + ext0stop;
      ext_int_edge(0,L_TO_H);
      ext0intedge = LTOH;
   }
   printf("INT!\r\n");
}


The problem is that, ext0_isr() is only called once, and I only see one "INT!" in hyperterminal. I verified with a oscilloscope and there were standard servo pulses. I am using PIC18F452. Any ideas? Thanks
Ttelmah
Guest







PostPosted: Sat Dec 08, 2007 3:56 am     Reply with quote

Er.
You are enabling INT_EXT2 (note the 2.....), but have a handler for INT_EXT (no 2). These are not the same....
These are on different pins (RB2, and RB0), and use different handlers. Which are you actually using.
I'm suprised the code even gets called...

Best Wishes
wei
Guest







PostPosted: Sat Dec 08, 2007 4:17 am     Reply with quote

Whoops sorry that was honestly a cut n paste error. I had INT_EXT, INT_EXT1 and INT_EXT2 enabled.
Ttelmah
Guest







PostPosted: Sat Dec 08, 2007 6:02 am     Reply with quote

Obvious comments then apply. The print takes a lot of time, and implies that interrupts will be disabled in external print code. Probably longer than the time between pulses. Better not to use this. The variables are presumably declared as int16 or long types?. You really should get multiple interrupts, but I'd suspect something outside is getting hung up because of the time in the routine (query serial receive handling?. - with the time in the interrupt, if serial data is received, the UART will go into an error state).
Are you sure you are seeing just one line?. Though /n, should move you to the next lne, in some configuration modes, hyperterminal will not respond to this if it is the wrong 'side' of the /r. So in these modes, /n/r, behaves differently, from /r/n, and one way round, won't result in a line feed....

Best Wishes
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