[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] ATMega128 Fast PWM
From: |
Thomas D. Dean |
Subject: |
[avr-gcc-list] ATMega128 Fast PWM |
Date: |
Tue, 26 Aug 2014 11:31:51 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 |
How do I change the polarity of the PWM output, WGM mode 5, OCR1A on the
fly?
I use WGM mode 5 to provide PWM to drive gearhead motors. I update the
OCR values every 50 msec. The algorithm makes changes gradually.
If, for example, the motor is CCW at 50%, the OCR value is 128. The
register values for this are:
(1)
TCCR1A = _BV(COM1A1) | _BV(WGM10);
TCCR1B = _BV(WGM12) | _BV(CS11);
OCR1A = 80;
I want to reverse the direction of the motor. The register values are:
(2)
TCCR1A = _BV(COM1A1) | _BV(COM1A0) |_BV(WGM10);
TCCR1B = _BV(WGM12) | _BV(CS11);
OCR1A = 80;
The algorithm will slow the motor to stop and then reverse it. I tried
setting OCR1A = 0, changing the TCCR1 values, and setting OCR1A = 80.
This does not work. After changing from (1) to (2), the PWM stops.
What am I doing wrong? Any ideas?
Tom Dean
oc-pwm.c
Description: Text Data
- [avr-gcc-list] ATMega128 Fast PWM,
Thomas D. Dean <=