You can get pretty close if you program Timer 1 directly (not
through the library), and have it run with the prescaler set to 1.
Ideally, you want the period of the timer in clock cycles to be:
F_CPU / 15 kHz = 16,000 kHz / 15 kHz ≈ 1066.67 CPU cycles
If you round this to the nearest integer, you get
F_CPU / 1,067 = 16,000 kHz / 1,067 ≈ 14.9953 kHz
This is ...
Since the timer1 library only accepts whole numbers for the µs parameter you get a error. You could skip using the library and configure the timer directly. Or you could have a look at the source code of the library, and see that you can kind of bypass the limitation it has by only calculating a more accurate value for the ICR1 register.
Look at cycles = ((...
There are various solutions. I suggest using two PWM channels driven by
a single timer. This way you do not have to worry about synchronizing
two timers. You can configure the channels identically, except that one
of them would be in “non-inverting” PWM mode, while the other one would
be in “inverting” mode.
Here is how I would do it: use Timer 1 to drive ...
A better way to do the above average 15 kHz (or any other frequency) is with a phase accumulator scheme. There are no IF tests; on each tick of an interrupt, you add a step to an accumulator and output the state of its MSB. This can give incredible resolution, and is probably the best you can do. But though the average frequency will be dead-on, the ...
I advice you to learn about basics of how to connect external components to MCU.
Anwser to your question is simple transistor amplifier... So you can use bipolar transistor (NPN/PNP) or MOSFET... MOSFETs is better for switching like your case, switching via PWM.
If you switching inductive load with MOSFET like motors or coils, don't forget add antiparallel ...
It will not be possible for you to PWM dim your LED with that LED driver (power supply).
That is a constant current driver with under/over-voltage protection. It delivers a specific amount of current (1.5A) and varies the voltage to allow that to happen.
If the voltage rises too high or falls too low then there must be a fault, so it shuts the power off. ...
TIMSK = (1<<OCIE1A) | (1<<TOIE1);
enables a couple of interrupts generated by Timer 1. Whenever you
enable an interrupt source, you should make sure that the matching ISR
has been defined. Otherwise, the interrupt request is routed to
__bad_interrupt(), which by default jumps to the reset vector, thus
resetting your program.
That is how it is supposed to be. In this fast PWM mode, the duty cycle
is (OCR1A+1)/(ICR1+1). If you want a duty cycle of zero, you have to
disengage the PWM and turn the pin to OUTPUT LOW.
This is what the Arduino's analogWrite() does: it treats the
value 0 as a special case. Note that 255 is also treated as a special
case, although that is not useful.
I can get within 5 Hz of 15,000 using a 16 MHz clock on a Nano, Uno or 2560. Here is the code...
// RTM_TimerCalc 1.20
// Timer-1 Mode_14_16Bit_Fast_TOP_is_ICR
TCCR1B = 0x18; // 0001 1000, Disable Timer Clock
TCCR1A = 0xA2; // 1010 0010
ICR1 = 1067-1;
OCR1A = (int) (ICR1 * 0.25);
OCR1B = (int) (ICR1 * 0.50);
// UnComment following lines for ...
It's working as intened.
The arduino UNO has no DAC (digital to analog converter) onboard, so all it can produce are digital signals, either 0 or 5v. The analogWrite function uses Pulse Width Modulation to produce an output that, on average, has the requested voltage, by quickly alternating between logic low and high with different durations.
This is done at ...
The Absolute Maximum is 40mA per pin, but you shouldn't go even close to that; max. 20mA per pin is about where you want to be. Total current (all pins) shouldn't exceed 200mA.
Only you know what current your "fairly small" motors pull, but you may have fried a few IO pins.
Also, you need flyback (or maybe bidirectional TVS) diodes and a few ...
To keep the same brightness, you have to keep the same duty cycle (percent of on time over off time). So to change the rate without changing the brightness, you have to increase
delayMicroseconds(onTime) by the same percent you increase delay(strobeDelay). But note that as you go slower, the on time will be too long to freeze the motion you are trying to ...
I know it is an old topic, but at the moment I'm also busy with it.
To be sure the ESP32 doesn't get to much voltage from the pwm input, you have to measure on the PWM input if the signal is not above 3V3, otherwhise you need a resistor divider or work with a transistor in between to pull the signal down. Mine is around 3V3 so I can directly connect the ...
Thanks for the reply Rowan.
Current draw from the power supply with a blank arduino sketch and the pwm example sketch are 0A which is clearly the issue. I've had a look back at the website I bought these PCA9685 boards from and there is a comment from another buyer with the exact same issue in the last week. They had no voltage to the servo connectors. I've ...
As far as I can tell the Arduino does not have open collector outputs, so you can mimic one as follows. The following inverts the Arduino output signal, so some adjustment is needed there when generating the PWM signal.
Excuse the rather gross schematic. I can't find any scaling parameters.
The particular resistors values are not terribly important, mainly ...
There's a number of steps you need to go through:
Read the ADC to get the joystick position
Subtract 50% of the full range (512) to get a ±512 value
Note the sign to get the direction
Take the absolute value to get the distance
Subtract a small amount to create a "dead zone" in the centre of the joystick
Map the result to 0-255 for the PWM.
I usually recommend against using delay()s, but if this system will only ever have to do what you've described, using delay()s is the simplest way to implement it.
I would suggest sending key-1, possibly several times, maybe a half second apart, delay for the 20 seconds you suggested, then send key-2, definitely several times for security.
If you buy a 30V current-limiting power supply set to limit the current to 1.5A, you should be able to use it to power your LED light through a high power logic level MOSFET. You could control the MOSFET with a PWM signal from an Arduino and use that to vary the brightness of your light. With a little googling I found an adjustable power supply with an ...
I think you need to think a little differently. Instead of "Move it at this speed until you get to here" you need to think more along the lines of "Where am I? Where do I want to get to? How far away is it?"
Basically the further you have to go the faster you want to go. The closer you get to your target value the slower you want to go.
That looks like the spectrum of an 8-bit sound that is playing low bass notes only. Most everything above that looks like noise floor. (You can only get about 6 dB range per bit of resolution, so 8 bits gives about 48 dB max.) If this is the case, you definitely don't want to reproduce the upper frequencies. If you want to stick to your original PWM ...
You can generate "stereo sound", but I don't think you'll like it. The PWM frequency is only 490 or 980 Hz, which is going to be plainly audible unless you filter the output very severely. So you'll only be able to produce low frequency sounds, about like what comes out of the woofer speakers in your home stereo. In other words, nothing like ...
The PWM looks ok but I'm unsure of the analog signal.
The “analog signal” looks like the PWM smoothed by a first-order
low-pass filter. It still has some oscillations, 584 mV
peak-to-peak. If you can tolerate that, then it's perfectly fine. If
not, then increase the time constant of your filter.
A first-order low-pass filter behaves, in its stop band, like ...
you have not put your code here so i can not understand it properly.From what i understand you must have put your code for rotating the servo motor 5 times in void loop. Don't do that put loop for rotating servo 5 time in setup.
void loop run continuously so it must be rotating 5 time then again 5 time and so on.
Your problem is that you don't know what ADC value maps to the maximum RPM. If you did you wouldn't need to know the RPM.
What you have here is a "feedback loop", and what you need is some method of using the detected RPM to control the speed of the motor.
You need to decouple the potentiometer from the analogWrite completely - the potentiometer ...
this makes heavy use of CPU, and I need to use CPU for something else
The issue with this code is that is heavily uses the CPU for busy
waiting rather than for doing useful work. You should try to get rid of
those waiting loops:
Serial.readString(): see Majenko's blog post Reading Serial on the
delayMicroseconds(): for this, you can indeed use a ...
In answer to a comment from the OP asking for another microcontroller that can do this, and in addition to Majenko's reply comment:
A SAMD21G running at 48 MHz (as seen on some Arduinos) can make 15 kHz, in several ways.
Note that this assumes that the clock is exactly 48 MHz, and stable, and both assumptions could well be wrong, unfortunately. It helps if ...
Arguable bug location
The problem appears to be here in the analogWrite() code:
timer_B->CCMPH = val;
I suppose it could be argued that you're using the timer in an way unintended
by the Arduino megaavr core, but I think it's reasonable to consider this as
a bug that should be fixed in the core.
16-bit hardware register access and analogWrite() ...
I suspect the 1Wire libary disables (and enables) interrupts when it sees fit. This will cause servo "hickups" because the servo library uses interrupts.
If I'm right, your best bet is using a servo library that doesn't use interrupts. I always use a hardware PWM library for driving servos, so I have no servo library recommendations to make, but ...
Thanks to comments I received from several people here I quadruple checked the wiring and eventualy found the problem. My recent Arduino Uno tests were done on a breadboard, but I had the Pro Mini prototype soldered on the prototyping board which has the holes connected in columns on the copper side. I made the cuts in all the necessary places ... but one! ...