Yes Art you keep taunting me about interrupts and how great they are, I agree. Well I've shown you my code, why don't you help a guy out instead of sniveling, and add to it.
Yes Art you keep taunting me about interrupts and how great they are, I agree. Well I've shown you my code, why don't you help a guy out instead of sniveling, and add to it.
What you want is not much different from the interrupt code I posted in your other thread.
You just need to add a line to count the interrupt events.
Regardless, I would begin with DTs Elapsed Time code,
and add the portb.0 interrupt from there.
If you just get the elapsed timer working,
so you can check within any program that the SecondsChanged
variable is set (a second has ticked over),
it already contains an interrupt routine for a timer.
Then trust me, I'm in a good position to help you.
You don't add to what you've got,
best put it aside and use parts of it that do what you want,
but consider beginning with the Elapsed timer demo and adding what you need to that.
Last edited by Art; - 7th March 2012 at 01:10.
Well S.C. , I've done my own work, but there are several concepts that are a little beyond my grasp, although I'm trying. I am 67 years old and its a little bit hard to understand when someone says, " Just cut and paste this here, and write an assembler routine and add it here....". I have bought books like, "Revolutionary Assembly Language" and "Learning Assembly Language the Easy Way", all to no avail. I guess its like a cave man trying to understand a computer. At some point in our lives things just don't sink in that well. But I do appreciate Art's input but its like asking your mechanic what is wrong with your car and he replies "read the book".
Maybe I should just quit, throw away the development board and PBP and just watch tv all the time, would that be better?
Hi,
Another option (still involving interrupts though) is to feed the pulses to the input of TMR1 and set that up as a counter. That way the the pulses are counted in hardware and you can just "collect" the count at a suitable interval - which is where the interrupt comes in (or you could use PAUSE if you don't need to do anything else at the same time).Now the TMR1 will count the pulses on the T1CKI-pin and you can read it likeCode:TMR1H = 0 'Clear count TMR1L = 0 T1CON.1 = 1 'Set TMR1 as counter, clock on T1CKIIf you don't want to reset the TRM1 count each time you can just take the difference between 'this' reading and the 'last' readingCode:PulseCount VAR WORD PulseCount.HighWord = TMR1H PulseCount.LowWord = TMR1LIf you call this code at a specified interval (by timer interrupt or a simple PAUSE) you'll always have the current 'speed' in the variable PulseCount. This could be done with ON INTERRUPT but DT-INTS would be 'better'. We tend to say it's easy, which it is once you know how to do it but it can be intimidating at first. However there are many examples for DT-INTS and timer interrupts on the forum. If you can't find it and/or you need help that's what we're here for but give it a try first - if this is a suitable approach to your project of course.Code:oldCount VAR WORD oldCount = PulseCount PulseCount.HighWord = TMR1H PulseCount.LowWord = TMR1L PulseCount = PulseCount - oldCount
/Henrik.
Thanks Henrik,
Now I can understand this code. Using the TMR1 is exactly what I need to do. I notice that you use both a Highword and a low word, I assume this detects the rising and falling edges of the signal. But I'm still a little confused, do I add the high and low counts together? AAAAgggg.... I'm thinking of getting Flowcode 5 and throwing PBP away. Any thoughts?
Hi,
No, TMR1 is 16bits wide so it consists of two bytes, TMR1H and TMR1L, meaning it can count from 0 to 65535 pulses before it rolls over. These two bytes gets "put together" into the WORD size variable called PulseCount.
/Henrik.
EDIT: Get Flowcode, perhaps.... Throw away PBP, not a chanse! Learning curve, yes of course but you'll get the hang of it. I bet Flowcode comes with a learning curve as well.
Last edited by HenrikOlsson; - 7th March 2012 at 07:36.
Bookmarks