Math wizzards....

109 views
Skip to first unread message

Bill van Dijk

unread,
Feb 22, 2014, 10:31:04 AM2/22/14
to neoni...@googlegroups.com

Hello,

 

I have built a clock controlled by a PIC with 6 numitrons in the centre. Around them is a circle of 60LEDs which are programmed to display a number of different patterns. I am currently working on a pendulum pattern which uses the lower 30 LEDs. I have the software done, the challenge is this:

 

A pendulum has a period and an angular velocity that changes from 0 at the ends, and maximum in the center, following an equation. In the software I currently have 36 time slices (program steps, 0 to 35) in a half period of 107 clock cycles, for a total of 3852 cycles for one swing (left or right).

 

Looking at one swing, my challenge now is to divide the 36 program steps of 107 clock cycles such that the total number of clock cycles remains 3852, but the actual number of clock cycles per step are divided such as to approximate the equation of one pendulum swing  (left or right).

 

Anyone willing to take a stab at this?

 

Bill van Dijk

DSCF0335.jpg

Tidak Ada

unread,
Feb 22, 2014, 11:02:54 AM2/22/14
to neoni...@googlegroups.com
Remember the swing velocity is a (co)sine function. The highest speed is in the zero crossing the tops are the left and right ends of the swing with a speed zero.
 
eric


From: neoni...@googlegroups.com [mailto:neoni...@googlegroups.com] On Behalf Of Bill van Dijk
Sent: zaterdag 22 februari 2014 16:31
To: neoni...@googlegroups.com
Subject: [neonixie-l] Math wizzards....

--
You received this message because you are subscribed to the Google Groups "neonixie-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neonixie-l+...@googlegroups.com.
To post to this group, send an email to neoni...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/neonixie-l/002101cf2fe3%242ae9c9c0%2480bd5d40%24%40com.
For more options, visit https://groups.google.com/groups/opt_out.

Bill van Dijk

unread,
Feb 22, 2014, 11:43:44 AM2/22/14
to neoni...@googlegroups.com

Yes, I am with you so far. My challenge is to actually put that knowledge to work, and find the correct numbers.

 

Cheers, Bill

Frank Bemelman

unread,
Feb 22, 2014, 1:05:33 PM2/22/14
to neoni...@googlegroups.com
Hi Bill,
 
I’d go for a table driven approach.
 
The table has 30 values (or perhaps 15, for one quadrant of your clock face) and the function
is called 3852 times with a parameter 0-3852 and compared against the table to decide which
led is to be activated.
 
The table can be calculated with a spreadsheet. Just do some experiments with a spreadsheet,
until you get that eureka feeling. Then transfer the values to your PIC code, putting them in a
nested if-then-else scheme to compare against the 30 or 15 values. It does not take more than
6  compares (maximum) to find the answer.
 
I would not use the PIC to do time consuming floating point math. A precalculated table makes
more sense here.
 
Cheers, Frank



Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus actief is.


chuck richards

unread,
Feb 22, 2014, 1:49:58 PM2/22/14
to bvd...@xplornet.com, neoni...@googlegroups.com
That should be easy enough to do. I don't have the
equations memorized for this. If it was me attempting
to do it, I'd start by grabbing any and all math and
physics books, and looking up pendulums and periods
and stuff like that. Sooner or later if you do that,
you'll find the equation which describes the velocity
at any given point in the swing.

Once you know that, then you can go back to your
time slices and your bits, and then assign them so that
they come the closest possible at each point that you
have defined.

Grab all the books, blow the dust off, and have fun!!
This is a good one, and congratulations for doing it!
Let us know how it turns out.

Chuck

