Covert from analog to digital control using arduino

Irving

Joined Jan 30, 2016
814
If my math is correct that generates a square wave at 14Hz, but there's no variable element there.

Arduino generates PWM natively at about 500Hz so if duty cycle is the only important thing then one line of code will replace that circuit.

If frequency is important too then the code for your needs isn't difficult but we need more info to give you more guidance.
 

RPLaJeunesse

Joined Jul 29, 2018
104
With 1M Ohm and 60pF the RC time constant is 60us. Oscillator period will be in the vicinity of 100us -150us (sorry, not going to canculate it) so 6-10 KHz, way more than 14Hz. There is info online to change the PWM frequency up from the native Arduino Atmega328 PWM values (480 & 960 Hz). It requires about 2-3 added lines of code to change the counter's clock prescaler from 64 to a lower number, typically 8 or 1. Take a look at https://arduinoinfo.mywikis.net/wiki/Arduino-PWM-Frequency
 

Irving

Joined Jan 30, 2016
814
I did mean kHz but it should be 12kHz.

time-period for voltage change from 33% to 66% and vice versa is 0.7RC so frequency is 1/(2 * 0.7 RC) = 10e6/(1.4 x 60 x 1) = 11.9kHz

I did it in my head quickly before and used 0.6 rather than 0.7 as the multiplier which gives 13.8kHz...

Doh!


But does it need to be such a high frequency? That can take a lot of resources out of a Arduino, even interrupt driven, depending on what else is required.
 
Last edited:

Thread Starter

MAINAHNOUD

Joined Jul 24, 2019
60
If my math is correct that generates a square wave at 14Hz, but there's no variable element there.

Arduino generates PWM natively at about 500Hz so if duty cycle is the only important thing then one line of code will replace that circuit.

If frequency is important too then the code for your needs isn't difficult but we need more info to give you more guidance.
Yes the frequa
If my math is correct that generates a square wave at 14Hz, but there's no variable element there.

Arduino generates PWM natively at about 500Hz so if duty cycle is the only important thing then one line of code will replace that circuit.

If frequency is important too then the code for your needs isn't difficult but we need more info to give you more guidance.
Yes the frequency is important
Could you tell me in steps what should I do?
 

Irving

Joined Jan 30, 2016
814
Yes, I can. But we need more information about what you're doing with this. Normally with PWM it's the duty cycle (on/off ratio) that's important, not frequency. Such high frequencies are normally associated with power conversion which is a very specialised area andyou wouldn't generally use a uController to generate it. Why is frequency important here? What are you using the PWM for?
 

Thread Starter

MAINAHNOUD

Joined Jul 24, 2019
60
Yes, I can. But we need more information about what you're doing with this. Normally with PWM it's the duty cycle (on/off ratio) that's important, not frequency. Such high frequencies are normally associated with power conversion which is a very specialised area andyou wouldn't generally use a uController to generate it. Why is frequency important here? What are you using the PWM for?
I use pulses signal to switch mosfet
 

Alec_t

Joined Sep 17, 2013
11,414
And what is the MOSFET controlling? If it's a motor or lamp or solenoid then normally the PWM frequency would be a good bit lower than 12kHz.
 

Irving

Joined Jan 30, 2016
814
Ah, so this is part of a battery charger set-up. An Arduino is the wrong approach here, except as a supervisor for a proper SMPS chip that is better able to manage the PWM and has appropriate loop control for constant voltage and/or current regulation and protective current limit sensing.

Can you explain what you want to achieve overall? What sort of battery chemistry & voltage/capacity, what is the battery supplying power to, and what is it charging from?
 

Thread Starter

MAINAHNOUD

Joined Jul 24, 2019
60
I want to convert analog control to digital control to consume less power cause opamp is hungry power device. Also, my system is energy harvesting so the power consumption is more important
 

Alec_t

Joined Sep 17, 2013
11,414
What are you harvesting energy from? Many sources are such low power that any battery charging current would be miniscule, so PWM would hardly be justified.
 

Irving

Joined Jan 30, 2016
814
What are you harvesting energy from? Many sources are such low power that any battery charging current would be miniscule, so PWM would hardly be justified.
Yes, especially as that circuit given by the OP, if using the specified op amp, uses < 10uA @ 6v! 60uW is hardly 'power hungry' and there's no way a digital solution will be any better.
 

Irving

Joined Jan 30, 2016
814
I think you need to explain the wider system to us. Its impossible to advise on something this complex in a piecemeal fashion.

The opamp you've got there takes 200nA. The 1M resistor chains and the capacitor charging takes close to 6uA, the rest is an estimate of switching losses and drive to the next stage. I'd imagine the switching losses in the MOSFET and inductor (if this is an smps ) will be a bigger problem.

Suggest you look the new ranges of nanoWatt all-in-one smps chips from the likes of TI and Maxim designed for wearable solutions as a better option...
 
Top