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: [email protected] [mailto:[email protected]] On Behalf Of David Forbes Sent: Saturday, February 22, 2014 2:02 PM To: [email protected] Subject: Re: [neonixie-l] Math wizzards.... 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. On 2/22/14 8:31 AM, Bill van Dijk wrote: > 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 > -- David Forbes, Tucson AZ -- 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 [email protected]. To post to this group, send an email to [email protected]. To view this discussion on the web, visit https://groups.google.com/d/msgid/neonixie-l/5308F429.9050302%40dakotacom.ne t. For more options, visit https://groups.google.com/groups/opt_out. -- 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 [email protected]. To post to this group, send an email to [email protected]. To view this discussion on the web, visit https://groups.google.com/d/msgid/neonixie-l/004101cf3008%2404b92d70%240e2b8850%24%40com. For more options, visit https://groups.google.com/groups/opt_out.
