# Make or buy a RC circuit?

Hello Arduino Forum.

I am experimenting with flatting out a PWM signal. I am thinking of using the PWM library and setting the PWM frequency to 1kHz:

``````#include <PWM.h>
int32:t frequency = 1000; //Hz

// and then in the loop function:
pwmWrite(Pin, Val)
``````

My problem is that I need to flatten out the signal or my Pizo might start to vibrate.
So my question is:

• Should I but a resistor (R) and a Capasitor(C) and solder my own LP-filter?
• Can I buy this as a neat small thing with input PWM and output smooth?

Thank you!

Also, side question: converting the PWM-signal to a smooth signal, is that what i DAC does, shoud I get one?

converting the PWM-signal to a smooth signal, is that what i DAC does,

No.

My problem is that I need to flatten out the signal or my Pizo might start to vibrate.

Do you mean smooth out the signal?

Should I but a resistor (R) and a Capasitor(C) and solder my own LP-filter?

Yes.

Can I buy this as a neat small thing with input PWM and output smooth?

Yes but you will need to know what cut off frequency you want. Indeed you will need to know what cut off frequency means. Along with the filter order. Low Pass filter

What frequency do you want this smoothed signal to change at?

http://www.thebox.myzen.co.uk/Tutorial/PWM.html

A piezo transducer is already a capacitor by its nature - you may only need a series resistor
to get low-pass filtering. Some experimentation needed of course.

Grumpy_Mike:
What frequency do you want this smoothed signal to change at?

PWM

So, I need to move my piezo quickly, take a picture and then move again.
I'd like a framrate of 200Hz. That means that after I take a picture, with a short short shutter speed, the piezo has less than 0,005s to move to a new position and become stationary.
The voltages I'd like to apply are 0,1,2,0,1V ...
So from the Arduino I write the voltages with PWM, and the piezo is connected in parallell with the capacitor. From your post I'd say I need a cut-off frequency of roughly 1kHz.

When it comes to the filter order i think 1st or 2nd should be adequate.
Could you provide a link to a online store? I have actually tried to google a lot.

MarkT:
A piezo transducer is already a capacitor by its nature - you may only need a series resistor
to get low-pass filtering. Some experimentation needed of course.

I wasn't aware of this. So your saying i could hook up the piezo directly to the PWM-port and to GND (Possibly with a resistor in between). I'm reluctant to trying it, since I might destroy my piezo if it doesn't work. Do you have any theory supporting this?

So, I need to move my piezo quickly, take a picture and then move again.
I'd like a framrate of 200Hz. That means that after I take a picture, with a short short shutter speed, the piezo has less than 0,005s to move to a new position and become stationary.

That is a whole new ball game and not at all what you asked in the first post. I also suspect that it is not going to happen.
What are you trying to do, this is coming across as a classic x-y problem.

So explain what you want to do and with what equipment and give a link to this piezo that looks like it has to move a camera. It doesn't sound like it is a project for an Arduino.

Grumpy_Mike:
That is a whole new ball game and not at all what you asked in the first post. I also suspect that it is not going to happen.
What are you trying to do, this is coming across as a classic x-y problem.

So explain what you want to do and with what equipment and give a link to this piezo that looks like it has to move a camera. It doesn’t sound like it is a project for an Arduino.

The piezo is not relevant for this post. (It does not move a camera, it moves a mirror which shift structured light)
I am searching for help on the design of a LP filter (or something else) that can smooth out a PWM-signal.
I’d like to send a constant 1V and 2V (seperately), sending a PWM square-wave does not work, I need the average value (duty cycle x 5V). I need the signal to converge in less than 5ms.

I thought of a RC circuit with t=RC=1ms, where R=100Ohm and C = 1uF.

Is it possible to buy this circuit?

Is it possible to buy this circuit?

Yes you buy the individual components.

I am searching for help on the design of a LP filter (or something else) that can smooth out a PWM-signal.

Yes but you do not have any specification to allow you to design it.
What is the acceptable ripple level?
How fast do you want the signal to move?
What PWM frequency do you want?

When it comes to the filter order i think 1st or 2nd should be adequate.

You have absolutely no foundation for saying this unless you plug in all the above numbers and see if that order of filter will do the job.

Is it not possible to use an I2C DAC?

Or switch to a SAM/SAMD based board since they have built-in DACs? I have not personally used this feature so take this with a grain of sodium-free salt substitute.

https://www.arduino.cc/en/Reference/AnalogWriteResolution

The Zero has the following hardware capabilities:

10 pins which default to 8-bit PWM, like the AVR-based boards. These can be changed to 12-bit resolution.
1 pin with 10-bit DAC (Digital-to-Analog Converter).

By setting the write resolution to 10, you can use analogWrite() with values between 0 and 1023 to exploit the full DAC resolution

gdsports:
Is it not possible to use an I2C DAC?

Great Idea!
I just bought this:

What fist bewilders me is which output channel from the Arduino I use as Input to the DAC.
I think the DAC want I2C (SLC/SDA) as input, but how do I provide/convert a given PWM (say 3V d=60%) to I2C.

A0 is the analog (flat/smoothed) output, right?

Run through the Adafruit tutorial for the board. You should be able to produce a triangle wave and sine wave at the DAC board VOUT pin. This ensures you have connected all the wires and soldered the pins correctly.

Read the datasheet and read the library source code to understand how it works.

I2C is a communications bus to the DAC chip.

Look at the source code for the triangle wave example.

``````dac.setVoltage(counter, false);
``````

The setVoltage function sends a message over the I2C bus to the DAC chip. The DAC chip then changes the voltage output based on the first parameter. Stop thinking in duty cycle and start thinking in voltage output. The program changes the output voltage from min to max then max back to min. Scope the DAC board VOUT pin. If you do not know how to use a scope, you are in over your head.