SuperHouse / esp-open-rtos

Open source FreeRTOS-based ESP8266 software framework
BSD 3-Clause "New" or "Revised" License
1.52k stars 491 forks source link

Initial HW PWM (Delta-Sigma) #609

Closed Zaltora closed 6 years ago

Zaltora commented 6 years ago

Hi, it is a HW PWM driver (WIP) I will do test with signals soon.

flannelhead commented 6 years ago

Looks like a great addition to the OS.

One nitpick: before merging, you might want to pay attention to naming. AFAICT the HW functionality that is used here is actually a delta-sigma modulator. Delta-sigma modulation is not pulse width modulation but rather pulse frequency modulation where the pulse width is constant and the frequency is altered. See e.g. this figure.

It would be good to check the actual output signals. I could do it later this month if my logic analyzer is sufficient for that.

Zaltora commented 6 years ago

Yeah, i think i will rename thing to be clear. (was planned, now i valid!) I will check tomorrow with an oscilloscope.

When you set duty, in fact you change frequency. The target mentioned here:

// Freq = (80,000,000/prescale) * (target / 256) HZ           (0   < target < 128)
// Freq = (80,000,000/prescale) * ((256 - target) / 256)  HZ  (128 < target < 256)

I will rename functions name too.

Zaltora commented 6 years ago

After test, I see Delata-sigma signal is very sensible to capacity line: Test with a low target and a prescale of FF: img_20180417_132945

Change target from 0 to 255 change my voltage ouptut from 0V to 3.3V. Measurement done with (x1) sensor. I will do test next week with (x10). It is feel easy do use it like a DAC. Tested on 2 different pin. The signals change between them because of different capacity. peek-to-peek is increase for one pin. the signal is not proper, increase prescale will linearized more the signal i guess... I understand why the max target i can get is 127 to control my motor. I got a transisor with Vgs between 1 and 3 volt.

Don't test it with a logic analyzer, you will get strange result.

I am not sure if the formula here is good:

// Freq = (80,000,000/prescale) * (target / 256) HZ           (0   < target < 128)
// Freq = (80,000,000/prescale) * ((256 - target) / 256)  HZ  (128 < target < 256)

because voltage increase close to a linear way . Or maybe the frequency decrease after 128 but voltage still increase.

Zaltora commented 6 years ago

Second test:

Zaltora commented 6 years ago

I will do a last test tomorrow to see what happen when the CPU clock is at 160MHz

Zaltora commented 6 years ago

I have test at 160MHz, nothing changes. All good for me :) until someone want improves the library.