SINUSOIDE proportional to the dutycycle of my PWM

Hello everybody,
I am an eingenering student and I just enter Inside Arduino world!
It is interisting and challenging. I dont have a lot of experience with the direct manipulation of microcontrollers but I programmeted in VHDL fpgq qnd I have knowleged of microeingenering.
I am doing a project regarding telecomunication, optical transmission. I am putting a signal Inside arduino I reqd it I trqnsmitted with a diodo led I receved it with a photodiodo. the signal trasmitted is a PWM. and I want demodulate it or let say I want to extract the sinusoide proportional to the duty cycle in order to obtain the message transmitted.
I really would like to use less possible hardward. I was thinking to obtain a PAM from the PWM in order to find with a RC circuit after the sinusoide but I have no idea how. I need a general help for this beautiful unfoundable ()for the moment) sinusoide!!!
I am using arduino micro, I prescaled the clock 16MHz to 8MHz. my sinusoide that I am transmitting is 50Hz with an amplitude from 0 to 5V.

Something like this?

http://interface.khm.de/index.php/lab/interfaces-advanced/arduino-dds-sinewave-generator/

yes exactly I have read it 1000 time.
I change it a little bit for arduino micro like in the micro there is not timer 2 and I change it in timer 4.
but int he file I have question that are:
I don't have interrupts in arduino micro, I am suppose to subsitute this difference?
Thanks a lot for quick replay :slight_smile:
I am writing bcs I have read all that it is written in the forum italian English and french
:confused:

The value of a pwm signal is equal to its duty cycle. The digital values of the duty cycle converted to a byte (Ton/T) then have the following correspondance to the phase angle: 0 deg=127, 90 deg=255, 270deg=0 that is asin(dutybyte/127-1). The trouble here is that both division and asin() are very processor intensive operations which cannot be performed in realtime (on an avr arduino at least). If T is fixed and known you can construct a lookup table to give you the phase vaules directly from Ton. The phase will have somme jitter but this can be handled by averaging the phase advance.

No my T it is not fixed... I was thinking that using DDS for a 50Hz frequency it is not the best way. maybe I have to understand how to compare the timer interrupt of the example with the one of arduino micro.. :frowning: :frowning:

Are you sure you can't use an Arduino with an ATmega328p processor like an UNO or Nano or Mini?

I can't, the arduino is not mine and they give me Arduino Micro to do it... I may had found one way to solve this problem, tomorrow I will work on it and I will write here if it is a good solution!

I did ssome modification of http://interface.khm.de/index.php/lab/interfaces-advanced/arduino-dds-sinewave-generator/
for arduino micro.
I am not sure it will work.. Can you see it?
I am using timer 4 instead of timer 2.

demodulo.ino (4.07 KB)

:slight_smile: :slight_smile: :slight_smile:
I don't know if you are interested but I change http://interface.khm.de/index.php/lab/interfaces-advanced/arduino-dds-sinewave-generator/ using timer 4 for arduino MICRO qnd it is working
I used the biggest prescaeler. just I need to wait the components for the RC to see if I will have my wonderfull sinusoide! :slight_smile: