kanflo / opendps

Give your DPS5005 the upgrade it deserves
MIT License
895 stars 124 forks source link

Add signal generator #148

Closed X-Ryl669 closed 5 years ago

X-Ryl669 commented 5 years ago

These commits add a signal generator (or function generator) to OpenDPS. It's accessible to a new screen (use SET button + ROT LEFT to see it). It's able to generate either a square signal, a saw signal or a sinus signal from 0.1Hz to 999Hz (although see below for usage).

In order to do that, I've added a new timer (TIM3) that's ticking each µs and interrupting after 65.536ms (where I'm accounting the overflow, since timer are 16bits only on STM32F1xx). With this, I get a 1µs resolution clock (by reading the timer's counter when required).

Then in the ADC's conversion done ISR, I'm calling the function generator callback (so it's ~20kHz update) to generate the next DAC output depending on the selected signal and frequency.

I've made some changes to the UI code to support Hz unit (in uui_number) and icons too (for selecting the signal type).

I've fixed some magic number to #define instead so it's easier to position the icons on the status bar

Quick remark on the functionality:

  1. Since the device is a power source, it has a huge capacitor on its output path. If you intend to use fast signal with this generator, you need to either reduce the voltage and/or have a large sink (a small resistor for example connected on the output), since when the voltage is decreasing, the load must consume the charge in the capacitor. With no load on the output, the signal will present a discharging slope. Please notice that I've not set any over current protection. So the system can source 5A on your load, make sure it's able to deal with it.
  2. This is not a professional generator and cranking up the frequency leads to less clear signal. At maximum frequency (1kHz, you can only get 20 points on the signal's curve). Yet, having a slow rising voltage system is useful and same for square signal for blinking led or whatever.
  3. Since no negative voltage are generated, if you need to use a sinus signal, then you should have a 2 identical resistors divider on the output path and use the midpoint as the new "ground" to get +/- voltage.

BTW, the initial code is very clean to work with, congratulations!

X-Ryl669 commented 5 years ago

This gives this screen: image

kanflo commented 5 years ago

Wow, that is awesome! Looking forward to testing the reviewing the coming week.

kanflo commented 5 years ago

Impressive, thanks!