how can I use function analogWrite() to write voltage to in certain times/s

Hi I'm Noob here, also noob about Arduino board, help needed.

now I have a project about sending and receiving message on Arduino mkr 1010 board at a certain speed, sampling rate I mean. and I get trouble about analogWrite() and analogRead() like below:

  1. I would like to use function analogWrite() to change the voltage at the analog output port, say 100 or 200 times per second. How can I do that?

  2. Also use function analogRead() to get the voltage at the analog input port, say 100 or 200 times per second. Is it the same as analogWrite()?

could anybody help me about this, Thanks a lot. :art:

  • You can use tone() down to 31Hz
  • Says here you can analogRead() 10k times a second
  1. I would like to use function analogWrite() to change the voltage at the analog output port, say 100 or 200 times per second. How can I do that?

By performing an analogWrite 100 or 200 times a second.

Unlike a lot of the earlier Arduino boards the MKR1010 has a true digital to analogue converter, 10 bits, and so has a true analogue output. Without this you have to use PWM and an external filter.

  1. Also use function analogRead() to get the voltage at the analog input port, say 100 or 200 times per second. Is it the same as analogWrite()?

Yes.

neiklot:

  • You can use tone() down to 31Hz
  • Says here you can analogRead() 10k times a second

Hi Neiklot Thanks a lot for answering me. But I still get problem.

As for 1, I just tried it. Say I called tone(A0, 1200, 20)(A0 is my DAC output, 1200 is the frequency, 20 ms), and then I called the analogwirte() to write voltages to A0. But result was the same as even if I didn't call tone()
or not.

As for 2, it says the max is 10k times/s, but I still want 100 or 200 times/s.

Grumpy_Mike:
By performing an analogWrite 100 or 200 times a second.

Unlike a lot of the earlier Arduino boards the MKR1010 has a true digital to analogue converter, 10 bits, and so has a true analogue output. Without this you have to use PWM and an external filter.
Yes.

Hello Grumpy, I'm very appreciate it for answering me.

as for the PWM, when I write sinusoidal waveform on the DAC port, the waveform looks like a sin wave on oscilloscope, you know up and then down, when I enlarge the time/div, I can see it is PWM clearly.

if using filter, could you tell how can I make it? Thanks a lot.

shengping:
as for the PWM, when I write sinusoidal waveform on the DAC port, the waveform looks like a sin wave on oscilloscope, you know up and then down, when I enlarge the time/div, I can see it is PWM clearly.

Your statement is full of contradictions. The DAC pin does not output pwm, so you would not see pwm. If you are not using the DAC pin, only a pwm pin without a filter, you would see only pwm and would not see a sine wave.

I think you should post a schematic showing what is attached to the Arduino and where the 'scope probes are attached. Also the test code that is running, in code tags. Some screen grabs from the 'scope or pictures of the 'scope screen would also be helpful, showing the signals you mentioned.

PaulRB:
Your statement is full of contradictions. The DAC pin does not output pwm, so you would not see pwm. If you are not using the DAC pin, only a pwm pin without a filter, you would see only pwm and would not see a sine wave.

I think you should post a schematic showing what is attached to the Arduino and where the 'scope probes are attached. Also the test code that is running, in code tags. Some screen grabs from the 'scope or pictures of the 'scope screen would also be helpful, showing the signals you mentioned.

Thank you for pointing my wrong statement out. I wrongly understand the DAC.