Measuring Pulse width of PPM signal

Help with any software/desktop related issues. e.g. companion9x, eePe, etc
Post Reply
Rahul
Posts: 3
Joined: Tue Jun 05, 2012 2:52 pm
Country: -

Measuring Pulse width of PPM signal

Post by Rahul »

hello all,



I have a code whic i think everything is ok but while compiling it gives many errors...can any one help me to debug it. I have this for measurinf pulse width of PPM signal received by 8 channel receiver.




Code: Select all

# define PPM_Number_of_Channels 8
int failSafePulses = 0;
int PPM_IN[input+1];                // Pulse Width of input signal
unsigned int rise[input+1] ; //rising edge clock
unsigned char ch; //PPM channel counter
unsigned int fall; // Record PPM fall time
Boolean framok; // Are all measurement ok
 
#define PPM_FAILSAFE_INPUT_MIN 1500
#define PPM_ADJUST 1000
 
void capture_int(void)
 
{
T2CON = 0b1000000000000000  ; // turn on timer 2 with no prescaler
TRISD = 0b1111111111111111 ; // make the d port input, to enable IC1 and IC2
TRISFbits.TRISF6 = 1 ; // make F6 an input to enable the 3rd switch
IC1CON = IC2CON = IC7CON = IC8CON = 0b0010000010000001 ; //IMC<2:0> = 001 (Capture every rising and falling edge)
 
IPC0bits.IC1IP = IPC1bits.IC2IP = IPC4bits.IC7IP = IPC4bits.IC8IP = 6 ; // priority 6
IFS0bits.IC1IF = IFS0bits.IC2IF = IFS1bits.IC7IF = IFS1bits.IC8IF = 0 ; // clear the interrupt
 
IEC1bits.IC7IE = 1 ; // turn on interrupt for input 1
 
return ;
}
 
void __attribute__((__interrupt__,__no_auto_psv__)) _IC7Interrupt(void)
{
unsigned int time ;
unsigned int pulse;
 
IFS1bits.IC7IF = 0 ; // clear the interrupt
while ( IC7CONbits.ICBNE )
{
time = IC7BUF ;
}
 
#if ( NORADIO == 0 )
if (!PORTBbits.RB4) //first change!
{
fall = time ;
}
else
{
pulse = ((time - fall ) >> 1 )+ PPM_ADJUST ;
 
if (pulse > 10000) //sync pulse
{
ch = 1;
frameOK = true;
}
else
{
 
PPM_IN[ch] = pulse;
 
if (ch < PPM_NUMBER_OF_CHANNELS + 1 ) 
ch++; //scan next channel
else 
{
if(frameOK == false)
{
failSafePulses = 0 ;
flags._.radio_on = 0 ;
LED_GREEN = LED_OFF ;
}
 
if( (PPM_IN[FAILSAFE_INPUT_CHANNEL] > FAILSAFE_INPUT_MIN) && (PPM_IN[FAILSAFE_INPUT_CHANNEL] < FAILSAFE_INPUT_MAX ) )
failSafePulses++ ;
 
ch = 1;
frameOK = true;
}
 
if ( (pulse < PPM_FAILSAFE_INPUT_MIN ) )
{
frameOK = false;
}
}
}
#endif
}

User avatar
MikeB
9x Developer
Posts: 17993
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Measuring Pulse width of PPM signal

Post by MikeB »

You don't mention what processor you are using, nor which compiler.
Also, perhaps you could include some of the compiler errors you are getting.
Lastly, if you post code, it makes it easier to read if you mark it as code, theree is an option for this at the top of the editing window.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
Rob Thomson
Site Admin
Posts: 4543
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: Measuring Pulse width of PPM signal

Post by Rob Thomson »

MikeB wrote:Lastly, if you post code, it makes it easier to read if you mark it as code, theree is an option for this at the top of the editing window.
I have edited his post to include these options.
Slope Soaring, FPV, and pretty much anything 'high tech'
...........if you think it should be in the wiki.. ask me for wiki access, then go add it!
User avatar
MikeB
9x Developer
Posts: 17993
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Measuring Pulse width of PPM signal

Post by MikeB »

Yes, but the indenting was already lost!

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

Post Reply

Return to “Software”