Comments (6)
from timerone.
Some hardware simply isn't capable of 100% duty cycle. Typically those boards give a very short pulse, less than 1 timer cycle.
Or it could be a software bug.
Which board are you using? I can't tell from your text and photo.
from timerone.
Here is the other code I run on my Arduino Uno (same hardware as before): source
#include <Arduino.h>
#define MIN_DUTY_CYCLE 0
#define MAX_DUTY_CYCLE 100
#define DEFAULT_DUTY_CYCLE 20
#define DELAY 100 //ms
//--- PWM control
const byte OC1A_PIN = 9;
const byte OC1B_PIN = 10;
const word PWM_FREQ_HZ = 25000; //Adjust this value to adjust the frequency
const word TCNT1_TOP = 16000000/(2*PWM_FREQ_HZ);
int dutyCycle=DEFAULT_DUTY_CYCLE;
//--- Forward declaration
void setPwmDuty(byte duty);
void setup() {
Serial.begin(9600);
pinMode(OC1A_PIN, OUTPUT);
// Clear Timer1 control and count registers
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
// Set Timer1 configuration
// COM1A(1:0) = 0b10 (Output A clear rising/set falling)
// COM1B(1:0) = 0b00 (Output B normal operation)
// WGM(13:10) = 0b1010 (Phase correct PWM)
// ICNC1 = 0b0 (Input capture noise canceler disabled)
// ICES1 = 0b0 (Input capture edge select disabled)
// CS(12:10) = 0b001 (Input clock select = clock/1)
TCCR1A |= (1 << COM1A1) | (1 << WGM11);
TCCR1B |= (1 << WGM13) | (1 << CS10);
ICR1 = TCNT1_TOP;
//The fan is by default operating at DEFAULT_DUTY_CYCLE (instructions are given in the loop)
Serial.print("Fan at default duty cycle: ");Serial.println(DEFAULT_DUTY_CYCLE);
}
void loop() {
setPwmDuty(100);
}
void setPwmDuty(byte duty) {
if(duty>MAX_DUTY_CYCLE)
{
duty = MAX_DUTY_CYCLE;
}
if(duty<MIN_DUTY_CYCLE)
{
duty = MIN_DUTY_CYCLE;
}
OCR1A = (word) (duty*TCNT1_TOP)/100;
}
from timerone.
Some hardware simply isn't capable of 100% duty cycle. Typically those boards give a very short pulse, less than 1 timer cycle.
Or it could be a software bug.
Which board are you using? I can't tell from your text and photo.
While this isn't an issue in my project, I did observe it on an Arduino Nano clone board (Atmega328p).
from timerone.
Related Issues (20)
- External input for the timer1 to generate an interrupt when the counter reaches the maximum HOT 4
- Errors when using TimerOne with new Arduino Nano Every HOT 3
- Inverted PWM HOT 1
- [Error:] Not Working for the Digispark with Attiny85 HOT 1
- is it possible to attach overload metheds to the timer
- TimerOne issue in combination with BMP085 Adafruit driver
- Lacking support for pwm pins 0 and 1 on ATTiny85
- probably flaw of start() HOT 2
- Timer will not delay for long periods
- Timer1 hangs delay() function. HOT 1
- First cycle after start() is half the specified interval on Teensy 3.6
- Two glitches at start of timer on Teensy 2.0++ HOT 1
- Is the TimerOne library not compatible with the GPL license?
- Support for ATtiny84/44/24
- Support for ATtiny13 HOT 1
- Compile Error with Updated A-Star 328PB Board Info HOT 6
- Feature Request
- New release? HOT 1
- Missing support for Atmega128
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from timerone.