mirror of
https://github.com/opentx/opentx.git
synced 2025-07-25 17:25:13 +03:00
PPM changes pulled from er9x (by Pat Mackenzie)
This commit is contained in:
parent
f9d3e11956
commit
80bfc11a83
1 changed files with 11 additions and 8 deletions
|
@ -94,7 +94,7 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation
|
||||||
#ifdef DSM2_SERIAL
|
#ifdef DSM2_SERIAL
|
||||||
if (g_model.protocol == PROTO_DSM2) {
|
if (g_model.protocol == PROTO_DSM2) {
|
||||||
OCR1A = 40000;
|
OCR1A = 40000;
|
||||||
sei();
|
// sei will be called inside setupPulses()
|
||||||
setupPulses();
|
setupPulses();
|
||||||
cli();
|
cli();
|
||||||
UCSR0B |= (1 << UDRIE0); // enable UDRE0 interrupt
|
UCSR0B |= (1 << UDRIE0); // enable UDRE0 interrupt
|
||||||
|
@ -142,17 +142,18 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation
|
||||||
|
|
||||||
pulsePol = g_model.pulsePol;
|
pulsePol = g_model.pulsePol;
|
||||||
|
|
||||||
|
// TODO does it exist PCBV3? If no, replace PCBV3 by PCBV4 everywhere
|
||||||
#if defined(PCBV3)
|
#if defined(PCBV3)
|
||||||
TIMSK1 &= ~(1<<OCIE1A); //stop reentrance
|
TIMSK1 &= ~(1<<OCIE1A); //stop reentrance
|
||||||
#else
|
#else
|
||||||
TIMSK &= ~(1<<OCIE1A); //stop reentrance
|
TIMSK &= ~(1<<OCIE1A); //stop reentrance
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sei();
|
// sei will be called inside setupPulses()
|
||||||
|
|
||||||
setupPulses();
|
setupPulses();
|
||||||
|
|
||||||
#if !defined(PCBV3) && defined(DPPMPB7_HARDWARE)
|
#if defined(DPPMPB7_HARDWARE)
|
||||||
// G: NOTE: This strategy does not work on the '2560 becasue you can't
|
// G: NOTE: This strategy does not work on the '2560 becasue you can't
|
||||||
// read the PPM out pin when connected to OC1B. Vincent says
|
// read the PPM out pin when connected to OC1B. Vincent says
|
||||||
// it works on the '64A. I haven't personally tested it.
|
// it works on the '64A. I haven't personally tested it.
|
||||||
|
@ -196,15 +197,14 @@ FORCEINLINE void setupPulsesPPM() // changed 10/05/2010 by dino Issue 128
|
||||||
uint16_t q = (g_model.ppmDelay*50+300)*2; //Stoplen *2
|
uint16_t q = (g_model.ppmDelay*50+300)*2; //Stoplen *2
|
||||||
uint16_t rest = 22500u*2-q; //Minimum Framelen=22.5 ms
|
uint16_t rest = 22500u*2-q; //Minimum Framelen=22.5 ms
|
||||||
rest += (int16_t(g_model.ppmFrameLength))*1000;
|
rest += (int16_t(g_model.ppmFrameLength))*1000;
|
||||||
if(p>9) rest=p*(1720u*2 + q) + 4000u*2; //for more than 9 channels, frame must be longer
|
|
||||||
for (uint8_t i=0; i<p; i++) {
|
for (uint8_t i=0; i<p; i++) {
|
||||||
int16_t v = limit((int16_t)-PPM_range, g_chans512[i], (int16_t)PPM_range) + PPM_CENTER;
|
int16_t v = limit((int16_t)-PPM_range, g_chans512[i], (int16_t)PPM_range) + PPM_CENTER;
|
||||||
rest -= (v+q);
|
rest -= (v+q);
|
||||||
*ptr++ = q;
|
|
||||||
*ptr++ = v - q + 600; /* as Pat MacKenzie suggests */
|
*ptr++ = v - q + 600; /* as Pat MacKenzie suggests */
|
||||||
|
*ptr++ = q;
|
||||||
}
|
}
|
||||||
*ptr = q;
|
*ptr = rest;
|
||||||
*(ptr+1) = rest;
|
*(ptr+1) = q;
|
||||||
pulses2MHzWPtr = ptr+2;
|
pulses2MHzWPtr = ptr+2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,15 +563,18 @@ void setupPulses()
|
||||||
#endif
|
#endif
|
||||||
#ifdef PXX
|
#ifdef PXX
|
||||||
case PROTO_PXX:
|
case PROTO_PXX:
|
||||||
|
sei();
|
||||||
setupPulsesPXX();
|
setupPulsesPXX();
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef DSM2_SERIAL
|
#ifdef DSM2_SERIAL
|
||||||
case PROTO_DSM2:
|
case PROTO_DSM2:
|
||||||
|
sei();
|
||||||
setupPulsesDsm2();
|
setupPulsesDsm2();
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
// no sei here
|
||||||
setupPulsesPPM();
|
setupPulsesPPM();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -596,7 +599,7 @@ ISR(TIMER1_COMPB_vect) // DSM2 end of frame
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OCR1B = 200;
|
OCR1B = 200;
|
||||||
sei();
|
// sei will be called inside setupPulses()
|
||||||
setupPulses();
|
setupPulses();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue