Function Generators and Arduino

Forum for discussion of narrow-bandwidth mechanical television

Moderators: Dave Moll, Andrew Davie, Steve Anderson

Function Generators and Arduino

Postby FlyMario » Fri Sep 25, 2020 8:50 am

So I am building my new Mechanical TV and been working out the motor speed control.

The MTV has a Nipkow disk and instead of using an optical sensor like my last build, I am using a hall effect sensor which I hope cleans things up.

I have a GW Instek SFG-1013 Function Generator and I connected to Pin 2 of the Arduino Uno. I set the function generator to 12.5Hz and setup an interrupt on the Arduino.

The code is at the bottom of this post.

The Arduino is reporting 80,052 +/- a tiny bit. However, I expected 80,000. The reason I am doing this is to make sure I have a solid method of counting the motor speed so that if I get a lot of errors when I use my Hall Effect sensor I can most likely figure it is something on the sensor's end and not the Arduino.

I realize that 52 microseconds are nothing to be concerned about. I would probably accept 200+/- m/s. I just wonder if this is to be expected? Are Function generators that accurate? Mine was fairly cheap... think like $170 or so.

Thanks,
Peter J. Fischel

20200924_174243.jpg
20200924_174243.jpg (133.9 KiB) Viewed 1857 times

20200924_174318.jpg
20200924_174318.jpg (176.96 KiB) Viewed 1857 times



void setup()
{
Serial.begin(9600);
pinMode(hallPin,INPUT);
attachInterrupt(digitalPinToInterrupt(hallPin), hallInterrupt, RISING);
lastPulseTime = micros();
}

void loop()
{
Serial.println(delta);
delay(500);
}

void hallInterrupt()
{
pulseTime = micros();
delta = pulseTime - lastPulseTime;
lastPulseTime = pulseTime;
}
Peter J. Fischel
Mechanical TV Fan, Programmer and Tinkerer.
FlyMario
Master Craftsman
 
Posts: 51
Joined: Sat Sep 22, 2018 11:34 am

Re: Function Generators and Arduino

Postby smeezekitty » Fri Sep 25, 2020 11:39 am

The function generator is much more likely to be accurate than the cheap ceramic resonator on the Arduino
smeezekitty
Evil Genius
 
Posts: 197
Joined: Fri Jan 29, 2010 11:42 am
Location: USA

Re: Function Generators and Arduino

Postby Steve Anderson » Fri Sep 25, 2020 12:00 pm

smeezekitty wrote:The function generator is much more likely to be accurate than the cheap ceramic resonator on the Arduino

Agreed, ceramic resonators are generally accurate to about +/-0.5% whereas crystals, even the cheapest ones, are better than +/-50ppm, or 0.005%. Likewise the temperature sensitivity...

The GW Instek SFG-1013 Function Generator has a quoted accuracy of +/-20ppm, 0.002%, I'd trust that above anything using a ceramic resonator.

Why use ceramic resonators? 'Cos they're cheaper, though not by much. It's the old bean-counters (accountants), the bane of any engineers life.

Steve A.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4496
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Function Generators and Arduino

Postby FlyMario » Fri Sep 25, 2020 1:01 pm

Oh I see. Thanks! That's a bit good news! Happy to think my Frequency Generator is reasonably up to snuff.

I thought the Arduino Uno boards used crystals. Oh well, it's still accurate enough. Makes me want to perfboard a Atmega328 and use my 16mhz crystal resonators to see if I can improve it.

Thanks,
Peter J. Fischel
Peter J. Fischel
Mechanical TV Fan, Programmer and Tinkerer.
FlyMario
Master Craftsman
 
Posts: 51
Joined: Sat Sep 22, 2018 11:34 am

Re: Function Generators and Arduino

Postby FlyMario » Fri Sep 25, 2020 1:22 pm

https://www.amazon.com/gp/product/B00NQ82OM0/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
I have a lot of these. Are they really Oscillators or Resonators? Sometimes I see things that look like this called resonators. Sometimes I see crystal oscillator resonators... Why so confusing. :roll: Is there a way to tell?

I always liked the Crystal Clocks that had gnd, +5 and clk out. Seems I could trust them.

Peter J. Fischel
Peter J. Fischel
Mechanical TV Fan, Programmer and Tinkerer.
FlyMario
Master Craftsman
 
Posts: 51
Joined: Sat Sep 22, 2018 11:34 am

Re: Function Generators and Arduino

Postby Steve Anderson » Fri Sep 25, 2020 1:51 pm

They're standard ordinary crystals, they need an active circuit to get them going. Most micros have that built-in, and can use either crystals or ceramic resonators, certainly Microchips PIC series do, I would assume that the Atmel series are the same. Though you may need to set configuration bits (fuses?) within the device. Download the datasheet for the device used and see if it's possible. Others may be able to help here...

Or use an external oscillator as you mentioned, again configuration bits/fuses may need altering for an external clock source.

A typical example below, 16MHz, GND, +5V and output, about a US$1.50.

Steve A.

MO-22B-HALFSIZE.jpg
MO-22B-HALFSIZE.jpg (5.83 KiB) Viewed 1846 times
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4496
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Function Generators and Arduino

Postby FlyMario » Fri Sep 25, 2020 2:01 pm

Thanks. I just wanted to make sure I had the right type of Crystal OSC. I didn't want to build an Arduino and find out I had another resonator.


Peter J. Fischel.
Peter J. Fischel
Mechanical TV Fan, Programmer and Tinkerer.
FlyMario
Master Craftsman
 
Posts: 51
Joined: Sat Sep 22, 2018 11:34 am

Re: Function Generators and Arduino

Postby Steve Anderson » Fri Sep 25, 2020 2:13 pm

As an example here's the choices of clock source for a PIC16F688 which is used in the AD9833 oscillator project currently underway in another thread..

;----- CONFIG Options --------------------------------------------------
_LP_OSC EQU H'3FF8' ; LP oscillator: Low-power crystal on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
_XT_OSC EQU H'3FF9' ; XT oscillator: Crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKINT
_HS_OSC EQU H'3FFA' ; HS oscillator: High-speed crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
_EC_OSC EQU H'3FFB' ; EC: I/O function on RA4/OSC2/CLKOUT pin, CLKIN on RA5/OSC1/CLKIN
_INTOSCIO EQU H'3FFC' ; INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
_INTRC_OSC_NOCLKOUT EQU H'3FFC' ; INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
_INTOSC EQU H'3FFD' ; INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
_INTRC_OSC_CLKOUT EQU H'3FFD' ; INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
_EXTRCIO EQU H'3FFE' ; EXTRCIO oscillator: External RC on RA5/OSC1/CLKIN, I/O function on RA4/OSC2/CLKOUT pin
_EXTRC_OSC_NOCLKOUT EQU H'3FFE' ; EXTRCIO oscillator: External RC on RA5/OSC1/CLKIN, I/O function on RA4/OSC2/CLKOUT pin
_EXTRC EQU H'3FFF' ; EXTRC oscillator: External RC on RA5/OSC1/CLKIN, CLKOUT function on RA4/OSC2/CLKOUT pin
_EXTRC_OSC_CLKOUT EQU H'3FFF' ; EXTRC oscillator: External RC on RA5/OSC1/CLKIN, CLKOUT function on RA4/OSC2/CLKOUT pin

Spoilt for choice...if it were a PIC used and using an external clock oscillator the _CONFIG bits would be set by _EC_OSC (Fourth one down). I would assume Atmel devices have a similar arrangement.

It is possible that you could simply replace the crystal resonator with a 'proper' crystal (as you linked to before) without changing anything within the chips code, note the second and third lines above, it mentions both crystal/resonator, consult the appropriate datasheet for the Atmel device used...also note the frequency limits.

You may have to add two small capacitors (15-22pF), one each from each end of the crystal to GND, again consult the datasheet...when dealing with these devices at this hardware level, the datasheet is your 'bible', follow it diligently...and make sure you have the most recent version...

Steve A.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4496
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Function Generators and Arduino

Postby FlyMario » Fri Sep 25, 2020 3:01 pm

I don't know. Looking at my Arduino Uno it appears to me it has an actual Crystal in it. There are only two pins coming out the bottom.

MyArduinoUno.jpg
MyArduinoUno.jpg (120.77 KiB) Viewed 1838 times


If that is true, I don't think I can really do better on a protoboard / breadboard.

Kind of strange to me. If I am loosing 52 m/s per frame then that means I am loosing 650 m/s per second. That number just feels huge to me. Again with building a MTV that's not huge... just something I cant get my head around.

Re: Pic
The thing with Avr is that I am kind of invested along that line. So many of the Atmega328 chips and Attiny. I really enjoy those chips. I even have the ice debugger/programmer.



Thanks for your help.

Peter J. Fischel
Peter J. Fischel
Mechanical TV Fan, Programmer and Tinkerer.
FlyMario
Master Craftsman
 
Posts: 51
Joined: Sat Sep 22, 2018 11:34 am

Re: Function Generators and Arduino

Postby FlyMario » Fri Sep 25, 2020 3:05 pm

oh wait... is that the ceramic resonator... the six pinned tiny shiny can just above the atmega328? I wonder if that 16mhz crystal to the left is for driving USB and has nothing to do with the Atmega328. If so that is kind of lame.

Heh I never noticed that there is another atmega chip on my uno that they use for USB. The crystal oscillator to the left of the board is for that. But the workhorse ATMEGA328 gets a stupid ceramic resonator. LOL. Best get my protoboard out and build an arduino with a crystal.
Last edited by FlyMario on Fri Sep 25, 2020 3:30 pm, edited 1 time in total.
Peter J. Fischel
Mechanical TV Fan, Programmer and Tinkerer.
FlyMario
Master Craftsman
 
Posts: 51
Joined: Sat Sep 22, 2018 11:34 am

Re: Function Generators and Arduino

Postby Steve Anderson » Fri Sep 25, 2020 3:26 pm

Seeing that odd 6-pin device is very close to pins 9 & 10 (the xtal/resonator pins) that's probably to source of clock for the micro. Why six pins? No idea! Try and find a circuit diagram for this PCB and perhaps the mists will vanish...

Steve A.

Found the appropriate datasheet for the micro used...see page 12 for pinning info...



Interesting to note that I was able to upload and download more than 20Mb...perhaps the ISP has woken up to the real world?
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4496
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Function Generators and Arduino

Postby FlyMario » Fri Sep 25, 2020 3:44 pm

Yeah thanks! I ordered a couple of 16mhz clocks (cans). I do have the proper caps and 16mhz crystals already so will build an arduino to be more accurate. Would be hallarious to do that and then find all that accuracy and then find out the hall effect sensors throws out some instability.

Peter J. Fischel
Peter J. Fischel
Mechanical TV Fan, Programmer and Tinkerer.
FlyMario
Master Craftsman
 
Posts: 51
Joined: Sat Sep 22, 2018 11:34 am

Re: Function Generators and Arduino

Postby Steve Anderson » Fri Sep 25, 2020 4:08 pm

The variation, not the accuracy, in what you're seeing is most likely to be derived from the mechanics rather than the electronics. Though not accurate on frequency, crystal resonator oscillators are reasonably stable given a reasonably stable temperature environment and supply voltage. If the instability is short-term it's unlikely to be those two things.

The lengths mechanical clockmakers go to for accuracy is astounding, Google it, but here's one example...

https://www.theverge.com/2015/4/20/8456 ... rld-record

Steve A.

Hall-effect sensors are also subject to the woes of temperature and supply voltage, as is the magnet that is sensed, though temperature only, but again that's a long-term thing, not rapid.

In short, anything based on semiconductors is temperature sensitive as hard as manufacturers might try and design that factor out.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4496
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Function Generators and Arduino

Postby FlyMario » Fri Sep 25, 2020 4:40 pm

wow I am quite impressed! I connected the Hall Effect sensor to the Arduino and see a fairly stable output. +/- about 30 m/s. Not a number that I think is worthy of complaint. You do see a drift in the speed of the motor requiring increase and decrease in motor voltage. Right now the voltage is not being regulated by PWM. Something I will work on this weekend.
Peter J. Fischel
Mechanical TV Fan, Programmer and Tinkerer.
FlyMario
Master Craftsman
 
Posts: 51
Joined: Sat Sep 22, 2018 11:34 am

Re: Function Generators and Arduino

Postby Steve Anderson » Fri Sep 25, 2020 5:02 pm

A motor, depending on type has a temperature coefficient too, as it gets warmer the resistance of the copper windings alters which will affect its speed. Also bearing friction with speed with temperature. Hence anything requiring a constant stable speed is incorporated in some some of negative feedback loop. With all the mechanical varying factors it makes designing a stable system quite tricky. Throw in load variations (though maybe not important here) and air resistance, aerodynamics. I believe that Baird used some of his larger discs in a vacuum, or at least a partial one to help mitigate this.

Steve A.

Vacuum, the only word in the English language that I know of that has two adjacent 'u's...Scrabble or crossword players take note...
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4496
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Next

Return to Mechanical NBTV

Who is online

Users browsing this forum: No registered users and 9 guests

cron