A Useful General Purpose Oscillator.

Anything not specifically related to NBTV, but at least of some technical nature that might be of interest to NBTV members. Items for sale and links to retailers do not belong here.

Moderators: Steve Anderson, Dave Moll

Re: A Useful General Purpose Oscillator.

Postby Andrew Davie » Thu Jun 25, 2020 6:45 pm

Andrew Davie wrote:
Steve Anderson wrote:Quickly banging out some PIC assembly code for 26-bit binary input multiplied by 34.3597 (decimal) results in a 32-bit output in 175 bytes of code executed in under 88us*. So nowhere near as efficient as the C-code example as provided by Andrew...there may be ways to improve it, but not by much...


... another thing -- if you only need 32 bits, that's a lot different than the 40 bits you originally asked for.
The C code could definitely be improved if fewer bits required.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1552
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Thu Jun 25, 2020 6:49 pm

If I were to choose a PIC18, that has a built-in multiply instruction, the 16s, 12s, and so on don't. So that could save instructions and time, but neither is really much of an issue.

But whatever, I think I see the writing on the wall, time to pull my finger out...

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

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Thu Jun 25, 2020 6:52 pm

Andrew Davie wrote:... another thing -- if you only need 32 bits, that's a lot different than the 40 bits you originally asked for.
The C code could definitely be improved if fewer bits required.


Yes 32 is enough, I only mentioned 40 as it usually wouldn't make much difference in PIC assembly, but if it does in C, then 32 bits it is...

Steve A.

The oscillator requires 5 bytes per instruction, 4 (32 bits) for the frequency, the 5th is phase and other stuff which I don't intend to use, i.e., just send 0x00..unfortunately you can't terminate the string early leaving out the 5th byte...but it makes no difference to the multiply routine...
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4252
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: A Useful General Purpose Oscillator.

Postby Andrew Davie » Thu Jun 25, 2020 9:45 pm

Using 32 byte arithmetic, the code inspection tells me that the 2nd variant is now 138 bytes.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1552
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Fri Jun 26, 2020 1:04 pm

Even using the shift-add-subtract method it's less than the PIC version now. It may be due to the much larger instruction set that Atmel devices have, some perhaps being optimised for C language - PICs do have that in the larger devices called "an extended instruction set'.

Sorry for the 'glich' r.e. the input/output bit sizes yesterday...

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

Re: A Useful General Purpose Oscillator.

Postby Andrew Davie » Fri Jun 26, 2020 1:13 pm

Steve Anderson wrote:Even using the shift-add-subtract method it's less than the PIC version now. It may be due to the much larger instruction set that Atmel devices have, some perhaps being optimised for C language - PICs do have that in the larger devices called "an extended instruction set'.

Sorry for the 'glich' r.e. the input/output bit sizes yesterday...

Steve A.


Generally, one doesn't have to worry too much about these size things anymore.
The ATmega32U4 (used in the Micro, which I used for the Arduinovisor) has 32 KB flash memory (with 4 KB used for the bootloader). It also has 2.5 KB of SRAM and 1 KB of EEPROM. You can get a fair bit of code into 28K. The "Pro-Micro" is the same thing, in a smaller package, and costing something around $2/unit.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1552
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Fri Jun 26, 2020 2:19 pm

Andrew Davie wrote:Generally, one doesn't have to worry too much about these size things anymore.

Agreed, even the MkI SSTV-625 up-convertor which used two PICs (one read, one write) used only 649 bytes for the write micro and 2,059 bytes for the read micro. Each have 64k bytes of program memory so most of it was unused real estate. The code was written in assembler.

At the start of that project I bought some micros with 128kB of program memory thinking I may need it - but obviously I didn't.

Steve A.

Memory usage map for the read micro follows, scroll to the end for memory summary...a few instructions are 32-bit...four variants in fact...

Code: Select all
MEMORY USAGE MAP ('X' = Used,  '-' = Unused)

0000 : XX------XX------ XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
00C0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0100 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0140 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0180 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
01C0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0200 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0240 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0280 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
02C0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0300 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0340 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXX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X XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0740 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0780 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
07C0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0800 : XXXXXXXXXXXX---- ---------------- ---------------- ----------------
0000 : -XXX-XX-XXXXXX-- ---------------- ---------------- ----------------

All other memory blocks unused.

Program Memory Bytes Used:  2059
Program Memory Bytes Free: 63477

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

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Thu Jul 23, 2020 7:26 pm

I'm still dwelling on this, how to make it user-friendly and keep it simple at the same time.

Part of the headache comes from the incremental value of 0.0291Hz, so the closest you could get to 1Hz would be around 1%. For a lot of applications that wound be 'near enough'. As the required frequency goes up the accuracy gets better - within the tolerance of the 125MHz crystal/oscillator used.

For an NBTV frame rate 12.5Hz would actually be 12.513Hz, an error of around 0.01%, good enough I would think. If divided down from 400Hz the line frequency becomes 399.9795Hz, 0.005%, more than good enough! 50 ppm, about the same as the crystal accuracy.

When I can I'll get on with this, I'm rather keen to see how it all works out!

It'll be interesting to see how accurate this is using my GPS disciplined oscillator/frequency meter combination. The GPS receiver & reference oscillator combination is quite affordable as a kit. PM me if interested - I don't want to be seen as advertising, though it's not me that would be supplying the kits. No commercial interest. US$41, you supply the case and simple 5V power supply. (7805 type of thing - not switched mode).

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

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Thu Jul 23, 2020 8:01 pm

Here's an example of the GPS data showing where the birds are plus a lot of other data not shown in this PDF...

The 'bite' out of the top (North) part is due to my location 13 degrees north of the equator. The further north you go the 'bite' gets bigger. In the southern hemisphere it's from the south...If you live in Singapore you won't even notice it! (About 1 degree north). Polar navigation (both) is almost impossible with GPS.

Steve A,
Attachments
24hrs GPS Coverage 10-04-2016 Balcony.pdf
(15.09 KiB) Downloaded 106 times
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4252
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Thu Jul 23, 2020 8:22 pm

Also here's a screen-shot of the software I use just to monitor the receiver....

PRN = Pseudo Random Number. A random number given to each bird every so often between 1 and 32 for the basic constellation. The others (here PRN40 and PRN193) belong to the goestationary birds or other GPS-like signals, PRN193, Japan...

The others greyed out are too weak a signal to give a reliable fix, usually too close to the horizon..

Steve A.
Attachments
48 Hrs GPS Coverage 01-03-2016 1.gif
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4252
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Fri Jul 24, 2020 4:59 pm

I forgot to add the software is a freebie available here:-

https://www.visualgps.net/

There's quite a selection of other GPS related software too, some (as above) are freeware....

You'll also need a GPS receiver that puts out NMEA data for the PC, usually at 9600 baud...

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

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Mon Jul 27, 2020 2:17 pm

Going back to the oscillator, I'm thinking of dropping the fractional Hz function. The only application r.e. NBTV I can think of is the 12.5Hz frame-rate. But you'd need 400Hz as well for the line frequency. As this only has a single frequency output [1] you'd have to use an external divider to generate 12.5Hz from 400Hz. But that's a single 14/16-pin chip, only for square waves though, e.g.74HC4040.

I can't think of many applications where there is a fractional Hz requirement unless dealing with very low frequencies.

Other AD devices have from three to eight outputs all independent of each other in frequency though only square wave with no inverses. What their phase relationship is between them I don't know.

This module is overkill to use as a fixed frequency generator just for NBTV, I'll be using it as the title of this thread says, "A useful general purpose oscillator."

[1] It has four outputs, sine and its inverse and square and its inverse, they're all at the same frequency though.

Steve A.

There is also a sibling of this module, very similar in almost all respects using an AD9851 chip, but goes up to 70MHz instead of 'only 40MHz' should you need it. The on-board oscillator is 180MHz so the frequency increment is 0.0419Hz rather than the 0.0291Hz of the AD9850. As before the increment is the oscillator frequency divided by 2^32.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4252
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Tue Sep 01, 2020 3:16 pm

I'm back in the 'hot seat' so I now have some time to devote to stuff here...

Continued evolution of this oscillator..

AD9850 DDS Frequeny Source 1v05.gif
AD9850 DDS Frequeny Source 1v05.gif (22.08 KiB) Viewed 988 times


The micro and oscillator are as before, I've just added the logic buffer and an output amplifier for the sine outputs. With compact layout the sine output should go to the full 40MHz. The '74HC540 might be a limitation at 40MHz, ideally an 74AC540 would be better...if you can get them!

Steve A.

I may add an additional sine output for lower frequency requirements, if you think that 100kHz is high enough the two-transistor amp could be replaced with a standard op-amp. As shown driving an external 75R load the LF -3db point is around 1Hz. An op-amp will easily go down as far as the oscillator can, 0.0291Hz...if you really need it!

I've just noticed there are two R101s and two R102s on the drawing, ignore for now, I'll update the drawing...done...though I won't re-post the circuit until there are any other significant changes...hopefully not...a bit later...I've updated it anyway...
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4252
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Wed Sep 02, 2020 2:55 pm

I've come across another related oscillator, also the chip is from AD (Analogue Devices) an AD9833. As a module (from Banggood etc.) its maximum frequency is 12.5MHz but its frequency increment is a more human-friendly 0.1Hz. It's simpler to interface as well as being somewhat cheaper than the AD9850/AD9851 modules mentioned previously.

The downside to the AD9833 is it can only generate one type of waveform at a time, not sine and square simultaneously, though there is a triangle waveform making a third choice...not sure how useful that would be though... I would call it sawtooth rather than triangular.

That would suit me fine so I'm considering doing the AD9850 version as described so far in this thread, and a AD9833 variant later. Except for the module I think the rest of the circuit will be virtually identical...with lower power consumption. However the PIC16F833 software would need to be different, not sure if there's enough program space to provide both versions on one PIC16F833. (14-pin DIP).

AD9833 Module.jpg
AD9833 Module.jpg (8.7 KiB) Viewed 975 times


The SMA connector can be unsoldered if you don't need it.

Steve A.


The 0.1Hz increment value mentioned is wrong, it's 0.0931...(get your calculator out), so with that I don't see any point in going further...shame when someone tries that game on...25MHz/2^28=0.0931...specmanship...I admit I had my doubts as I started to read the datasheet...to get a 0.1Hz increment value the crystal would need to be 26.864Mhz which is outside the specifications (7.3% high) though most would work there's a chance it may not, and it's not a common crystal/oscillator frequency anyway.

The datasheet for the AD9833 is attached...

ad9833.pdf
(464.06 KiB) Downloaded 46 times
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 4252
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Thu Sep 03, 2020 7:15 pm

I've just ordered some AD9833 modules from Banggood at US$7.99 each. Smaller and a bit more basic than the one above, but it will do the job (he hopes). I've written the code to cope with the non-0.1Hz factor, if 12.5MHz is enough for you this should do the job. More to come...

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

PreviousNext

Return to Off Topic

Who is online

Users browsing this forum: No registered users and 7 guests