Interrupt on change high to low on Pic

JohnInTX

Joined Jun 26, 2012
4,787
at least two timer intervals. The first time to display the first column then a delay between each column after that.
Two timer intervals - one timer.
After the HOME IRQ, set the timer interval to locate the first LED column, start the timer and enable its interrupt.
On the first timer interrupt, its all LED column timing from there so just load/reload the timer to the inter-column time. Note that its only the one time (the inter-column time0 to reload if its a timer interrupt. If its a HOME interrupt, its the 'locate the first column' time. These are different interrupts so its a no brainer which time to use.
Nice.
 

joeyd999

Joined Jun 6, 2011
5,283
The problem I see doing them all in one turn is I will need two timers or at least two timer intervals. The first time to display the first column then a delay between each column after that. I suppose I could just use a standard delay for each of those ???
If all your 'triggers' are forward in time by a known (though possibly variable amount), you can do it with one timer, say Timer1, in conjunction with the CCP module. Use a state machine in the CCP interrupt routine to keep track of where you are, and add the next period counts to the compare register (CCPRxH:L) at the start of each interrupt. Sounds complicated, but it is actually pretty easy.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
If all your 'triggers' are forward in time by a known (though possibly variable amount), you can do it with one timer, say Timer1, in conjunction with the CCP module. Use a state machine in the CCP interrupt routine to keep track of where you are, and add the next period counts to the compare register (CCPRxH:L) at the start of each interrupt. Sounds complicated, but it is actually pretty easy.
I am not sure I understand then again I do not have a full understanding of how CCP works. I will have to do more reading.

In very quick browsing and reading

http://www.mikroe.com/chapters/view/6/chapter-5-ccp-modules/



Is this the right track?

It says

Compare Mode compares values contained in two registers at some point. One of them is the timer TMR1 register. This circuit also allows the user to trigger an external event when a predetermined amount of time has expired.


What value is TMR1 set to? Is it set to the time for a full rotation and the CCP would break that into "segments"?
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
I don't suppose the internal OSC is going to be accurate enough for a propeller clock project. And maybe not fast enough? It only goes to 16MHZ internal I think.
 

JohnInTX

Joined Jun 26, 2012
4,787
I'd also consider timer 2. All you would have to do is set it up for PR2= the first time then change PR2 on the first interrupt to the column time.
EDIT: INTOSC is probably accurate enough since its trimed to 1% (usually better than that) and its drift is over mostly temperature. You eventually would want to measure the 'home' pulse period anyway to take into account variances in fan speed (and automatically, the oscillator speed) in terms of angular velocity so variances would calibrate out.
16MHz is pretty spiffy. Plus with 4XPLL you get 16MIPS. Take a few jabs at what the column period is with your fan speed and see how many Tcycs that is. I think you are OK.

The first step is - what is the fan's RPM? Then, how many columns of LED patterns make up the display field. What is the resulting inter-column time? How many instructions is that? Examining the proposed column-spitting code, are we in the ballpark? i.e. if it takes 10 instructions to spit the pre-fetched column pattern, how does that compare to the number of instructions that you can execute between columns? 10%? sweet! 50%, not so much but doable, pushing all of the Tcycs? - time to rethink things a bit maybe.

I think that mechanical issues will limit the RPM you can do (balance, torsionals, drag etc) before you run out of PIC.

EDIT:
OK, some numbers. A reasonable POV is 10msec (most folks can see slower but we'll use that). So each column of LEDs has to be hit each 10msec.
Assume:
5x7 font = 6cols/char.
20 chars in a 180deg arc.
10ms per refresh -> 100rpm. The visible arc occupies 50ms.
20 chars x 6 cols/char in 50ms gives 41.6uS per column.
Running at 16MIPS, the PIC does one instruction in 62.5ns.
41.6uS per col/62.5ns per instruction = 665 instructions per column.
Hell, even I could code that.

You can poke in different values but the procedure is the same.
(Might also want to recheck the numbers - doing this on a yellow pad - but that's the idea).

Note that you may run the disc faster but even at x10 (1000RPM) , you still have 65 instructions/column. Works for me.
 
Last edited:

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Thanks for doing the math and you might have solved a problem for me. I was trying to make one full port available for my led strip. But from the sounds of it, I will have time to break the byte up across two ports??

When you say 5x7. Is that 5 high 7 wide? Will that be enough? I was going to go 8 x8 but 5 high will also solve a problem with port availability.
 

joeyd999

Joined Jun 6, 2011
5,283
I'd decide in advance how many columns I want per rotational period. Then, track the time elapsed for each rotation and divide that by the number of columns for the time between columns. This way, the columns will always be the same size regardless of change in RPM.
 

JohnInTX

Joined Jun 26, 2012
4,787
7 high by 5 wide with one blank col to separate the digits but the font/display is up to you.
As joeyd999 says, and I did in post 17, keep a running value for rotational speed and make MAIN do the tweaking of the timer settings.
 
Last edited:
Top