does anyone know how to get reliable PWM on an attiny cuz ive tried a few programs and they
are spuratic running a dc motor it works but it will pause and start at like 65-70% duty cycle
and other random points ? please help ! Im programming with an arduino uno waiting on another
programmer BTW....
I have.. somewhere several pieces of code that implement PWM on a Tiny, with no issues...
I do have an issue with your code, however.
I would highly suggest you reading the fifth note How to use this Forum - Please read..
Post your code Using the code tag icon ( </> )...
My crystal ball is broken and I have no intention of ever fixing it.. besides I'm a very poor Very Poor guesser.
Doc
I have no problem using PWM on the Tinyx5 series, I have several devices that use it with no problem.
There is some other problem with your circuit or code. If you would post those, we could advice.
int ledpin=1;
int analogpin=A3;
int val=0;
void setup()
{
pinMode(ledpin,OUTPUT);
}
void loop()
{
val=analogRead(analogpin);
analogWrite(ledpin,val/4);
}
// here its the best I could find that would fit on the 13 with 1 k of memory but I have several 85s so as
// long as it works good I could use one of those
bandmwhitt2013:
int ledpin=1;
int analogpin=A3;
int val=0;
void setup()
{
pinMode(ledpin,OUTPUT);
}
void loop()
{
val=analogRead(analogpin);
analogWrite(ledpin,val/4);
}// here its the best I could find that would fit on the 13 with 1 k of memory but I have several 85s so as
// long as it works good I could use one of those
What is connected to analog in and how is the motor connected?
You should have a snubber diode on the motor and bypass caps across the tiny
What kind of motor are you driving and how is it connected?
Try using just an LED with a resistor. Are you using a transistor or other motor driver to power the motor? If so, does it have a separate power supply?
Try sending both the input, and the output to your serial monitor. What does it look like then?
If val = 9, then what will the PWM output be? I think 2. That probably will not run a motor.
I have a sneaking suspicion that he's driving a computer PWM fan (those have 4 wires - ground, +12v, speed sensor and PWM, and the PWM is meant to be driven with 5v - but those can't be turned all the way off, to prevent you from forcing it off from software and damaging the computer (as the difference between a fan that's barely spinning, and one that's not spinning at all is huge, in terms of cooling). That's my experience at least - I couldn't make mine stop on my BFFL (a 150 watt LED flashlight), so I just put up with it slowly spinning whenever the controller is powered up, whether or not the light is on.