Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Sine wave


  • Please log in to reply
13 replies to this topic

#1 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 13 March 2014 - 05:14 PM

Hi.  I was wondering if anyone can enlighten me on how to go about creating a 26khz sine wave with a Netduino?  Also, is the ND's DAC fast enough to sample/measure a responding wave with this frequency?

 

Sorry if my question doesn't make sense.  My strengths are more with coding... I'm not 'tuned in' to the electronics as much.

 

Thanks!

Terry



#2 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 14 March 2014 - 12:41 AM

After further research, it looks like I am going to use the 50% duty cycle PWM with a 40us period to produce an approximate 25.5kHz square wave instead of a true sine wave.

 

 

I am using the output to drive an antenna.  I additionally need to READ a responding wave at the same frequency and measure the phase shift.

 

Can the Netduino do this?  The specification looks like the ND is 5000 times faster than this frequency...  but, can I access and the analog or digital pins fast enough to measure phase shift somehow?



#3 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 14 March 2014 - 05:29 PM

It's not clear to me what do you mean as "I am using the output to drive an antenna". I suppose the sine wave is the signal to be modulated (e.g. AM, FM or whatever), and the antenna will actually irradiate a high-frequency modulated carrier (e.g. 868 MHz).

If you inject a square wave, you'll also inject a lot of harmonics. That is, the fundamental sine wave at 25.5KHz, then the third (3x the frequency, at one third of amplitude), then the fifth (5x the frequency at 1/5 of amplitude, etc). As you may see, the decay is very slow, hyperbolic, as 1/N.

 

You'd need a "well shaped" sine wave, but with Netduino is almost impossible to do (unless you hack the firmware). If you had an Arduino, probably the goal would be easier to reach. However...how would you shape it? The best way is maybe issuing the "sampled sine" from a table, at a very tight interval. Let's say to split the full sine (2*PI) in 8 or 16 slices, thus the sample frequency should be 8x or 16x. Could a 16MHz chip achieve a so fast loop table-lookup?

 

Another suggestion might be to add some hardware to your circuit. Suppose to design and create an high-pass active filter, which cuts any harmonics but the fundamental. At that point the Netduino PWM output is trimmed, trimmed and trimmed, and the result is a good sine wave.

The hardware is not trivial, and I believe it's not for electronics beginners.

 

If your deal is some kind of modem (MO-dulator and DEM-odulator), the successful option is in favor of any DSP-enabled MCU.

There are plenty, but...again...you'd need some practice on DSP math (not so trivial).

 

Just a question: how long should last the supposed sine wave? Is it a endless signal, or rather a pulsed pattern (e.g. some encoding)?


Biggest fault of Netduino? It runs by electricity.

#4 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 14 March 2014 - 06:11 PM

Hi Mario!  Thank you for the reply.

 

Sorry... I knew I was struggling trying to describe my intentions.

 

My end goal is to try and make a metal detector... I figured this would be a fun project to help me (and anyone else interested) learn some fundamental concepts of Transmitters/Receivers!

 

I would like to see if the ND could be used to generate a signal then read the response amplitude and phase shift from a returned signal.

 

My starting point is the transmitter.  I was thinking of trying to use a PWM output and SOMEHOW converting this to an AC square wave (instead of 0-3.3V, perhaps convert this to +-12V or even +-5V.  Do you know of any devices that can assist in doing this?

 

Thank you!



#5 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 14 March 2014 - 08:18 PM

Recently, the local "radio shack" offered one of those wood/metal beam and AC detector units for only 5 dollars - you know, the kind of device used to find beams inside your walls. Maybe you could find a cheap one and hack it?

#6 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 14 March 2014 - 08:36 PM

Thanks, Hazibal.  That's definitely an option.   :)

 

But, my goal is to see how much I can do with the ND... I'm not so much about the end result as how to get there!



#7 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 15 March 2014 - 04:51 AM

Recently, the local "radio shack" offered one of those wood/metal beam and AC detector units for only 5 dollars - you know, the kind of device used to find beams inside your walls. Maybe you could find a cheap one and hack it?

 

That's interesting, but a metal detector works based on a different principle.

The AC detector is pretty simple: it detects the AC voltage leveraging a capacitive coupling. Since the voltage is high, even a small coupling will have a noticeable effect. All is tuned on the 50/60 Hz.

 

As seascan tells, a metal detector is much more complex. There's a huge coil creating a magnetic field, and when something enters in the field, the inductance of the coil changes a little. The goal is measuring the inductance, and the phase shift.

I don't think it's an easy project, aside the Netduino itself. However, the easier way to approach is using a DSP, because that's the most successful way to "surrogate" the analog hardware using a programmatic approach. Once the core sensor is done, you may interface it with the Netduino.

 

Good luck.


Biggest fault of Netduino? It runs by electricity.

#8 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 15 March 2014 - 07:45 AM

That's interesting, but a metal detector works based on a different principle.
The AC detector is pretty simple: it detects the AC voltage leveraging a capacitive coupling. Since the voltage is high, even a small coupling will have a noticeable effect. All is tuned on the 50/60 Hz.

The device actually did both with three separate indicator LEDs for wood beams, metal beams and for cables carrying AC. Naturally, it was very simple and can't compare with an actual metal detector.

#9 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 15 March 2014 - 07:58 AM

For just 5$ it worthwhile to try, that's for sure! That's because I think it's interesting.

 

BTW, our lab is mainly focused on wood drying controllers and related sensors.

I suppose the detector you've seen is based on the humidity (i.e. water) contained in the wood. Having such a detector would be pretty easy to prove it, by taking it closer to heating pipes, or even a simple glass of water.

In a professional drying context, the humidity value must be very accurate and reliable. There are basically two way to measure it: the resistivity (with a couple of nails), or the capacitance (by simple contact). However, the second solution is way less accurate. For a simple detector, might be suitable, though.

 

Do you have any link/specs about that detector?


Biggest fault of Netduino? It runs by electricity.

#10 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 15 March 2014 - 01:51 PM

I agree with the DSP approach.  PIC makes one that is somewhat user friendly but, that means learning WAY more than I intended... oh well, part of the fun I guess.

 

I have read that some detectors do use a square wave instead of a sine wave...  I am not sure if this is accurate information or not.  If it is then I was thinking that if I could use the PWM output coupled to SOMETHING to drive the AC wave then I could use two inputs to measure the phase shift.  One would read the PWM pulse and one the return signal.  Then measure the time delay between them.  Since they are both digital waveforms, I figure this would be a lot easier than trying to do the same with analog waves.



#11 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 15 March 2014 - 01:55 PM

There's not much info:
http://www.kjell.com...65-a2cf00ca0fb4

...but I got one so I could open it up and take som photos of the circuitry inside. Might be of help for seascan too.

#12 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 15 March 2014 - 11:39 PM

Okay...  let me ask about part 2 of all this:

 

IF a PWM wave of say 25KHz was driving the transmitter coil, is an ND2 fast enough to read say 8 points within the response.  So, the period is 40us.  To read 8 points would be a sample every 5us.  Can the Netduino reliably do this?  Based on this post  it looks doable.  Does anyone have any experience with high speed ADC with the Netduino?



#13 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 16 March 2014 - 05:35 AM

Okay...  let me ask about part 2 of all this:

 

IF a PWM wave of say 25KHz was driving the transmitter coil, is an ND2 fast enough to read say 8 points within the response.  So, the period is 40us.  To read 8 points would be a sample every 5us.  Can the Netduino reliably do this?  Based on this post  it looks doable.  Does anyone have any experience with high speed ADC with the Netduino?

 

Hmm...

First off, from where the "response" is meant to be taken? Either you have two coils, or more likely there's a single coil, and the phase-shift is between voltage and current. In any case, the very first problem is *how* to read the response...I mean what kind of hardware is needed to detect the phase shift.

 

Secondly, I don't think you're able to measure a so tight interval. That's essentially because the program runs over a managed framework, and the GC might start anytime. This leads to an unpredictable delay from an operation and another one.

The Stopwatch post is related to the internal precision of the timer, but all those precision is almost useless because the GC problem.

 

However, you may try to obtain a decent precision with the SPI-trick I've used for the Infrared transmitter.

You know, the code is managed, but the underlying low-level layer is managed natively, thus its reliability is far better. So, let's take your position: N=8 samples in a wave (although are too few for me). This leads to a sample rate of 25kHz * N.

Now, set the SPI clock rate as the best closer (actual) value as you desire, and also verify it with a scope. That's because the real clock rate is not always exactly what you set. If your "response signal" is readable as a normal boolean signal (first problem above), this can feed the MISO input.

 

Just as example:

 

            //no matters those params, but the clock rate
            SPI.Configuration config = new SPI.Configuration(
                SPI_mod: SPI.SPI_module.SPI1,
                ChipSelect_Port: Pins.GPIO_PIN_D10,
                ChipSelect_ActiveState: false,
                ChipSelect_SetupTime: 0,
                ChipSelect_HoldTime: 0,
                Clock_IdleState: false,
                Clock_Edge: true,
                Clock_RateKHz: ... //best value
                );


            var spi = new SPI(config);
            var outgoingBuffer = new byte[1024];
            var incomingBuffer = new byte[1024];

            spi.WriteRead(
                outgoingBuffer,
                0,
                1024,
                incomingBuffer,
                0,
                1024,
                0);
Then, right into the "incomingBuffer" you'll have a sampled pattern version of your response.
 
Why 1024 samples? Oh, just a random value...
Well, a full-wave period is roughly 40us. Suppose to set the SPI clock to 1MHz, you'll cover about 40 waves for a single buffer shot, and you have sliced a wave in forty samples, that is a resolution of 360/40 = 9 degrees.
But there's more...
since the sampling "window" is very short (should take about 1ms) you can consider the phase-shift "constant". This allows you to "super-sample" the data collected and gain other FIVE-bits! Five, because you have 40 waves to average, and every half is a bit gained.
At the end, you should measure the phase-shift with a (theoretical) resolution of 9 degs /40 = 0.225 deg! Although, I'd realistically expect about 5 degs because errors and other factors.
 
This solution is not a panacea, but it's very simple and effective. It's also worthwhile noting that the GC may *ALSO* run while the SPI is working, but as far as my experience is way less probable than in the high-level code, especially whereas the buffer is not very long (i.e. the transition lasts few time).
 
Do you like it better?

Biggest fault of Netduino? It runs by electricity.

#14 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 16 March 2014 - 01:50 PM

Oh wow.  It will take me a little bit to digest this but, at first glance this does look like the answer!

 

As for the coils, I am planning on  two separate coils.  One to transmit and one to receive.  Can two SPI channels be opened simultaneously?   I was thinking to use one for the Transmit and One for the Receiver and then compare them to find the phase shift.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.