>
>
>---- Original Message ----
>From: bvd...@xplornet.com
>To: neoni...@googlegroups.com
>Subject: RE: [neonixie-l] Math wizzards....
>Date: Sat, 22 Feb 2014 11:43:44 -0500
>
>>Yes, I am with you so far. My challenge is to actually put that
>knowledge to
>>work, and find the correct numbers.
>>
>>
>>
>>Cheers, Bill
>>
>>
>>
>>From: neoni...@googlegroups.com
>[mailto:neoni...@googlegroups.com] On
>>Behalf Of Tidak Ada
>>Sent: Saturday, February 22, 2014 11:03 AM
>>To: neoni...@googlegroups.com
>>Subject: RE: [neonixie-l] Math wizzards....
>>
>>
>>
>>Remember the swing velocity is a (co)sine function. The highest
>speed is in
>>the zero crossing the tops are the left and right ends of the swing
>with a
>>speed zero.
>>
>>
>>
>>eric
>>
>>
>>
>> _____
>>
>https://groups.google.com/d/msgid/neonixie-l/002d01cf2fed%2452113dd0%
>24f633b970%24%40com.
>>For more options, visit https://groups.google.com/groups/opt_out.
>>



$4.95/mo. National Dialup, Anti-Spam, Anti-Virus, 5mb personal web space. 5x faster dialup for only $9.95/mo. No contracts, No fees, No Kidding! See http://www.All2Easy.net for more details!

Bill van Dijk

unread,
Feb 22, 2014, 1:53:50 PM2/22/14
to neoni...@googlegroups.com

Hi Frank.

 

Yes, that is indeed about the way it works, I currently have a lookup table with 36 entries containing the value 0x6B, each time the PIC shifts the LEDs, it looks up the required step time, resulting in a nice linear pendulum. I did fiddle with a spreadsheet, but after 40+ years of not using any advanced math, I don't know how to set up a formula. I suppose my only other option is to just take a stab at it, add some here, subtract the same somewhere else and approximate something. I figured that there could be someone on this list who'd say: oh, that's easy, you just do..... or even better: here are your numbers...... :-)

 

Thanks, Bill.

David Forbes

unread,
Feb 22, 2014, 2:02:01 PM2/22/14
to neoni...@googlegroups.com
Bill,

This problem is not hard to solve when writing new code for a clock, but
the constraint you have offered makes it hard to solve.

A faster loop would make it easy.

If it were my design, I would make the clock software use a main loop of
a few milliseconds (for example 200 loops per second), triggered by a
software timer based on the CPU clock crystal. Each cycle through the
loop would do any necessary timekeeping tasks, time-setting button
reading, etc. There would be only one constraint on that code's timing,
that it complete before the next timer trigger event.

Then I would add a short routine to look up which LED to light with a
lookup table based on a cosine wave, calculated in Excel as integers, as
was suggested earlier. The input to the lookup table would be a counter
that increments once per timing loop and is reset once per pendulum
cycle, when it reaches 200.

However, since your code is not structured in this general-purpose
manner, you will need to build the cosine into your timing code. A
spreadsheet will help to calculate the position of each LED based on the
cosine of the time slice.
--
David Forbes, Tucson AZ

Bill van Dijk

unread,
Feb 22, 2014, 2:06:59 PM2/22/14
to neoni...@googlegroups.com
Hi Chuck,

It appears you and I have different definitions of fun! :-)

I do still have the books btw, and I did look it up, found the formulas, and
realized I don't know what to do with them anymore (It is a function of age
I suppose; according to the sidebar notes I did know 40+ years ago. Who'da
thunk....). It would be something like giving me a sonic screwdriver; I'd
have no idea what to do with that either!

At the risk of fully exposing myself, I distinctly remember a university
professor announcing that they recently invented something they called a
transistor. He warned us not to be distracted by these things, nothing could
ever be invented that would replace the thermionic valve! As funny as that
is today, he was not as far off as some may think. Most of us still use tube
equipped appliances. I do not yet see a practical semiconductor replacement
for the magnetron in our microwave ovens!

Bill
https://groups.google.com/d/msgid/neonixie-l/380-22014262218495852%40all2eas
y.net.

chuck richards

unread,
Feb 22, 2014, 2:19:02 PM2/22/14
to neoni...@googlegroups.com
It's the instantaneous velocity at your points that
you're after.

That's the first derivative as I recall.
Once you know these instantaneous velocities, then the
problem becomes arriving at the timing between shutting
one LED off, and turning the next one on.

In this way, the LEDS will fool the eye into
"seeing" the prescribed instantaneous velocity
during each interval.

To show yourself how this works, you could simply
start out with an intuitive guess at some values, plug
them in, and watch it go for a while.

At first it may not look much like a real pendulum
if the numbers are way off. But then you can make another
iteration and try it again, speeding things up some
here, maybe slowing it down a little there, etc.

After a while, you should be able to get your values
pretty much lined up with the real math, but you really
don't need to sweat that much at first just to get
something going to see it and to try it.

Usually, these sorts of things will help you along
if you give them a chance, simply by rigging up
a crude first approximation enough to watch it work.

Then, later on, make it agree with the math.
>https://groups.google.com/d/msgid/neonixie-l/003d01cf3001%2454a36a50%
>24fdea3ef0%24%40com.

Bill van Dijk

unread,
Feb 22, 2014, 2:54:51 PM2/22/14
to neoni...@googlegroups.com
The PIC actually has a really cool feature I am using for the LED patterns.
First of all, everything is timed through interrupts, every time a timer 2
interrupt occurs, LEDs need to be moved. Depending on the active pattern, it
uses a number of lookup tables, some for the position, another for the
timing of the next move.

Timer 2 overflows once it content matches a particular readable and writable
variable (same function used in its PWM). This is the value I am trying to
find. One swing of the pendulum (let's say left to right) takes 3852
interrupts. In this time it completes 36 steps of 107 interrupts, which also
happens to be 1 second real time. The trick is now to adjust the steps from
36 107 interrupts to 36 steps of varying values that still add up to the
required 3852 interrupts, but in steps that approximate the true pendulum
dynamic.

I have now made a table that goes something like this (off-sets from the
basic 107):

......-50 -40 -30 -20 -10 0 +10 +20 +30 +40 +50........ | ......-50 -40 -30
-20 -10 0 +10 +20 +30 +40 +50........


It actually looks not bad.....

Bill



-----Original Message-----
From: neoni...@googlegroups.com [mailto:neoni...@googlegroups.com] On
Behalf Of David Forbes
Sent: Saturday, February 22, 2014 2:02 PM
To: neoni...@googlegroups.com
Subject: Re: [neonixie-l] Math wizzards....

--
You received this message because you are subscribed to the Google Groups
"neonixie-l" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to neonixie-l+...@googlegroups.com.
To post to this group, send an email to neoni...@googlegroups.com.
To view this discussion on the web, visit
https://groups.google.com/d/msgid/neonixie-l/5308F429.9050302%40dakotacom.ne
t.

David Forbes

unread,
Feb 22, 2014, 3:18:29 PM2/22/14
to neoni...@googlegroups.com
Bill,

Thanks for providing a description of the software architecture.

Since you're already using timers, it should be easy to set one up for a
periodic interrupt, and have that interrupt turn off the LED that's on
and turn on the next LED in the lookup table.

Often, the LED that it turns on is the same one that it just turned off,
so the pendulum doesn't move during that interval. That's OK.

The point is that if the timer interrupt occurs at the same interval
every time, the code is a lot easier to write. You don't have to keep
changing the interval every time, and no fancy math is required, just a
cosine lookup table that maps the fractional pendulum time into the LED
position..


On 2/22/14 12:54 PM, Bill van Dijk wrote:
> The PIC actually has a really cool feature I am using for the LED patterns.
> First of all, everything is timed through interrupts, every time a timer 2
> interrupt occurs, LEDs need to be moved. Depending on the active pattern, it
> uses a number of lookup tables, some for the position, another for the
> timing of the next move.
>
> Timer 2 overflows once it content matches a particular readable and writable
> variable (same function used in its PWM). This is the value I am trying to
> find. One swing of the pendulum (let's say left to right) takes 3852
> interrupts. In this time it completes 36 steps of 107 interrupts, which also
> happens to be 1 second real time. The trick is now to adjust the steps from
> 36 107 interrupts to 36 steps of varying values that still add up to the
> required 3852 interrupts, but in steps that approximate the true pendulum
> dynamic.
>
> I have now made a table that goes something like this (off-sets from the
> basic 107):
>
> ......-50 -40 -30 -20 -10 0 +10 +20 +30 +40 +50........ | ......-50 -40 -30
> -20 -10 0 +10 +20 +30 +40 +50........
>
>
> It actually looks not bad.....
>
> Bill


Matthew Smith

unread,
Feb 22, 2014, 5:15:26 PM2/22/14
to neoni...@googlegroups.com
More thinking aloud, than a practical solution:

One of the reasons that I'm in the throes of building an analogue
computer is that, in the analogue domain, maths can be done very simply,
in hardware.

What if you were to get your cosine function as a voltage? Then take
said voltage and feed it into a bargraph driver (LM3914 is basically a
set of comparators.) OK, that doesn't give you a sequence of one LED
illuminating after another, but the growing stack of LEDs would still
have the same effective motion - no calculations involved.

This is all assuming that there's some way of persuading op amps to get
a cosine function out of a square wave - which could be provided by the
microcontroller. Not yet well-enough versed with op amp circuits, but
sure it must be possible - would start out with an integrator?

M

--
Matthew Smith

Business: http://www.smiffytech.com
Blog: http://www.smiffysplace.com
Linkedin: http://www.linkedin.com/in/smiffy
Flickr: http://www.flickr.com/photos/msmiffy
Twitter: http://twitter.com/smiffy

ABN 16 391 203 815

Matthew Smith

unread,
Feb 22, 2014, 5:21:40 PM2/22/14
to neoni...@googlegroups.com
Regarding my previous mention of the LM3914, I was incorrect in stating
that you can only have a growing/shrinking stack of LEDs - there is a
Dot Mode that would provide the motion of a pendulum bob quite nicely, I
think.

Michel van der Meij

unread,
Feb 23, 2014, 5:25:46 AM2/23/14
to
Hi Bill,

I agree with David on this that it is a bit of a strange approach to realize your pendulum routine. The velocity on the outer left and right hand side is 0 so that would result in a very large timer value. However, if you say your numbers based on adding something * 50 gives you a reasonable result, you can use the "int" numbers from the table as attached. I based on on 100 rather than 50, in theory it should be 107 I reckon, but I thought that might cause problems with the rest of your interrupt routines, so 100 should be alright I think.
 
Michel
PendulumCOS.pdf

Bill van Dijk

unread,
Feb 22, 2014, 9:09:05 PM2/22/14
to neoni...@googlegroups.com

Hi Michel,

 

Thanks for that, that is actually going to help.

 

It is so difficult to explain a design in a few words, and I can see where my poor explanations confuse some. I don't know if it would help or not, but I'll attach the portion of the schematic for the LED section. The LEDs are multiplexed in an 8x8 fashion (the last group actually has only 4 LEDS). By using high output LEDS, the visual result is plenty bright. The columns are driven directly from the PIC outputs, the rows are selected by a counter, buffered by a ULN2803.  Off to the left is the section with the numitrons which I left out for now. They are controlled via a serial data flow (bit-banged) from the PIC, a shift register, and a BCD decoder / latch for each numitron (you can't multiplex them, there would be no light output left). It is working great, and has currently 7 different display settings which can be selected with the same buttons used for time adjustment. The software is done in assembler, still my preferred language for these small PICs. Including the lookup tables I have used only 22% of its program memory space, so I keep looking for other things to do with it.

 

Thanks again for your and everyone else's contributions.

 

Bill.

 

From: neoni...@googlegroups.com [mailto:neoni...@googlegroups.com] On Behalf Of Michel van der Meij
Sent: Saturday, February 22, 2014 6:22 PM
To: neoni...@googlegroups.com
Subject: Re: [neonixie-l] Math wizzards....

 

Hi Bill,

I agree with David on this that it is a bit of a strange approach to realize your pendulum routine. The velocity on the outer left and right hand side is 0 so that would result in a very large timer value. However, if you say your numbers based on adding something * 50 gives you a reasonable result, you can use the "int" numbers from the table as attached. I based on on 100 rather than 50, in theory it should be 107 I reckon, but I thought that might cause problems with the rest of your interrupt routines, so 100 should be alright I think.

 

Michel

 

 

 

 

on Feb 23, 2014, Bill van Dijk <bvd...@xplornet.com> wrote:

 

--

You received this message because you are subscribed to the Google Groups "neonixie-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neonixie-l+...@googlegroups.com.
To post to this group, send an email to neoni...@googlegroups.com.

Capture.JPG

Joseph Bento

unread,
Feb 22, 2014, 11:28:03 PM2/22/14
to neoni...@googlegroups.com



On Saturday, February 22, 2014 12:06:59 PM UTC-7, Bill v wrote:


 Most of us still use tube
equipped appliances. I do not yet see a practical semiconductor replacement
for the magnetron in our microwave ovens!

Or guitar amplifiers!  :-)

Joe, N6DGY
 

MrNixie (UK)

unread,
Feb 23, 2014, 10:57:26 AM2/23/14
to neoni...@googlegroups.com

MrNixie (UK)

unread,
Feb 23, 2014, 11:16:47 AM2/23/14
to neoni...@googlegroups.com
Bill, not unlike this one here, then!  :)   (my own design, of some five years back)

http://www.youtube.com/watch?v=WgFVbnZrwYg

I used a lookup table which the software consults at regular time intervals, once per display multiplex cycle, which was about every 6mS from memory. The table had about 170 entries in it for the full second. Once the table is done, there is no math in the software routine. It just looks up the value, and displays it.

Incidently, you may find (as did I) that a "swing" of greater than about 60 degrees just doesn't "look" right. As you'll see, while I was at it, I made several other effects available to the user, all through lookup tables (no space efficient, but easier)

Here is a simple sine wave spreadsheet. I've done it for steps of 5 degrees. You can change the number of LEDS in the "swing" in the yellow box - enjoy.

Laurence



On Saturday, 22 February 2014 15:31:04 UTC, Bill v wrote:
SINE table.xls

Mich...@aol.com

unread,
Feb 23, 2014, 12:20:48 PM2/23/14
to neoni...@googlegroups.com
Laurence....
 
I am completely familiar with the looks of that clock.  I am still waiting for you to produce one for me.  Hint - don't forget me.  :)
 
Michail Wilson
206-920-6312
 
--
You received this message because you are subscribed to the Google Groups "neonixie-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neonixie-l+...@googlegroups.com.
To post to this group, send an email to neoni...@googlegroups.com.

Bill van Dijk

unread,
Feb 23, 2014, 12:58:53 PM2/23/14
to neoni...@googlegroups.com

Very nice!

 

Now I have to work on some more patterns...... :-)

 

Bill

--

threeneurons

unread,
Feb 23, 2014, 2:37:37 PM2/23/14
to neoni...@googlegroups.com
I'm a little late to the table, here. To simulate a pendulum, its a cosine function, first mentioned by Erik. As Frank, also noted, calculate the values externally, and then load it as a lookup table, into your code. Speed and position, were also noted to be a derivative of each other. Fortunately, the derivative of a cosinewave is a sinewave, and both are really the same thing, only shifted a quarter of the way (90 degrees) off each other. That means you don't have to think too hard. Also a couple of the guys worked out the tables for you. For speed, or duration, just use the absolute value. I noticed one had negative numbers. Again don't worry about it too hard. Write and test the code. If it ends up its off, by 90 degrees, just shift the table. Or better yet, add an offset constant to your lookup index. Add a simple "mod" limiter, so the index will wrap around. That way you can rotate the function, with adjusting just one value.

Quixotic Nixotic

unread,
Feb 24, 2014, 9:33:42 AM2/24/14
to neoni...@googlegroups.com
I just got what I think is a scam email from Westdave, with a reply-to that I don't think is him:

---snippety snip---

I really hope you get this fast. I could not inform anyone about our trip, because it was impromptu. we had to be in Philippines for a Tour..The program was successful, but our journey has turned sour. we misplaced our wallet and cell phone on our way back to the hotel we lodged in after we went for sight seeing. The wallet contains all the valuables we have. Now, our passport is in custody of the hotel management pending when we make payment.

I am sorry if i am inconveniencing you, but i have only very few people to turn to now. i will be indeed very grateful if i can get a short term loan from you ($2,450). this will enable me sort our hotel bills and get my sorry self back home. I will really appreciate whatever you can afford in assisting me with. I promise to refund it in full as soon as I return. let me know if you can be of any assistance. Please, let me know soonest.

Thanks so much
David Weiner

---end snip---

Anyone else getting this?

John S

Quixotic Nixotic

unread,
Feb 24, 2014, 9:36:31 AM2/24/14
to neoni...@googlegroups.com
I also just got second one with a reply-to of neoni...@googlegroups.com

John S
> --
> You received this message because you are subscribed to the Google Groups "neonixie-l" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to neonixie-l+...@googlegroups.com.
> To post to this group, send an email to neoni...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/neonixie-l/CD2B2501-DF4D-48FF-92BD-2C33059478DF%40jsdesign.co.uk.

Dylan Distasio

unread,
Feb 24, 2014, 9:42:56 AM2/24/14
to neoni...@googlegroups.com

Definitely a fake. I've seen these before.

Cqr

unread,
Feb 24, 2014, 9:46:57 AM2/24/14
to neoni...@googlegroups.com
I've had exactly the same text apparently from an acquaintance a few months back .... Looks like the scammers have hold of some social graph data.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/neonixie-l/1BF3B7DB-2F6E-4882-8794-5EBDDE739352%40jsdesign.co.uk.

Mich...@aol.com

unread,
Feb 24, 2014, 10:11:33 AM2/24/14
to neoni...@googlegroups.com
Isn't it pretty darn stupid for a scammer to email the group without instruction on sending money directly?  And, to top it off know that hitting a reply simply goes back to the entire group?
 
Just seems like a poor strategy to get money.  To follow suite, I will throw cash at the screen... So, anything that goes through, he can have.
 
Michail Wilson
206-920-6312

Quixotic Nixotic

unread,
Feb 24, 2014, 10:20:55 AM2/24/14
to neoni...@googlegroups.com
On 24 Feb 2014, at 15:11, mich...@aol.com wrote:

Isn't it pretty darn stupid for a scammer to email the group without instruction on sending money directly?  And, to top it off know that hitting a reply simply goes back to the entire group?

The first one I received was to my personal email address, one I don't use with the group.

John S

Instrument Resources of America

unread,
Feb 24, 2014, 10:40:58 AM2/24/14
to neoni...@googlegroups.com
Yep!!! Got one here Monday morning. Ira.
IRACOSALES.vcf

Nick

unread,
Feb 24, 2014, 10:45:30 AM2/24/14
to neoni...@googlegroups.com
I know about this - Dave's email contact list is compromised - its an old scam - just ignore it - we got a copy on the list and I've deleted that.

Just pretend it didn't happen. He probably knows about the issue and hopefully is dealing with it.

Nick

threeneurons

unread,
Feb 24, 2014, 1:20:29 PM2/24/14
to neoni...@googlegroups.com
Yes, it was. I got that email directly, to one of my email accounts. He's had that email, since day one of the internet. I saw him, in person, on Saturday. TRW swapmeet. We're both there every month. I don't recall our side trip to the Philippines. I don't access that email account regularly, anyways. He thinks I'm ignoring him. If its important, he'll call me. Plus he has no cellphone.
Reply all
Reply to author
Forward
0 new messages