Hello,
I want to decode PPM Signals with an Arduino Duemilanove with a mega328. I have a "c" code, I want to usw in this program, but I only get a lot of Errors during compiling.
Servo_Controller.cpp.o: In function `loop':
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:13: undefined reference to `ppm_Get(int)'
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:14: undefined reference to `ppm_Get(int)'
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:15: undefined reference to `ppm_Get(int)'
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:16: undefined reference to `ppm_Get(int)'
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:17: undefined reference to `ppm_Get(int)'
Servo_Controller.cpp.o:C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:18: more undefined references to `ppm_Get(int)' follow
Servo_Controller.cpp.o: In function `setup':
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:8: undefined reference to `ppm_Init()'
The Arduino Code:
#include <PPM.h>
void setup(){
Serial.begin(115200);
ppm_Init();
}
void loop(){
delay(250);
Serial.print(ppm_Get(0),DEC);
Serial.print(ppm_Get(1),DEC);
Serial.print(ppm_Get(2),DEC);
Serial.print(ppm_Get(3),DEC);
Serial.print(ppm_Get(4),DEC);
Serial.print(ppm_Get(5),DEC);
Serial.println("--");
}
And the Lib, placed in the libraries folder in the folder "PPM"
#ifndef PPM_H_
#define PPM_H_
#define PPM_CHANNELS (6)
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <avr/io.h>
#include <avr/interrupt.h>
unsigned char ppm_channel[PPM_CHANNELS];
extern volatile char ppmNewData;
extern volatile char ppmValid;
extern volatile int chan;
extern volatile uint8_t last_ppm_state;
void ppm_Init();
unsigned char ppm_Get(int n);
#endif /* PPM_H_ */
#include "PPM.h"
volatile unsigned int ppm[PPM_CHANNELS];
volatile int chan = -1;
#define T_MIN ((1*F_CPU)/64/1000)
#define T_MAX ((2*F_CPU)/64/1000)
#define T_OUT ((3*F_CPU)/64/1000)
volatile char ppmNewData;
volatile char ppmValid;
volatile unsigned int timeOld;
volatile uint8_t last_ppm_state;
void ppm_Init()
{
DDR_ICP &=~(1<<PORT_ICP);
TCCR1B = (1<<CS11)|(1<<CS10); //Prescaler 64
TCCR1B |= (1<<ICNC1); //Noise canceler
//TCCR1B |= (1<<ICES1); //Riseing edge, when bit is set
TIMSK1 = (1<<ICIE1) | (1<<OCIE1A);
ppmNewData = 0;
ppmValid = 0;
chan=-1;
}
ISR(TIMER1_COMPA_vect)
{
if(chan!=-1)
{
ppmNewData = 1;
/*PPM Decoding*/
/*ppmValid = 0xff;
char i;
for(i=0;i<PPM_CHANNELS;i++)
{
int tmp = ppm_Get(i);
if((tmp<5)||(tmp>250))
{
ppmValid = 0x00;
}
}*/
/**************/
}
else
{
ppmValid = 0;
}
chan=-1;
}
ISR(TIMER1_CAPT_vect)
{
unsigned int time=ICR1;
OCR1A=time+T_OUT;
if (time>timeOld)
{
time=time-timeOld;
}
else
{
time=time+(0xffff-timeOld)+1;
}
timeOld=ICR1;
if (chan>=0 && chan<PPM_CHANNELS)
{
ppm[chan]=time;
}
chan++;
}
unsigned char ppm_Get(int n) {
unsigned int t=ppm[n];
// conversion T_MIN...T_MAX -> 0...255
if (t<T_MIN) t=T_MIN;
t-=T_MIN;
t=t/((T_MAX-T_MIN)/255.0);
if (t>255.0) t=255.0;
return ((unsigned char)t);
}
I don't know, whats my fault. Can somebody please help me?
Greeting Philipp