|
|
View previous topic :: View next topic |
Author |
Message |
wei Guest
|
Problem using INT_EXT to measure pulse width |
Posted: Sat Dec 08, 2007 3:38 am |
|
|
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
|
|
Posted: Sat Dec 08, 2007 3:56 am |
|
|
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
|
|
Posted: Sat Dec 08, 2007 4:17 am |
|
|
Whoops sorry that was honestly a cut n paste error. I had INT_EXT, INT_EXT1 and INT_EXT2 enabled. |
|
|
Ttelmah Guest
|
|
Posted: Sat Dec 08, 2007 6:02 am |
|
|
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 |
|
|
|
|
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
|