1kHtz? #4474
Replies: 1 comment
-
Posted at 2015-02-18 by DrAzzy You can get that on a pwm pin real easy... analogWrite(pin, 0.5, {freq:1000}) Posted at 2015-02-18 by user52526 Do you know the highest frequency that can be achieved with analogWrite? Posted at 2015-02-18 by user52526 Apparently 25 pins are capable of PWM, thanks! Posted at 2015-02-18 by @gfwilliams I'm not 100% sure on the highest frequency, but I believe it is over 1MHz. My guess is that based on Espruino's execution speed, your code might struggle to run at 1KHz. You can definitely do a bit better with software if you need to (using Posted at 2015-02-18 by @gfwilliams You can also get a good idea of which pins you can use on this page Posted at 2015-02-18 by user52526 The reason why I'm not using setInterval is because it would work for LED's but when I tried using it with a toy motor, it would turn on but not off... setTimeout works for the motor and LED's so I've just been using that In case it's not obvious, lol, I'm super new and just learning as I go. Posted at 2015-02-18 by @gfwilliams Ahh, well what you'd want to do with setInterval is something like this:
(So you use a setInterval for each full cycle, and then setTimeout for each pulse) Or you could use the built-in
Hopefully those should work on anything Posted at 2015-02-18 by HerrLinder Which pwm timers are assign to which pins? Posted at 2015-02-18 by user52526 All the pins that are marked with a PWM are compatible http://www.espruino.com/ReferenceESPRUINOBOARD Posted at 2015-02-18 by user52526 I just found this page http://www.espruino.com/Waveform which says espruino can only go up to .5KHtz with analogWrite() Posted at 2015-02-18 by DrAzzy Hover your mouse over the pins on the reference page and it will show which timers they're on. As for which ones Espruino uses (in cases where there are more than one timer on a pin), I think my list here is accurate: http://forum.espruino.com/comments/12102383/ (Avoid using B4/B5, as noted in that thread) The Waveform page is describing outputting analog voltages using analogWrite() on a DAC pin (there are 2 DAC pins on Espruino board, A4 and A5 - output an actual analog voltage between 0 and 3.3v, instead of PWM), not a PWM pin. Posted at 2015-02-18 by user52526 I've been trying to replicate the voltage doubler (tripler actually) that is presented here: http://youtu.be/I4ED_8cuVTU?t=11m by alternating between
and
via the console but this isn't making a difference in voltage... I'm using 47uF Capacitors and regular diodes... I'll try replicating this again and sharing the result via video. Posted at 2015-02-19 by @gfwilliams What he's suggesting there should work just fine with analogWrite. If you don't have an oscilloscope then maybe in order to check it's working you could set Posted at 2015-02-19 by user52526 I've been trying that, and the voltage seems to be doubling, but I've wired it up to be tripled (which makes me believe it's only doubling because there's another input, not because there's added voltage from capacitors)... I've tested the difference by pulling out the second capacitor, but the brightness remains the same and changing the frequency has no difference from if I used the toggle function in the OP. I'll try uploading a test to youtube today and link it here. Posted at 2015-02-19 by @gfwilliams If you have an oscilloscope it'd be a lot easier to see what was happening... I've just tried here and with two capacitors and two diodes I can get around 6v, which is about what you'd expect from the 3.3v output (minus some diode voltage drops). Because of the way it works, increasing the frequency won't increase the voltage at all - it'll just increase the current, but only up to as much as the 20mA STM32 output can supply. Posted at 2015-02-19 by @gfwilliams Just to add that yes, it does work as a tripler. I get 8.64v out of it with the 4 caps and 4 diodes from his circuit. Are you sure you've wired it up right? I did mine wrong the first time (connecting the diode from the second set of capacitors to 3.3v not the output of the previous voltage doubler), and I just got 6v off it again. Posted at 2015-02-20 by user52526 Got distracted with something else, tomorrow for sure. Thanks for the help so far Posted at 2015-02-21 by user52526 The test leads are measuring the second capacitor from the PWM line, the schematic I've replicated can be found here: http://youtu.be/I4ED_8cuVTU?t=11m11s There is actually a drop in voltage from 5000 Htz to 10000 Htz and I just noticed a weird thing where the Capacitor's Voltage actually increases when you use digitalWrite(C9,0) and will only start discharging when you use digitalRead(C9)... also, if you look at the line of code I ran just before running the first digitalRead(C9), you will see that the output was 0 and yet I got a 1 on that pre-test... no idea what was going on there... I'm using 47uF capacitors, diodes that have a .7 forward voltage drop, 10K potentiometer and a 76ohm resistor Posted at 2015-02-23 by @gfwilliams It looks to me like you're maybe drawing too much power out of it. Where is the LED connected? What happens if you just totally disconnect the potentiometer and the LED and then look at the voltage that you get? Posted at 2015-02-23 by user52526 The LED and potentiometer are connected where they should be receiving somewhere near 11V after you subtract the voltage drop from the diodes and how it's around a 4.7V output (the multimeter is monitoring the voltage of the second capacitor, not the total voltage of the circuit, when I measure the total voltage, it's just showing up as 4.7V). I've tried removing the LED and potentiometer and the capacitor just slowly discharges. Do you know why the voltage wouldn't drop until I used a digitalRead(C9)? Shouldn't just calling the digitalWrite(C9,0) cut the signal? Posted at 2015-02-23 by @allObjects Did you ever set pinMode(pin,"mode") of C9 to "output"? If not, it is still on automatic setting mode, which means that a write makes it an output, and a read makes it an input... and as soon the read happens, the 'feeding' of your circuitry with power stops. Furthermore, I think, you may need to put a power driver in there... either a PNP or PMOS thing to get more juice to the circuitry while pin is high (active switching/feed). This allows you then also to feed directly from the battery - or even higher voltage source, if you desire so. Higher voltage source requires a little different circuitry (pin low, passive switching/feed). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-02-18 by user52526
In theory, the toggle function in the code below would create a PWM with a 1kHtz frequency with a 50% duty cycle, but I know there are some limitations to the hardware, has anybody tried something like this before?
Beta Was this translation helpful? Give feedback.
All reactions