EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / hello all, I have a code whic

hello all, I have a code whic

|

Microcontroller › PIC › About dsPIC33 programming in C › hello all, I have a code whic

July 9, 2012 at 4:39 pm #8225
Rahul
Participant

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.

 

 

# 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
}
 
 
 
thank you
Rahul

RSS Recent Posts

  • What is correct names for GOOD user friendly circuit drawing program? June 18, 2025
  • Curved lines in PCB design June 18, 2025
  • using a RTC in SF basic June 18, 2025
  • Is AI making embedded software developers more productive? June 18, 2025
  • Why can't I breadboard this oscillator? June 18, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise