Author Topic: High frequency (50kHz) 16 bit PWM  (Read 1428 times)

0 Members and 1 Guest are viewing this topic.

Offline BennoGTopic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: nl
High frequency (50kHz) 16 bit PWM
« on: September 21, 2024, 07:14:55 am »
For the led light of a camera setup I want to use a pwm signal to adjust the brightness of the led's
The shutter time of the camera is between 1 and 10 ms. It is a camera with a global shutter and no trigger input.
This is to have at least 50 led flashes during the 1 ms exposure. Because of the missing trigger input the PWM signal must be on for about 50 ms.
The best I can do with pars I have is 10 bits at 48 khz (50 Mhz 10 bit counter input)
Are there options besides using a variable DC (DAC -> Amplifier)

Benno


 

Online ArdWar

  • Frequent Contributor
  • **
  • Posts: 668
  • Country: sc
Re: High frequency (50kHz) 16 bit PWM
« Reply #1 on: September 21, 2024, 07:36:35 am »
The "normal" way to do this is to current control the first 3 or 4 MSB and PWM the rest. Even then you still need 100s of MHz clock.... Do you really need that much dynamic range? Why that high of a frequency? Why 50 flashes?
« Last Edit: September 21, 2024, 07:48:19 am by ArdWar »
 

Offline PGPG

  • Regular Contributor
  • *
  • Posts: 182
  • Country: pl
Re: High frequency (50kHz) 16 bit PWM
« Reply #2 on: September 21, 2024, 07:39:35 am »
I don't understand why you need LED flashes during exposure and can't drive LED with PWM passed through low pass filter?
 

Offline BennoGTopic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: nl
Re: High frequency (50kHz) 16 bit PWM
« Reply #3 on: September 21, 2024, 07:58:47 am »
Do you really need that much dynamic range?

I can get away with the 10 bits I have now, was curious if it was possible to extend.
In the really low (pwm 1-5) the steps are very noticable. (even 10 or 20 % per step)

Why 50 flashes?

I don't have exact control over when the camera shutter starts and stops. So if I have at least 50 flashes during the 1 ms exposure I chan have max variation of 2% in brightness of the image. Between the individual camera captures.



 

Offline BennoGTopic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: nl
Re: High frequency (50kHz) 16 bit PWM
« Reply #4 on: September 21, 2024, 08:05:10 am »
I don't understand why you need LED flashes during exposure and can't drive LED with PWM passed through low pass filter?

Because I get a signal from the PLC and need to capture 2 images in fast sequence, with 2 different brightnesses.
So at the moment I set the PWM value that will change in 1/50000 of a second after the command. And then start the camera trigger by software. Between setting the PWM value and the CCD exposure starting is about 1 ms or even shorter (and probably not constant, the trigger is send over USB)
So the time is too short for LP filter to settle at a constant value during the exposure.

P.S. I can get away with the 10 bits I have now. Always on the lookout for a better solution.
 

Offline PGPG

  • Regular Contributor
  • *
  • Posts: 182
  • Country: pl
Re: High frequency (50kHz) 16 bit PWM
« Reply #5 on: September 21, 2024, 08:33:13 am »
I understand that having 50 pulses in exposure time and being not synchronized you have to assume 1 pulse error so 2%.
You set PWM with 0.1% accuracy (10 bit) and you are trying to improve it to get 0.0015% accuracy (16 bit) and then use this light with 2% accuracy. Did I missed something?
 
The following users thanked this post: Siwastaja

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 4280
  • Country: nl
Re: High frequency (50kHz) 16 bit PWM
« Reply #6 on: September 21, 2024, 08:34:52 am »
Did you do any calculations on this?

50kHz carrier with 16 bit PWM resolution based on a timer needs a clock frequency of 65536 * 50000 = 3276800000Hz. That is 3.2768 GHz. Even for a FPGA not an easy thing to handle.

I can get away with the 10 bits I have now, was curious if it was possible to extend.
In the really low (pwm 1-5) the steps are very noticable. (even 10 or 20 % per step)

Is this not due to properties of the LED's and might not improve with a higher resolution of the PWM granularity.

Offline BennoGTopic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: nl
Re: High frequency (50kHz) 16 bit PWM
« Reply #7 on: September 21, 2024, 08:42:18 am »
I understand that having 50 pulses in exposure time and being not synchronized you have to assume 1 pulse error so 2%.
You set PWM with 0.1% accuracy (10 bit) and you are trying to improve it to get 0.0015% accuracy (16 bit) and then use this light with 2% accuracy. Did I missed something?
Yes at really low intensities (PWM value between 1 and 10) you get noticeable steps due to the nonlinearity of our perception of brightness.
For the higher brightness this is accurate enough. (At the moment I do not need the lower PWM values, lowest in use now is 20 out of 1024). It is more to know there is a good solution when I need lower light values.

Benno
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 20417
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: High frequency (50kHz) 16 bit PWM
« Reply #8 on: September 21, 2024, 09:17:49 am »
If they are white LEDs intended for illumination, you may find the phosphor decay characteristics are important and work in your favour (for once!). Use a reverse biassed PIN diode, and observe the decay characteristics on a scope.

PWM can be done naively and cleverly. MCU PWM outputs are naive. It may be worth you understanding

But unless you need computer control, it is probably simplest to just use a PSU to set the current.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline BennoGTopic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: nl
Re: High frequency (50kHz) 16 bit PWM
« Reply #9 on: September 21, 2024, 09:54:36 am »
But unless you need computer control, it is probably simplest to just use a PSU to set the current.
That is the problem the PC needs to set the brightness and it should be stable within 1 ms.

 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 20417
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: High frequency (50kHz) 16 bit PWM
« Reply #10 on: September 21, 2024, 11:02:12 am »
But unless you need computer control, it is probably simplest to just use a PSU to set the current.
That is the problem the PC needs to set the brightness and it should be stable within 1 ms.

Apparently you only need two brightnesses, but to switch between them.

Have two slow speed DACs each controlling separate "DC" currents. Use a fast digital signal to divert the currents into either the LEDs or a different load.

Consider a long-tailed pair with the DAC controlling the emitter "tail" current. One collector would have the LEDs as a load, the differential signal on the base would direct the emitter current through one or other of the collectors.

In this diagram one collector resistor would be replaced by the LEDs. Ignore the marked voltage "outputs"; your output is the current into the LED


The current would be switched orders of magnitude faster than 1ms, so the LED response would dominate the timing.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12496
  • Country: ch
Re: High frequency (50kHz) 16 bit PWM
« Reply #11 on: September 21, 2024, 11:11:46 am »
I don't understand why you need LED flashes during exposure and can't drive LED with PWM passed through low pass filter?

Because I get a signal from the PLC and need to capture 2 images in fast sequence, with 2 different brightnesses.
So at the moment I set the PWM value that will change in 1/50000 of a second after the command. And then start the camera trigger by software. Between setting the PWM value and the CCD exposure starting is about 1 ms or even shorter (and probably not constant, the trigger is send over USB)
So the time is too short for LP filter to settle at a constant value during the exposure.

P.S. I can get away with the 10 bits I have now. Always on the lookout for a better solution.
You could divide the LEDs into two or more banks that you can control independently, adding another level of brightness control without needing more bits of PWM. (For example, alternate every LED between 2 banks, so that for lower brightnesses, you just disable one bank.)

Another thing you could consider is not using PWM, but some other encoding like PDM (pulse density modulation, which is almost the same thing as delta-sigma modulation). This would reduce the brightness error by spreading out the pulses within a 16-bit value.

It also seems to me you could use a DAC to control a constant-current LED driver. Modern audio DACs, for example, are often 24-bit at 48, 96, and 192kHz, more than enough. The question I don’t know off the top of my head is how long the latency is.
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 818
  • Country: ca
Re: High frequency (50kHz) 16 bit PWM
« Reply #12 on: September 21, 2024, 01:10:25 pm »
stmH7, stmG4 have HRTIM. G4 equivalent clock is >4 GHz, so 16-bits at 83 kHz PWM.
Nucleo-G474re is at mouser about $23 CAD.
 
The following users thanked this post: BennoG

Offline BennoGTopic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: nl
Re: High frequency (50kHz) 16 bit PWM
« Reply #13 on: September 21, 2024, 01:36:57 pm »
that looks interesting. Will have a look at this when i have some spare time.
 

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 4280
  • Country: nl
Re: High frequency (50kHz) 16 bit PWM
« Reply #14 on: September 21, 2024, 02:48:08 pm »
stmH7, stmG4 have HRTIM. G4 equivalent clock is >4 GHz, so 16-bits at 83 kHz PWM.
Nucleo-G474re is at mouser about $23 CAD.

This HRTIM is also mentioned in this thread but it comes with a lot of constraints, and is not a true high speed clock, but something with delay lines, so read the manual carefully before you decide to buy. A G474 board from weactstudio is ~7 euro on Aliexpress.

Offline BennoGTopic starter

  • Regular Contributor
  • *
  • Posts: 158
  • Country: nl
Re: High frequency (50kHz) 16 bit PWM
« Reply #15 on: September 21, 2024, 03:44:44 pm »
You could divide the LEDs into two or more banks that you can control independently, adding another level of brightness control without needing more bits of PWM. (For example, alternate every LED between 2 banks, so that for lower brightnesses, you just disable one bank.)

Another thing you could consider is not using PWM, but some other encoding like PDM (pulse density modulation, which is almost the same thing as delta-sigma modulation). This would reduce the brightness error by spreading out the pulses within a 16-bit value.

It also seems to me you could use a DAC to control a constant-current LED driver. Modern audio DACs, for example, are often 24-bit at 48, 96, and 192kHz, more than enough. The question I don’t know off the top of my head is how long the latency is.

That would limit the flexibility of the device I want it to be. At the moment it is 2 recording with vastly different lightning settings.
My experience is that if you develop something with limits you will run into them at a later moment when you want to reuse the same device then find it can not meet the requirements forcing you to do the same thing again.

This post is for me a investigation if there are other possibilities using a microcontroller and a Fast Mosfet driver to drive the switching mosfet.
This is to make the device as flexible as possible so it can be reused
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 20417
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: High frequency (50kHz) 16 bit PWM
« Reply #16 on: September 21, 2024, 04:37:00 pm »
This post is for me a investigation if there are other possibilities using a microcontroller and a Fast Mosfet driver to drive the switching mosfet.
This is to make the device as flexible as possible so it can be reused

Yes there is at least one; see my earlier post.

No fast MOSFETs needed. Only low-speed DACs/current sources, and ordinary BJTs operating in a mode that is known for its excellent high frequency performance. Turning the LEDs on/off only requires a <1V swing.

Plus, since the current is constant (it goes through either one or the other BJT), there is minimal EMI/EMC. That's relevant if the LED current is high (you don't state the current).
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6207
  • Country: es
Re: High frequency (50kHz) 16 bit PWM
« Reply #17 on: September 21, 2024, 04:58:09 pm »
Why not use constant current control?
I think it would be way easier, using a dac or digital interface to adjust the CC controller.
Though 16 bit resolution seems overkill, I don't think you need so much fine control for lighting?
« Last Edit: September 21, 2024, 05:02:01 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 3951
  • Country: ua
Re: High frequency (50kHz) 16 bit PWM
« Reply #18 on: September 21, 2024, 05:12:04 pm »
50 kHz PWM is very low frequency, not high.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4662
  • Country: dk
Re: High frequency (50kHz) 16 bit PWM
« Reply #19 on: September 21, 2024, 05:33:07 pm »
50 kHz PWM is very low frequency, not high.

it is if you want 16 bit resolution at the same time ...
 
The following users thanked this post: pcprogrammer

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6207
  • Country: es
Re: High frequency (50kHz) 16 bit PWM
« Reply #20 on: September 21, 2024, 06:18:06 pm »
Yep, would need a crazy 3.2GHz base clock (50KHz * 65536 steps)
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 3951
  • Country: ua
Re: High frequency (50kHz) 16 bit PWM
« Reply #21 on: September 21, 2024, 07:27:44 pm »
Using 1-st order 1-bit Delta-Sigma Modulator you can get 16 bit with oversample 2048x. For 48 kHz sample rate it needs 98.304 MHz clock.
Using 1-st order 4-bit Delta-Sigma Modulator you can get 16 bit with oversample 512x. For 48 kHz sample rate it needs 24.576 MHz clock.

Using 2-nd order 1-bit Delta-Sigma Modulator you can get 16 bit with oversample 128x. For 48 kHz sample rate it needs 6.104 MHz clock.
Using 2-nd order 4-bit Delta-Sigma Modulator you can get 16 bit with oversample 64x. For 48 kHz sample rate it needs 3.072 MHz clock.

But 2-nd order DSM is unstable and can produce artifacts.

Its better to use DSM with 4-bit DAC.



« Last Edit: September 21, 2024, 07:59:32 pm by radiolistener »
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12496
  • Country: ch
Re: High frequency (50kHz) 16 bit PWM
« Reply #22 on: September 24, 2024, 04:39:47 pm »
50 kHz PWM is very low frequency, not high.
No it isn’t. You’ve clearly not noticed the many threads where people think an Arduino’s 490Hz default PWM is more than enough, because they remember that 60Hz is enough for moving images.

As someone who is sensitive to slow PWM flicker, it always bugs me when people want to use anything below around 3KHz.

Note that the PWM frequency isn’t the clock frequency used to generate the PWM. That is the PWM frequency multiplied by the number of bits.
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 818
  • Country: ca
Re: High frequency (50kHz) 16 bit PWM
« Reply #23 on: September 24, 2024, 04:47:04 pm »
.....
Its better to use DSM with 4-bit DAC.

 Totaly agree. Have you mind to show a circuits/ schematics? Have you ever build DSM, or know somenone who did?
Otherways copy/ paste wikipedia quatation is not really helpfull.
 

Offline mtwieg

  • Regular Contributor
  • *
  • Posts: 240
  • Country: us
Re: High frequency (50kHz) 16 bit PWM
« Reply #24 on: Yesterday at 12:16:58 pm »
Do you really need that much dynamic range?

I can get away with the 10 bits I have now, was curious if it was possible to extend.
In the really low (pwm 1-5) the steps are very noticable. (even 10 or 20 % per step)

Why 50 flashes?

I don't have exact control over when the camera shutter starts and stops. So if I have at least 50 flashes during the 1 ms exposure I chan have max variation of 2% in brightness of the image. Between the individual camera captures.
I don't know much about photography and modern cameras, but is variation in luminous output within the exposure not a concern?

Anyways, if all you need is high precision (as opposed to high accuracy), then I would suggest looking at using a microcontroller with special high precision pwm. C2000, STM32, and Kinetis V MCUs have such special peripherals (need to be careful though, not all devices have them). Though using these peripherals is generally far more complicated than your basic pwm on an arduino. The Nucleo board suggested by MasterT above may be a good start, hopefully they offer a good example project for setting up the HRTIM.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf