Author Topic: Generating a "good enough" 10kHz sine wave from a square one  (Read 4356 times)

0 Members and 1 Guest are viewing this topic.

Offline mawyatt

  • Super Contributor
  • ***
  • Posts: 3334
  • Country: us
Re: Generating a "good enough" 10kHz sine wave from a square one
« Reply #25 on: July 09, 2022, 10:34:39 pm »
Just remembered (memory is fading) an old EDN article that might be useful. The output could be selected as a triangular wave and the filter with a lower corner, which may produce acceptable sine waves rather the triangular. Circuit was shown on front cover for 92 and 93 on EDN Design Ideas.

Best,
« Last Edit: July 09, 2022, 10:37:57 pm by mawyatt »
Curiosity killed the cat, also depleted my wallet!
~Wyatt Labs by Mike~
 

Online gf

  • Super Contributor
  • ***
  • Posts: 1247
  • Country: de
Re: Generating a "good enough" 10kHz sine wave from a square one
« Reply #26 on: July 10, 2022, 10:00:38 am »
Right now, the team is discussing adding one more analog sensor, which would require the use of another one or two ADC channels, making it next to impossible to use the technique we were just discussing.

Another option could be to use a Stereo Audio Codec IC for the analog output and input.
Most of them are intended for 16-bit or 24-bit audio, and have have a high dynamic range and low distortion.
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 14292
  • Country: de
Re: Generating a "good enough" 10kHz sine wave from a square one
« Reply #27 on: July 10, 2022, 11:54:46 am »
One could still measure the sensors one at a time, measuring the phase relative to the PWM. The phase of the excitation relative to the PWM would than be 1 extra measurement if common excitation is used.
The measurments would not be at the same time, but this could still be good enough.

An external ADC would be an option. Besides ADCs for audio, there are also ADCs made for power metering that may be interesting (e.g. MCP39xx series)). Some metering chips can also directly calculate the phase - so they have ADCs and the math inside.
Feeding an audio codes could be demanding for the relatively small µC.
 

Offline robcaTopic starter

  • Frequent Contributor
  • **
  • Posts: 257
Re: Generating a "good enough" 10kHz sine wave from a square one
« Reply #28 on: July 10, 2022, 05:02:35 pm »
Right now, the team is discussing adding one more analog sensor, which would require the use of another one or two ADC channels, making it next to impossible to use the technique we were just discussing.

Another option could be to use a Stereo Audio Codec IC for the analog output and input.
Most of them are intended for 16-bit or 24-bit audio, and have have a high dynamic range and low distortion.
Yep, but we are trying to avoid using additional ICs. Especially ones that would lock us into a device that might have availability issues. While even using a specific opamp is potentially risky, a programmable chip is the worst: if that chip becomes hard to get, any replacement would require a different firmware.

The goal is to use only the nRF52840, passives and opamps. All things that are (relatively) easy to second source
 

Offline robcaTopic starter

  • Frequent Contributor
  • **
  • Posts: 257
Re: Generating a "good enough" 10kHz sine wave from a square one
« Reply #29 on: July 13, 2022, 04:45:43 pm »
To contribute back to the community, I posted sample code to generate a square wave on the nRF52840 using timers and PPI, and use the comparator to get the phase delay https://github.com/robcazzaro/nRF52_sample_code. Clearly useful only for nRF52 family chips, but I could not find an existing example on how to tie everything together. Using PPI, the entire process happen in hardware, and the updated delay value is always available in the timer CC5 register
 

Offline jwet

  • Frequent Contributor
  • **
  • Posts: 463
  • Country: us
Re: Generating a "good enough" 10kHz sine wave from a square one
« Reply #30 on: July 15, 2022, 02:29:48 am »
And in the end, you ended up where you started.  I hope it was an entertaining detour at least.  The best design is the one that does what you need.  What you came up with is pretty clean.  As far as parts availability- it will be a cold dark day after the Zombie apocalypse.  Use any low voltage dual op-amp, there are thousands and they all share a pin out.  I generically put an LM358 in SO-8 for my layout but the actual part can be anything.  Well done- enjoyed it from my end.
 

Offline robcaTopic starter

  • Frequent Contributor
  • **
  • Posts: 257
Re: Generating a "good enough" 10kHz sine wave from a square one
« Reply #31 on: July 15, 2022, 03:33:48 pm »
And in the end, you ended up where you started.  I hope it was an entertaining detour at least.  The best design is the one that does what you need.  What you came up with is pretty clean.  As far as parts availability- it will be a cold dark day after the Zombie apocalypse.  Use any low voltage dual op-amp, there are thousands and they all share a pin out.  I generically put an LM358 in SO-8 for my layout but the actual part can be anything.  Well done- enjoyed it from my end.
Oh, no, actually I ended up in a much better place than I started, thanks to the help I got for all of you :) sorry if I gave the wrong impression

I now have 2 working versions, one using the ADC and one using the comparator. I just posted the code sample for the timer/comparator one because there was no example and I used techniques that don't have many examples in the Nordic SDK. I also think it's a relatively elegant use of the nRF52 functions done purely in hardware, and hopefully it will help other people. I didn't post the ADC/DSP solution which incidentally is more portable to other processors, because capturing a signal with an ADC is a trivial piece of coding and the necessary DSP code was already posted here and working well.

I learned a ton, and have 2 working solutions from which to choose, depending on how the sensor will be used in future boards/devices. I couldn't be happier :)
 
The following users thanked this post: jwet


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf