Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1229 → Rev 1242

/branches/V0.74d-Arthur P/timer0.c
13,7 → 13,12
volatile int16_t ServoNickValue = 0;
volatile int16_t ServoRollValue = 0;
 
// Arthur P: Added two variables for control of the shutter servo cycle.
 
volatile static unsigned int CameraShutterCycleCounter = 0;
volatile static unsigned int CameraShutterCycle = 0;
 
 
enum {
STOP = 0,
CK = 1,
129,6 → 134,7
// to control a camera servo for nick compensation.
void TIMER2_Init(void)
{
uint8_t sreg = SREG;
 
// disable all interrupts before reconfiguration
176,6 → 182,7
//----------------------------
void Timer_Init(void)
{
 
tim_main = SetDelay(10);
TCCR0B = CK8;
TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM
218,7 → 225,17
static int16_t ServoNickOffset = (255 / 2) * MULTIPLYER; // initial value near center positon
static int16_t ServoRollOffset = (255 / 2) * MULTIPLYER; // initial value near center positon
 
// Arthur P: Added initialization of the CameraShutterCycle value here as this routine is only
// called once. This retains all code changes in timer0.c. If parameter 6 > 0 then the user
// has set a value for the cycle. CameraShuytterCycle == 5x Para6 to get approx 0.1sec increments.
// CameraShutterCycle = 5 * Parameter_UserParam6;
CameraShutterCycle = Parameter_UserParam6;
 
// Arthur P: Modified the code to scheck the value of parameter 8. If 128 or higher then a HEF4017 is
// expected and will be used. Else J7 and J9 are seen as separate normal outputs.
// if((PlatinenVersion < 20)
 
if((PlatinenVersion < 20) && (Parameter_UserParam8 < 128 ))
{
//---------------------------
320,11 → 337,22
DebugOut.Analog[20] = ServoNickValue;
break;
case 2: // Roll Compensation Servo
ServoRollOffset = (ServoRollOffset * 3 + (int16_t) 80 * MULTIPLYER) / 4; // lowpass offset
// Arthur P: Modified the code here to allow the user to either continue with the default
// offset value of 80, or set a different offset using parameter 7. I.e. if
// parameter 7 == 0 then the default is used, but if a value > 0 is entered then
// that value is used.
if(Parameter_UserParam7==0)
{
ServoRollOffset = (ServoRollOffset * 3 + (int16_t) 80 * MULTIPLYER) / 4; // lowpass offset
}
else
{
ServoRollOffset = (ServoRollOffset * 3 + (int16_t) Parameter_UserParam7 * MULTIPLYER) / 4;
}
ServoRollValue = ServoRollOffset; // offset (Range from 0 to 255 * 3 = 765)
//if(EE_Parameter.ServoRollCompInvert & 0x01)
if(Parameter_UserParam8 & 0x40)
{ // inverting movement of servo if 64 has been added to User Parameter8
{ // Arthur P: Inverting movement of servo if 64 has been added to User Parameter8
ServoRollValue += (int16_t)( ( (int32_t) 50 * MULTIPLYER * (IntegralRoll / 128L ) ) / (256L) );
}
/**/ else
369,7 → 397,57
ServoRollValue /= MULTIPLYER;
//DebugOut.Analog[20] = ServoRollValue;
*/ break;
case 3: // Arthur P: Shutter Servo including interval control over parameter 5 and 6.
 
if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] < -32)
{
// Set servo to null position, turning camera off.
RemainingPulse = MINSERVOPULSE;
}
else
{
if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] > 32)
// Middle position on a 3 position switch which runs from -127 to +127
{
RemainingPulse = MINSERVOPULSE + SERVORANGE/2;
}
else
{
// Cycle shutter servo between on and off depending upon CameraShutterCycleCounter
// If CameraShutterCylce < 50 then default to continuous shoot.
if(CameraShutterCycle < 50 )
{
RemainingPulse = MINSERVOPULSE + SERVORANGE/2;
}
else
{
if(CameraShutterCycleCounter == CameraShutterCycle)
{
// Shutter on
CameraShutterCycleCounter = 0;
RemainingPulse = MINSERVOPULSE + SERVORANGE/2;
}
else
{
// Leave on for at least 24 cycles or 0.25 seconds to allow
// the camera to properly trigger, turn off if past 0.25 sec.
// For now this is actually set via para5 to allow for a long enough
// shutter pulse for different cameras. Once it is clear what value
// works, this can be changed to a hardcoded value.
if(CameraShutterCycleCounter>Parameter_UserParam5)
{
RemainingPulse = MINSERVOPULSE;
}
CameraShutterCycleCounter++;
}
}
}
}
break;
default: // other servo channels
RemainingPulse += 2 * PPM_in[ServoIndex]; // add channel value, factor of 2 because timer 1 increments 3.2µs
break;
378,6 → 456,9
if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit
else if(RemainingPulse < MINSERVOPULSE ) RemainingPulse = MINSERVOPULSE; // lower servo pulse limit
// substract stop pulse width
// Arthur P: I think the following line, correcting for the PPM sTOPPULSE does not apply for the
// calculated pulses, or maybe not at all. Therefore I-m commenting it out to see what happens....
// 090624 reactivated as rollservo correction can now be done over para7.
RemainingPulse -= PPM_STOPPULSE;
// accumulate time for correct sync gap
ServoFrameTime += RemainingPulse;