I have a problem when using the TimerOne.h library on a Uno board.
The scetch include an adjustable pwm signal whith low frequency. It works but
for some reason the output is disturbed at various frequencies, see photos. I have removed all unnecessary code and added the basic code.
Replacing the Arduino board didn't matter.
What could be the cause of this?
Regards Wim
#include <TimerOne.h>
unsigned long t=30000,f,k=512;
byte k1,kn,kn1,kn2;
int drive,drive0;
void setup()
{
pinMode(9, OUTPUT);
pinMode(A2,INPUT);// button at input A2
pinMode(12,INPUT);// button at input 12
pinMode(13,INPUT);// button at input 13
}
void loop()
{
Timer1.initialize(t); // period
Timer1.pwm(9, k); // k - fill factor 0-1023.
kn=digitalRead(A2);// button input 6 (- pulse period)
kn1=digitalRead(12);// button input 7 (+ pulse period)
kn2=digitalRead(13);// button input 13 (+ fill factor)
if(kn==HIGH) // decreasing the period
{
drive++;
if(t>14000)
{
t=t-800;
}
else if(t>7000 && t<=14000 )
{
t=t-500;
}
else if(t<=7000)
{
t=t-200;
}
}
else
{
drive=0;
}
if(kn1==HIGH)// adding a period
{
drive0++;
if(t>14000)
{
t=t+800;
}
else if(t>7000 && t<=14000 )
{
t=t+500;
}
else if(t<=7000)
{
t=t+200;
}
}
else
{
drive0=0;
}
if(t==0 || t>300000){ // limiting the pulse duration to the minimum
t=1;
}
if(t>200000 && t<300000){ // limiting the pulse duration to the maximum
t=200000;
}
f=1000000/t; // calculate the frequency
k1=k*100/1024; // calculate% fill factor
if(kn2==HIGH){// button for adjusting the fill factor
k=k+16;// step 16 out of 1024
}
if(k==1024){
k=0;
}
delay(100);
}
Thanks for your reply.
I tried to add á recorded movie but that's not possible.
The scope shows a flickering in horizontal direction. You can see the little moving dot bottom left that disturb the signal. In the movie it's very clear...