PWM and duty cycle on MKR1000

Hej
I Have an arduino which gets an input sinus wave signal from an waveform generator, and from this i want to get a PWM duty cycle on an oscilloscope.
I have filteret the frequency and also calculated the voltage. But i am not sure how to get PWM signal.

Hi @laura_lomholt

It's possible to generate a PWM output signal by using Arduino's analogWrite() function. You just need to specify the digital pin number and duty-cycle value:

This generates a fixed frequency signal at 732Hz. If you require a different frequency, that's also possible, but requires setting some of the microcontroller's registers.

Hey
Yes that's also what i have read from a lot of different websides. But i want the duty cycle to depend on current, which i have calculated from the frequency.

Hi @laura_lomholt

In you initial post you mentioned that you receive, filter and calculate the voltage of the incoming sine wave.

Please could you explain what you mean by your requirement that the duty-cycle should depend on the current?

Oh sorry, i dont use the voltage for the pwm. only the current, which my code calculates based on the frequency. the frequency i get from a wave generator, so if i change the frequency on the wave generator from 50 to 60. it is a new PWM. but i dont want to change the frequency in the code. i want it to happen when i change it on the wavegenerator. thus from the input.

Hi @laura_lomholt

So are you using the PWM to control the average voltage and current fed to a load or some sort of device?

hey sorry, i figured it out. thanks for your help