Simple pulse counter and display using PIC 16F627

Discussion in 'Embedded Systems and Microcontrollers' started by woodysgreen, Nov 5, 2009.

  1. woodysgreen

    Thread Starter New Member

    Nov 5, 2009
    3
    0
    Hi guys, first time here

    I have just had some work experience and have been asked to look at a counter which will display the amount of electricity used every minute. eg the counter will receive pulses from an electricity meter and after one minute display the count on a 3*7-segment display. The counter should then reset and begin counting the next minute with the display still holding the previous minutes count, after the next minute it should display the new count.

    I have bought a PIC programmer and experiment board (K8048) with a PIC 16F627 and I'm trying to learn via modifying code to get the near the result. Could anybody give me some guidance as to how I set-up the counter and the minute timer.

    Any help is much appreciated.
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Some of the internal timers of the PIC can be used as counters which can count external pulses. If non is able to do that use an input pin and increment a variable each time a pulse arrives. Use delay functions to create the one minute delay which will read the value from the counter or the variable and display it and restart the counting. If possible an interrupt can be triggered every minute instead of delays.
     
  3. woodysgreen

    Thread Starter New Member

    Nov 5, 2009
    3
    0
    I'm trying the input pin and incrementing a variable. i'm determined to complete this at the weekend. Thanks for the reply mik3
     
  4. woodysgreen

    Thread Starter New Member

    Nov 5, 2009
    3
    0
    Completely desperate.

    Can anyboby give me a starting point with my problem. I have tried the incf command but can't even get my led's to count up in binary. I don't know where I'm going wrong.

    COUNT EQU b'00000000'

    SWITCH_1 BTFSC PORTA,0
    GOTO ADD
    GOTO SWITCH_1

    ADD INCF COUNT,0
    MOVWF PORTB
    RETLW COUNT
    END
     
  5. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    You have to create a loop for the whole program as to repeat again and again.

    For example:

    LOOP

    COUNT EQU b'00000000'

    SWITCH_1 BTFSC PORTA,0
    GOTO ADD
    GOTO SWITCH_1

    ADD INCF COUNT,0
    MOVWF PORTB
    RETLW COUNT

    GOTO LOOP
    END
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I think this might be what you are trying to do. You will find that this increases the counter very quickly all the time the button is pressed (or not pressed depending on the circuit) so some more code will be required to make it count once per press.

    COUNT EQU b'00000000'


    SWITCH_1 BTFSC PORTA,0
    CALL ADD
    GOTO SWITCH_1

    ADD INCF COUNT,F
    MOVF COUNT, W
    MOVWF PORTB
    RETURN


    END
     
Loading...