Topics Topics Edit Profile Profile Help/Instructions Help Member List Member List  
Search Last 1|3|7 Days Search Search Tree View Tree View  

Adding elapsed time to counter project

:: EPE Chat Zone ­:: ­Radio Bygones Message Board :: » EPE Forum Archives 2007-2009 » Archive through 15 January, 2008 » Adding elapsed time to counter project « Previous Next »

  Thread Last Poster Posts Pages Last Post
  ClosedClosed: New threads not accepted on this page        

Author Message
Top of pagePrevious messageNext messageBottom of page Link to this message

tommy
Just joined
Username: tommy

Post Number: 2
Registered: 10-2007

Rating: N/A
Votes: 0 (Vote!)

Posted on Monday, 31 December, 2007 - 02:58 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

PIC 16f684
Langauge C
Compiler PICC Lite
Display controller: Samsung KS0066

Project brief.

Control board to switch relay on for 1 second at 6 second intervals for 30,000 cycles. User to start sequence with push button. 16 character 2 line display to number of times relay switches (line 1 of display) and total elapsed time on line 2 of display.

Sequence for counter without elapsed time.

Initialise everything

Main loop
Display press start in display
Press start
De-bounce
Write display count on line 1 of display

Do while I < 30,000
Switch relay on 1 second
Delay 6 seconds
Increment variable I by 1
Convert variable I to decimal
Display variable I} elihw

This counter program works fine.

Problem adding elapsed time to line 2 of display

My next step was to display the total elapsed time in hours on the second line of the display.

I was thinking of interrupting the main program every-time TMR1 (16 bit)overflows, updating another variable J, doing the decimal conversion and then update the display. With the prescaler set at 8 this happens about every 0.5 seconds with a 4Mhz oscillator. If I were to do this, am I right in assuming it would increase the switching time of the relay sequence, ie. Approx 14 interupts per cycle. Is this additional time significant? (I have a tolerance in the relay switching of 0.5s per cycle).

Alternatively, I am think of incrementing another variable J at the end of each cycle, timing the full cycle using the simulator and then incrementing the variable by this value. If I divide this value by 3600 this will give me the number elapsed hours which will be updated once per cycle.

I interested in your informed opinion as to the best approach to this problem. I am new to PIC programming but I am encouraged by my success in getting the counter to work so far.
Top of pagePrevious messageNext messageBottom of page Link to this message

grab
Frequent Contributor
Username: grab

Post Number: 626
Registered: 05-2005


Rating: N/A
Votes: 0 (Vote!)

Posted on Wednesday, 02 January, 2008 - 01:13 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Is this additional time significant?

You're the only person who can answer that question. How accurate do you want your switching and timing to be? Also remember that you can set the timer so that the interrupt happens maybe every 0.1s or quicker - you're not forced to use 0.5s. Beware though that if you set your interrupt to happen more times per second, you need to make sure that the code in the interrupt routine is very fast. At 0.1s this shouldn't be a problem, but I'd be worried at 0.1ms! :-/

I definitely would *NOT* recommend trying to set timing by measuring how long the code takes to execute. It will work, sure, but what happens when you add one line of code? If you know that you're never going to change that code after you've written it, then I suppose it's OK. But for you that isn't going to be the case, is it?

Graham.

Administration Administration Log Out Log Out   Previous Page Previous Page Next Page Next Page