Which pins should i use according to the following code & the arduino pro mini? Also is it possible to connect pin 3 and pin 10 the the servo signal cable simultaneously ? Or I am not getting the meaning of the code right ? Which pins were actually used here then according to your programming understanding of the code....
// inout for 16mhz arduino
// timebase is timer1 running 0.5us resolution up to 0xA000
// servo output timer1 channel A & B pin9 & pin10
// PPMSUM input INT0 PIN2 or
// Single channel INT0 & INT1 pin2 & pin3
#define PPM_FREQ 0xA000 //xA000 // 20ms
#define SERVOS 2
#define RC_CHANNELS 5
uint16_t servo[SERVOS];
volatile uint16_t rcValue[RC_CHANNELS];
#if defined(PPM_IN)
volatile uint16_t last_0;
volatile uint16_t last_1;
void rxInt0()
{
uint16_t now,diff;
now = TCNT1;
if (!(PIND & 1<<2)) // we got a low on PD2
{
if (now >= last_0) diff = now - last_0;
else diff = now + PPM_FREQ - last_0;
if (1800<diff && diff<4200) rcValue[0] = diff>>1; // 1000 - 2000
}
last_0 = now;
}
void rxInt1()
{
uint16_t now,diff;
now = TCNT1;
if (!(PIND & 1<<3)) // we got a low on PD3
{
if (now >= last_1) diff = now - last_1;
else diff = now + PPM_FREQ - last_1;
if (1800<diff && diff<4200) rcValue[1] = diff>>1; // 1000 - 2000
}
last_1 = now;
}
#endif
#if defined(PPMSUM)
volatile uint16_t last_ppmsum;
volatile uint8_t chan = 0;
void rxIntSum()
{
uint16_t now,diff;
now = TCNT1;
if (now >= last_ppmsum) diff = now - last_ppmsum;
else diff = now + PPM_FREQ - last_ppmsum;
if (diff>6000) chan = 0; // Sync gap
else if (chan < RC_CHANNELS)
{
if (1800<diff && diff<4200)
{
rcValue[chan] = diff>>1;
chan++;
}
else chan = 20;
}
last_ppmsum = now;
}
#endif
void setupInput()
{
TCCR1A = (1<<WGM11);
TCCR1B = (1<<WGM12) | (1<<WGM13);
ICR1 = PPM_FREQ; // 20ms
TCCR1B |= (1<<CS11);
#if defined(PPM_IN)
pinMode( 2,INPUT);
attachInterrupt(0, rxInt0, CHANGE);
pinMode( 3,INPUT);
attachInterrupt(1, rxInt1, CHANGE);
#endif
#if defined(PPMSUM)
pinMode( 2,INPUT);
attachInterrupt(0, rxIntSum, FALLING);
#endif
for (byte i=0;i<RC_CHANNELS;i++) rcValue[i] = 1500;
}
void setupServo()
{
pinMode( 9,OUTPUT);
pinMode(10,OUTPUT);
TCCR1A |= (1<<COM1A1); // connect pin 9 to timer 1 channel A
TCCR1A |= (1<<COM1B1); // connect pin 10 to timer 1 channel B
for(int i=0;i<SERVOS;i++) servo[i] = 1500; // 1,5ms
writeServo();
}
void writeServo()
{
OCR1A = servo[0]<<1; // pin 9 PB5
OCR1B = servo[1]<<1; // pin 10 PB6
}

