Code Monkey home page Code Monkey logo

Comments (6)

sylvanoMTL avatar sylvanoMTL commented on July 30, 2024

IssueTimerOne100p100Duty

from timerone.

PaulStoffregen avatar PaulStoffregen commented on July 30, 2024

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.

sylvanoMTL avatar sylvanoMTL commented on July 30, 2024

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;
}

IssueTimerOne100p100Duty_directTimer

from timerone.

SteveGuidi avatar SteveGuidi commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.