Digital Hourmeter


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Hmmm... don't quite understand your figures...

    1/60=16667uS = $411B based on 1uS tick time (4MHz clock)

    $0000-$411B=$BEE5

    Use Microsofts Calculator in Scientific mode... you cant do 0-411B in hex directly, so instead do FFFF-411B and just add 1 to your answer.

    Setting the clock for a 16667uS count would be...

    T1CON.0=0 ' Stop the Clock
    TMR1H=$BE ' Set Timer Highbyte
    TMR1L=$E5 ' Set Timer Lowbyte
    T1CON.1=1 ' Restart the Clock
    PIR1.0=0 ' Reset TMR1's Interrupt Flag

    If you're returning from an Interrupt then use RESUME otherwise if it's from a subroutine use RETURN.

    You may have to adjust the $E5 value slightly to trim your time accurately to account for instruction cycle time in setting the clock etc.

  2. #2
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    Melanie,
    I think we have our wires crossed a little.

    Are you setting up the timer to count internal pulses? I am trying to count a 60hz 50% duty cycle pulse from the mains supply. When I've counted 21600 of them, I want the counter to reset, send a increment to a counter, and start again.

    Therefore, I dont understand why we need to measure 16.67ms. This is the period between highs at the i/p. Time really has nothing to do with it, we just need to get to 21600 and say, ok, im done, reset me please :-)
    So thats why I have the numbers in there that I do. Start the counter at 43935, when we've counted 21600 pulses we should be at 65535. The next pulse will set the interupt, and we start again. Well, start the timer at 43936 I guess.

    65535 = $FFFF
    43935 = $AB9F
    21600 = $5460

    65535 - 21600 = 43935

    According to Microsoft's calculator.
    Thanks for the tidbit on the resume command.

    Disclaimer:- I know you're not stupid, so the natural conclusion is that I must be LOL. Thanks for your help Mel.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    No, it's my fault... not reading the thread properly from the beginning...

    What I told you was valid for the timer keeping it's own time...

    But, nevertheless if you want the Timer to count 21600 (or however many) pulses from an external source then yes, it's 65536-21600=43936, or $ABA0 that needs to be preset into TMR1H & TMR1L. Note I'm subtracting from 65536 ($0000 or zero) and not from 65535 ($FFFF), because the interrupt is on the roll from 65535 ($FFFF) to 65536 ($0000).

    Look at the T1CON Register for your PIC... you will also have to set TMR1CS for EXTERNAL input and provide your 60Hz pulses on the appropriate T1CKI pin for your PIC.

  4. #4
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    So I am on track with this?
    Timer counts up, sets the interupt. Interupt causes CounterA to advance by 1, which increments the digits for the display. Obviously, the segment drive logic is not there yet.



    Tenths var word
    Units var word
    Tens var word
    Hundreds var word
    Thousands var word
    Tenthousands vAR WORD

    Gosub SetTimer ' Set the Timer
    On Interrupt goto CounterA
    PIE1.0=1 ' Enable TMR1 Interrupts

    SetTimer:
    T1CON.0=0 ' Stop the Clock
    TMR1H=$AB ' Set Timer Highbyte
    TMR1L=$A0 ' Set Timer Lowbyte
    T1CON.1=1 ' Restart the Clock
    PIR1.0=0 ' Reset TMR1's Interrupt Flag
    Return

    CounterA:
    ' Timer Interrupt Handler
    ' =======================

    Gosub SetTimer ' Set the Timer for next count
    Tenths=Tenths+1 ' Increment 1/10TH minute Counter

    If Tenths>9 then
    Tenths=0
    Units=Units+1 ' Increment the Units

    If Units>9 then
    Units=0
    Tens=Tens+1 ' Increment the Tens

    If Tens>9 then
    Tens=0
    Hundreds=Hundreds+1 ' Increment the Hundreds

    If Hundreds>9 then
    Hundreds=0
    Thousands=Thousands+1 'Increment the Thousands

    If Thousands>9 then
    Thousands=0
    Tenthousands=Tenthousands+1 'Increment the Tenthousands

    endif
    endif
    endif
    endif
    endif
    endif
    endif
    Resume
    End

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Ummm.... on track?.... well maybe you're on a siding but you've not reached the main line yet... theory might be there, but reality it won't run - way to go yet...

    Tenths var word
    Units var word
    Tens var word
    Hundreds var word
    Thousands var word
    Tenthousands vAR WORD

    Where's the PIC initialisation here? No Registers are configured, no I/O, TMR1 is not set up to accept external pulses...

    Gosub SetTimer ' Set the Timer
    On Interrupt goto CounterA
    PIE1.0=1 ' Enable TMR1 Interrupts

    At this point your program runs into a subroutine without calling it. You should have a logical program loop.

    SetTimer:
    T1CON.0=0 ' Stop the Clock
    TMR1H=$AB ' Set Timer Highbyte
    TMR1L=$A0 ' Set Timer Lowbyte
    T1CON.1=1 ' Restart the Clock
    PIR1.0=0 ' Reset TMR1's Interrupt Flag
    Return

    Your program encounters a Return with nowhere to return to... so at this point it dies - quite apart from the fact it's counting INTERNAL clock ticks.

    You've not set any ENABLE/DISABLE to identify which sections of your code will be interruptable, and which sections should be protected from interrupt.

    That's just a starter without going into any depth.

  6. #6
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    I realize all the initialization settings are not there! I was just asking if what I posted made any sence. I also realize that there is no program loop, becuase I havent created it. I'm just trying to learn this stuff piece by piece. It easier for me to break it down into sections to figure exactly what is going on before I attempt to write a huge program with a 1000 mistakes only to get disheartened and pay someone to do it for me.

  7. #7
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Jm,

    Jm>>I was just asking if what I posted made any sence. I also realize that there is no program loop, becuase I havent created it. I'm just trying to learn this stuff piece by piece. It easier for me to break it down into sections to figure exactly what is going on before I attempt to write a huge program with a 1000 mistakes only to get disheartened and pay someone to do it for me.<<

    Naw, I think we can help you figure it out <smile>..

    I am curious... what are you going to use your hour meter for??? I am a pilot, and I am building a new airplane right now... I am going to use a PIC chip as a HOBBS meter for my Engine, as well as a RPM and a possibly a Altimeter/Velocity (if I can find a sensor that is cheap enough). Your project looks almost exactly like mine to many a degree, that is why I ask.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

Similar Threads

  1. Replies: 5
    Last Post: - 16th October 2009, 18:29
  2. Digital Out on an A/D pin safe ?
    By mr.sneezy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st January 2009, 22:48
  3. analog and digital
    By lerameur in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th June 2008, 02:40
  4. Replies: 4
    Last Post: - 24th January 2007, 22:20
  5. Digital IC Tester
    By precision in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th September 2006, 03:38

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts