flapping servo workaround, ugly ass hell, do not use as example

This commit is contained in:
Jan-Philipp Warmers 2014-06-14 12:34:03 +02:00
parent 5e12e742ba
commit 1752f5a0a1
1 changed files with 15 additions and 1 deletions

View File

@ -14,6 +14,8 @@
#define BUFSIZE 10 #define BUFSIZE 10
#define DEBUG2
volatile uint16_t syscounter = 0; volatile uint16_t syscounter = 0;
volatile uint16_t power; volatile uint16_t power;
uint8_t data_count = 0; uint8_t data_count = 0;
@ -92,6 +94,7 @@ static void work_uart() {
* \param display The power value from 0 to 400 (including bounds) * \param display The power value from 0 to 400 (including bounds)
*/ */
void set_servo(uint16_t display) { void set_servo(uint16_t display) {
int diff;
if( display > POWER_MAX ) display = POWER_MAX; if( display > POWER_MAX ) display = POWER_MAX;
@ -121,7 +124,18 @@ void set_servo(uint16_t display) {
//cli(); // read and write atomic //cli(); // read and write atomic
TIMSK &= ~(_BV(OCIE1A)); TIMSK &= ~(_BV(OCIE1A));
diff = OCR1A - (2500-display);
if(diff <=20 && diff >= -20) {
OCR1A = 2500-display; OCR1A = 2500-display;
}
else {
if(diff <=20) {
OCR1A = OCR1A+5;
}
else if ( diff >= -20 ) {
OCR1A = OCR1A-5;
}
}
//sei(); //sei();
TIMSK |= _BV(OCIE1A); TIMSK |= _BV(OCIE1A);
} }