PDA

View Full Version : Single event data logger wth LCD



med2007
- 9th January 2008, 22:21
Hi everybody, I am struggling most of the time with PICs, this is my first post...does anyone have an event logger design such that on a switch closure, count = 1, and measure time interval of closure, then log number of times switch has closed, with total time, and total number of switch closures, displayed on LCD module?
range up to 256 for count and 24 hours. Please ask if this isn't clear.
Cheers

mister_e
- 10th January 2008, 02:19
Easy to do with almost all RTC and a external EEPROM, or skip the RTC and use ElapsedTimer example.

med2007
- 11th January 2008, 13:41
I don't understand your reply and is it not possible to impliment solution with a single chip?
Do a 16F84 not have enough data space?
Rgds

skimask
- 11th January 2008, 13:50
I don't understand your reply and is it not possible to impliment solution with a single chip?
Do a 16F84 not have enough data space?
Rgds

Sure it do (does...) have enough data space...
If you want to record 64 events, each of which are only one byte wide data, or 32 events of 2 byte data, or 16 events of 4 byte data, or 8 events of 8 byte data, or 4 events of 16 byte data, or 2 events of 32 byte data, or one event of 64 byte data.
See where I'm going with this?
We don't know: what you are logging (A) and how often you are logging it (B).
A x B = total data space required.

Some simple math and a quick trip to the datasheets will answer all your questions.

med2007
- 22nd January 2008, 09:03
As a complete NOOB I am struggling again, my interrupt handler doesn't work. It's for a timer
and this code is only part of the complete project. It should pulse portb.0 and susequently portb.2 It does not work. Please help if you have the time. Rgds Mike

'Using 16F628 4MHz crystal
secs var byte
mins var byte
clear

option_reg = %10000111
intcon = %10110010

test:
on interrupt goto seconds
goto test

disable
seconds: 'Interrupt Handler 'Disable interrupts during Handler
secs=secs+1
intcon.2=0 'interrupt bit 2 must be rest in software
if secs=10 then
mins=mins+1
secs=0
high portb.0
pause 1
low portb.0
endif
if mins=5 then gosub minutes
resume test
enable 'Re-enable interrupts after Handling

minutes:
mins=0
intcon.2=0
secs=0
high portb.2
pause 5
low portb.2
return

skimask
- 22nd January 2008, 14:37
The setup is a bit goofy in my mind, but if it works for you, great...
This is the way I'd do it (keep in mind I don't have my 'stuff' handy, so the register setup might be off)



secs var byte : mins var byte : dummycounter var byte
clear
option_reg = %10000111 : intcon = %10110010
goto skip_ints_and_subs
on interrupt goto int_handle
disable
int_handle:
intcon.2 = 0
secs = secs + 1
if secs = 10 then
mins = mins + 1 : secs = 0 : high portb.0 : pause 1 : low portb.0
'1ms? sure you'll see the pulse?
endif
if mins = 5 then
mins = 0 : secs = 0 : high portb.2 : pause 5 : low portb.2
'5ms? probably won't see this pulse either
endif
resume

enable
skip_ints_and_subs:
dummycounter = dummycounter + 1
goto skip_ints_and_subs


Again, check your pulse length on the LED flash. Increase it maybe.

scarroll01
- 22nd January 2008, 15:35
if secs = 10 then
mins = mins + 1

Did you mean:-

if secs = 60 then
mins = mins + 1

... Steve

skimask
- 22nd January 2008, 16:28
if secs = 10 then
mins = mins + 1
Did you mean:-
if secs = 60 then
mins = mins + 1
... Steve

Nope...if the O/P put 10 and his minutes are 10 seconds long, then great...
Besides...if you're making something, and something else isn't working...I don't know about you, but I'd rather wait 10 seconds to see if something doesn't work rather than 60 of them seconds.
Can always change it later...

med2007
- 23rd January 2008, 08:42
Too right 10 seconds is for test purposes.
I have tried your code skimask and it does do something..however a bit strange, is there a way of posting scope waveforms on this forum? I think my scope will produce either jpg or bitmap, I'll check it out.
Rgds
Mike

skimask
- 23rd January 2008, 13:59
Too right 10 seconds is for test purposes.
I have tried your code skimask and it does do something..however a bit strange, is there a way of posting scope waveforms on this forum? I think my scope will produce either jpg or bitmap, I'll check it out.
Rgds
Mike

I'm guessing here...'cause I don't see ALL of your code...just a couple of ideas...

You're probably seeing jitter caused by ON INTERRUPT.

The ON INTERRUPT is probably being triggered at different points in the code and might have a different amount of clock cycles before it actually gets into the interrupt code.
The number of cycles it takes to get to the interrupt code might be different between the 'dummy = dummy + 1' part and the 'goto main' part.

WDT on? If it is, might be timing out causing the PIC to reset, resetting all the variables, therefore screwing up the timing overall.

EDIT: Forgot to mention that using DT's Fast Interrupt routines would most likely solve any interrupt latency issues.

med2007
- 23rd January 2008, 14:11
Thanks for that I'll check it out...meantime is it allowed to have a GOTO inside a subroutine to exit that routine before the RETURN?

Or can I just say IF so-and-so THEN RETURN?

Rgds
Mike

skimask
- 23rd January 2008, 14:14
Thanks for that I'll check it out...meantime is it allowed to have a GOTO inside a subroutine to exit that routine before the RETURN?
Or can I just say IF so-and-so THEN RETURN?
Rgds
Mike

It's allowed and it'll compiled, but it'll probably bite you in the rear later on 'cause you'll probably end up with a stack overflow that you'll have a hard time tracing.

The second option works just fine, the IF/THEN-RETURN type thing that is...

med2007
- 18th February 2008, 16:50
Easy to do with almost all RTC and a external EEPROM, or skip the RTC and use ElapsedTimer example.

Thanks for your help with my project, it is now almost complete and working well enough.
In the end I didn't use an Interrupt Handler, just counted until intcon.2=1, fairly accurate for what I want, about +-0.02%, according to my real time clock.
I've packaged the result as a demo, hoping to strike up some interest with a few of my chums...you never know?
Rgds
Mike