I'm very new in arduino and facing one problem.
NOT getting PWM
code is attached herewith.
but if I put
x=512; instead of x=1023*(5/10) getting PWM with 50% duty and frequency 8kHz
it would be nice of you if you give suggestion regarding this
/* Thsi file is the basic test of PWM
- Kingsuk Majumdar
- Arduino uno
*/
#include <TimerOne.h> // Including library
#include <math.h> // Math library
#define PWM 9 // 9 pin taken as PWM pin
double duty,x;
void setup() {
// put your setup code here, to run once:
pinMode(PWM,OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Timer1.initialize(125); // 8kHz frequency
}
void loop() {
x=1023*(5/10); // 50% duty ****
duty=round(x);
// put your main code here, to run repeatedly:
Timer1.pwm(PWM,duty); // Duty cycle set up
digitalWrite(LED_BUILTIN, HIGH);
Serial.println(x, DEC);
}