there is still a nasty fucking bug with OCR1A

This commit is contained in:
Lucas Pleß 2014-06-03 16:47:18 +02:00
parent c66c8a0def
commit 2cc08730e3
2 changed files with 21 additions and 18 deletions

View File

@ -58,7 +58,7 @@ static void work_uart() {
reset_input_buffer();
}
#ifdef DEBUG
#ifdef DEBUG1
for(uint8_t i=0;i<BUFSIZE;i++) {
uart_print_uint8(data_in[i]);
uart_putc('\r');
@ -67,7 +67,7 @@ static void work_uart() {
uart_puts_P(" -- \r\n");
#endif
if (cur == '\n' && data_count > 1) { // \n
if (cur == 13) { // \n
power = atol(data_in);
if(power > POWER_MAX) power = POWER_MAX;
@ -76,10 +76,10 @@ static void work_uart() {
uart_puts_P("power = ");
uart_print_uint16(power);
uart_puts_P("\r\n");
#endif
set_servo(power);
if(power > 0) {
set_servo(power);
}
reset_input_buffer();
}
@ -113,13 +113,17 @@ void set_servo(uint16_t display) {
// check if timer is currently in the small pulse, then sleep here 2ms
// and do again
if(OCR1A < 2250) {
_delay_ms(2);
if(OCR1A <= 2250) {
_delay_ms(10);
}
cli(); // read and write atomic
OCR1A = 2500-display;
sei();
//cli(); // read and write atomic
TIMSK &= ~(_BV(OCIE1A));
OCR1A = 2500-display;
//sei();
TIMSK |= _BV(OCIE1A);
}
@ -143,13 +147,13 @@ int main(void) {
timer_init();
uart_init(UART_BAUD_SELECT(38400,F_CPU));
reset_input_buffer();
demo_display();
//demo_display();
while(1) {
work_uart();
if(syscounter >= 100) {
if(syscounter >= 10) {
reset_input_buffer();
uart_putc('a'); // send a to receive values from master box
syscounter = 0;

View File

@ -11,11 +11,10 @@ incdec = 0
while 1:
tdata = ser.read()
time.sleep(1)
if tdata == 'a':
print power
ser.write(str(power) + '\n')
ser.write(str(power) + '\x0d')
#ser.write('100\n')
ser.flush()
@ -31,7 +30,7 @@ while 1:
if power < 0:
power = 0
incdec = 0
else:
data_left = ser.inWaiting()
tdata += ser.read(data_left)
print tdata
#else:
#data_left = ser.inWaiting()
#tdata += ser.read(data_left)
#print tdata