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: Dave Moll, Steve Anderson

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Tue Jun 23, 2020 5:19 pm

Hmm, quite possible, but I'm reluctant to learn another language if needed (probably). In other applications I've considered a Raspberry Pi, but the same issue holds true...though a RP is an overkill for this.

Maybe I should just bite the bullet and get on with it?

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

Re: A Useful General Purpose Oscillator.

Postby Andrew Davie » Tue Jun 23, 2020 5:49 pm

Firstly it's all already written - Arduino examples include full functional source code and hardware setup.
In any case, the Arduinos are programmed in C and if you don't know C... you should!
Thirdly... I'd be more than happy to handle any programming requirements for you.
Cheers
A
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: A Useful General Purpose Oscillator.

Postby Andrew Davie » Tue Jun 23, 2020 5:51 pm

Very first link returned on a search shows keypad + display + source code...

https://www.instructables.com/id/Arduin ... ix-Keypad/
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Tue Jun 23, 2020 7:28 pm

Decisions, decisions...certainly a way to go Andrew...and thanks for the offer of coding, it would be quite simple I think. Even in PIC code it's no rocket science. I'm rather stuck, which way to go, the Arduino Uno board, or the PIC route?

I'd like some feedback as to any preferences preferred. Though there's no reason why both couldn't be done....

Andrew, I have no C coding experience, perhaps it's time to jump on the bandwagon?

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

Re: A Useful General Purpose Oscillator.

Postby Andrew Davie » Tue Jun 23, 2020 8:55 pm

C is very close-to-the-metal, and its main advantage in this instance is the availability of third-party libraries to (for example) drive the LCD and the keypad. In my ArduinoVisor I used a third-party library for the SD-card reading/writing and (originally) to run the Nextion display. It's a huge time-saver when you can just grab components, attach them to the arduino, download a library and a few simple calls and you're up and running.
So, since you don't know C - I will of course handle any of that if you want, and if you go the Arduino route.
As to the "Uno" - that is just one of many arduino variants/options. The Uno is a relatively large board but very simple because you just power it via USB connector and you're ready to go. For the ArduinoVisor I used an "Arduino Micro" which has a faster processor. As long as your Arduno has enough digital pins for the keypad and whatever else you need (LCD perhaps) then you could use any one of many variants. Cost should be round about $5 max for what you need.
I would highly recommend exploring C, as it opens up a world of new processors for your projects.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Wed Jun 24, 2020 3:05 pm

Thanks for the detailed overview Andrew, it's certainly something I'll look into. Perhaps I should buy the book, "C for Dummies"...assuming it exists..

Many years ago (like 40+) I did use higher level languages, not only Basic which was the new kid on the block at the time, but also Fortran and Algol...now lost in the mists of time. Entry was by punched cards, you submitted your program and if you were lucky you got the result (if any) the next day. (RMIT, Melbourne, 1974/5).

I guess it's a case of "Watch this space"...

Steve A.

There are "For Dummies" books, several of them, C, C+ and C++...then I guess you need an assembler/compiler/programmer...
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 5357
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: A Useful General Purpose Oscillator.

Postby Andrew Davie » Wed Jun 24, 2020 3:23 pm

Steve, as a prelude you need a decent modern IDE to edit your code.
Here, install this...

https://code.visualstudio.com/

That will give you the best environment to start with.
Next, for Arduino stuff you want to install "PlatformIO"

https://marketplace.visualstudio.com/it ... formio-ide

That's all you need.
Once you've got that setup, we can load an Arduino project and have fun.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: A Useful General Purpose Oscillator.

Postby Andrew Davie » Wed Jun 24, 2020 3:25 pm

Steve Anderson wrote:There are "For Dummies" books, several of them, C, C+ and C++...then I guess you need an assembler/compiler/programmer...


I wouldn't worry about the books. We can get you up and running easily with 1:1 here, and also online links.
As to the compiler/programmer, Visual Studio Code already has all that. The links I posted last message are all you need.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Wed Jun 24, 2020 3:41 pm

Thanks for all that Andrew...I'll look into this and decide if I want to go this route...I'm sure you'll say I should!

Steve A.

I'm wondering, what would a routine look like that took a 32-bit number and multiplied that by 34.364 (decimal)....result still in binary...allow 40 bits for the result...with a 16-bit PIC it would be trifling...

Even in 8-bit devices it's not that hard...

Take original, shift left 5 times (x32) store somewhere.
Take original, shift left 1 time (x2) add to store, (=x34)
Take original, shift right 2 times (/4 or x0.25) add to temporary = =34.25....and so on until you achieve the desired accuracy...

To save time you may not want to do it in that order, do the x2 first, then the x32...and so on...

Take original, shift left 1 time (x2) store somewhere, (=x2)
Take interim, shift left 4 times (total of x32) add to store (=x34)....saves a few shifts and re-loads...
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 5357
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: A Useful General Purpose Oscillator.

Postby Andrew Davie » Wed Jun 24, 2020 6:17 pm

Steve Anderson wrote:I'm wondering, what would a routine look like that took a 32-bit number and multiplied that by 34.364 (decimal)....result still in binary...allow 40 bits for the result...with a 16-bit PIC it would be trifling...



Depends on how quick you want it. These things are relatively fast, so the easiest is just to do the multiply... here using a 64-bit (long long) as the result.

Code: Select all
    long long result = (long long)(34.364 * original);


Alternatively, if you really want to bit-shift, then C has that, too...

Code: Select all
    long long t64 = original;  // cvt to 64-bit
    long long result = (t64 << 5) + (t64 << 1) + (t64 >> 2); // etc...


For most uses, I'd go with the first example.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Thu Jun 25, 2020 1:45 pm

Yes, certainly easier for the human, I wonder mow many instructions the first example results in?

In this case speed isn't that important, would be nice to see the amount of memory required, both program and RAM.

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

Re: A Useful General Purpose Oscillator.

Postby Andrew Davie » Thu Jun 25, 2020 2:00 pm

Steve Anderson wrote:Yes, certainly easier for the human, I wonder mow many instructions the first example results in?

In this case speed isn't that important, would be nice to see the amount of memory required, both program and RAM.

Steve A.



According to the code inspector, the first uses 22 bytes, and the latter uses 282 bytes.
Bit of a surprise to me, but there you go.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: A Useful General Purpose Oscillator.

Postby Steve Anderson » Thu Jun 25, 2020 2:10 pm

The first example is surprisingly efficient...probably more so than the assembly version, which goes against the grain generally for high-level languages.

Yours surprised of Bangkok....

Later...as I'm quite keen to get this going I may do the PIC version first, write it up then take a sabbatical whilst I learn C coding and (shock, horror) defect to Atmel devices. The PICs certainly brought me back to the realm of programming after a break of decades, maybe now is the right time to move on...
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 5357
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:31 pm

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...

*With the processor and clock as per diagram previously. It will certainly do the job, but if there are more efficient ways to do it it makes sense to go that route...

Steve A.

Estimated error in output is 0.000827%...the maths error that is...
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 5357
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: A Useful General Purpose Oscillator.

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

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...

*With the processor and clock as per diagram previously. It will certainly do the job, but if there are more efficient ways to do it it makes sense to go that route...

Steve A.


I haven't actually viewed the compiled code; I have merely presented the stats that the compiler is throwing out.
But in any case, my view on this whole thing is that the opportunity to learn something new with regard to Arduino and the VC IDE/PlatformIO -- and more particularly... C - with someone to assist - is worth serious consideration.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

PreviousNext

Return to Off Topic

Who is online

Users browsing this forum: No registered users and 5 guests

cron