ArduPPM: PWM to PPM mode
PPM polarity reversing was not working when changing the Output PPM pin level before timer 1 / output compare init. The compare generator initialization was reverting the pin to low level. Instead of that a force match compare is used after timer / compare generator init to set the PPM output to high level.
This commit is contained in:
parent
c5b68b17cd
commit
70c6739fbf
@ -259,6 +259,7 @@ const uint16_t failsafe_ppm[ PPM_ARRAY_MAX ] =
|
|||||||
#define PPM_COMPARE OCR1A
|
#define PPM_COMPARE OCR1A
|
||||||
#define PPM_COMPARE_FLAG COM1A0
|
#define PPM_COMPARE_FLAG COM1A0
|
||||||
#define PPM_COMPARE_ENABLE OCIE1A
|
#define PPM_COMPARE_ENABLE OCIE1A
|
||||||
|
#define PPM_COMPARE_FORCE_MATCH FOC1A
|
||||||
|
|
||||||
#define USB_DDR DDRC
|
#define USB_DDR DDRC
|
||||||
#define USB_PORT PORTC
|
#define USB_PORT PORTC
|
||||||
@ -312,6 +313,7 @@ void EVENT_USB_Device_Disconnect(void)
|
|||||||
#define PPM_COMPARE OCR1B
|
#define PPM_COMPARE OCR1B
|
||||||
#define PPM_COMPARE_FLAG COM1B0
|
#define PPM_COMPARE_FLAG COM1B0
|
||||||
#define PPM_COMPARE_ENABLE OCIE1B
|
#define PPM_COMPARE_ENABLE OCIE1B
|
||||||
|
#define PPM_COMPARE_FORCE_MATCH FOC1B
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error NO SUPPORTED DEVICE FOUND! (ATmega16u2 / ATmega32u2 / ATmega328p)
|
#error NO SUPPORTED DEVICE FOUND! (ATmega16u2 / ATmega32u2 / ATmega328p)
|
||||||
@ -343,13 +345,8 @@ void ppm_start( void )
|
|||||||
// Stop interrupts
|
// Stop interrupts
|
||||||
cli();
|
cli();
|
||||||
|
|
||||||
#if defined (_POSITIVE_PPM_FRAME_)
|
|
||||||
// Make sure initial output state is high
|
|
||||||
PPM_PORT |= (1 << PPM_OUTPUT_PIN);
|
|
||||||
#else
|
|
||||||
// Make sure initial output state is low
|
// Make sure initial output state is low
|
||||||
PPM_PORT &= ~(1 << PPM_OUTPUT_PIN);
|
PPM_PORT &= ~(1 << PPM_OUTPUT_PIN);
|
||||||
#endif
|
|
||||||
|
|
||||||
// Wait for output pin to settle
|
// Wait for output pin to settle
|
||||||
//_delay_us( 1 );
|
//_delay_us( 1 );
|
||||||
@ -363,6 +360,11 @@ void ppm_start( void )
|
|||||||
|
|
||||||
// Set TIMER1 8x prescaler
|
// Set TIMER1 8x prescaler
|
||||||
TCCR1B = ( 1 << CS11 );
|
TCCR1B = ( 1 << CS11 );
|
||||||
|
|
||||||
|
#if defined (_POSITIVE_PPM_FRAME_)
|
||||||
|
// Force output compare to reverse polarity
|
||||||
|
TCCR1C |= (1 << PPM_COMPARE_FORCE_MATCH);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Enable output compare interrupt
|
// Enable output compare interrupt
|
||||||
TIMSK1 |= (1 << PPM_COMPARE_ENABLE);
|
TIMSK1 |= (1 << PPM_COMPARE_ENABLE);
|
||||||
|
Loading…
Reference in New Issue
Block a user