[SOLVED !] Pulse counter memory problem


Today 09:31
Forum: Proton Plus Compiler v3
Starter: glenlivet
Views: 0
Replies: 10
Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Pulse counter memory problem85 days old

  1. #1
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    67
    Thumbs Up
    Received: 43
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Pulse counter memory problem

    Please tell me my faults.My pulse counter memory does not store.When i switch on device after 5 second ,memory exist by after 30 seconds it is washed display shows 9551 (this digit varies)

    my code is:
    Code:
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings
    
    
    Device = 16F886
    
    
    Config1 FOSC_INTRC_NOCLKOUT, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, BOREN_ON, IESO_ON, FCMEN_ON, LVP_OFF, DEBUG_OFF
    Config2 BOR4V_BOR40V, WRT_OFF
    
    
    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
     Xtal=4
    
     OSCCON = %01110001
    
     Dim DG1        As Byte       
     Dim DG2        As Byte    
     Dim DG3        As Byte
     Dim DG4        As Byte
     Dim DIGIT      As Byte
     Dim DG         As Byte
     Dim COUNTT     As Byte
     Dim I          As Byte
     Dim AdjVal     As Word
     Dim CountTT    As Byte
     Dim Teller     As Word
     Dim NUMB       As Word
     Dim N          As Word
     
    '==========================================
     
     ADCON1  = %10000000
     ADCON0  = %01000011 
     TRISA   = %00111101          
     TRISB   = 0   
     TRISC   = %11110000           
     ANSELH  = %00000001
     ANSEL   = %00000001
     CM1CON0 = 0
     CM2CON0 = 0
     VRCON   = 0
     
    '========================================== 
     
     N=ERead 03
     DelayMS 1000 
     
    '==========================================
     
     Main:
     
     If PORTA.3 = 0 Then EWrite 00,[N]
     
     If PORTA.3 = 0 Then             'counter
        If CountTT = 0 Then
            Inc Teller
        EndIf
        CountTT = 1
     Else
        CountTT = 0
     EndIf
     
     N = Teller
     
     If PORTA.3 = 1 Then EWrite 00,[N]
     
     If PORTA.2 = 0 Then               'tare routine
        AdjVal = Teller
     EndIf
     
     N = Teller - AdjVal
     
     GoSub DISPLAY                   'display subroutine
     GoSub DIGITCALC
     GoTo Main
     
    '==========================================
    
     DISPLAY:             'display subroutine
            
     For COUNTT = 0 To 99
    
     PORTB = DG1
     PORTC.3 = 0
     DelayUS 100
     PORTC.3 = 1
    
     PORTB = DG2
     PORTC.2 = 0
     DelayUS 100
     PORTC.2 = 1
    
     PORTB = DG3
     PORTC.1 = 0
     DelayUS 100 
     PORTC.1 = 1
            
     PORTB = DG4
     PORTC.0 = 0
     DelayUS 100 
     PORTC.0 = 1
    
     Next COUNTT
    
     Return
    
    '================================================
    
    DIGITCALC:
    
    DIGIT = 0
    
    LP1:
    
    If N < 1000 Then DS1
        
    N = N - 1000
    DIGIT = DIGIT + 1
    GoTo LP1
    
    '================================================
    
    DS1:
    GoSub FND
    DG1 = DG
           
    DIGIT = 0
    
    '================================================
    
    LP2:
    
    If N < 100 Then DS2
        
    N = N - 100
    DIGIT = DIGIT + 1
    GoTo LP2
    
    '================================================
    
    DS2:
    
    GoSub FND
    DG2 = DG
    DIGIT = 0
    
    '================================================
    
    LP3:
    If N < 10 Then DS3
    N = N - 10
    DIGIT = DIGIT + 1
    GoTo LP3
    
    '================================================
    
    DS3:
    GoSub FND
    DG3 = DG | 1
    
    DIGIT = N
    GoSub FND
    DG4 = DG
     
    Return
    
    '================================================
    
    FND:
    
    FND0:
    
    If DIGIT > 0 Then FND1
    DG = %00000011                       '%0111 1110      
    GoTo FNDEND
    
    '------------------------------------------------
    
    FND1:
    
    If DIGIT > 1 Then FND2
    DG = %10011111                       '%0100 1000      
    GoTo FNDEND
    
    '------------------------------------------------
    
    FND2:
    
    If DIGIT > 2 Then FND3
    DG = %00100101                       '%0011 1101      
    GoTo FNDEND
    
    '------------------------------------------------
    
    FND3:
    
    If DIGIT > 3 Then FND4
    DG = %00001101                       '%0110 1101      
    GoTo FNDEND
    
    '------------------------------------------------
    
    FND4:
    
    If DIGIT > 4 Then FND5
    DG = %10011001                       '%0100 0011      
    GoTo FNDEND
    
    '------------------------------------------------
    
    FND5:
    
    If DIGIT > 5 Then FND6
    DG = %01001001                       '%0110 0111      
    GoTo FNDEND
    
    '------------------------------------------------
    
    FND6:
    
    If DIGIT > 6 Then FND7
    DG = %01000001                       '%0111 0111      
    GoTo FNDEND
    
    '------------------------------------------------
    
    FND7:
    
    If DIGIT > 7 Then FND8
    DG = %00011111                       '%0100 1100      
    GoTo FNDEND
    
    '------------------------------------------------
    
    FND8:
    
    If DIGIT > 8 Then FND9
    DG = %00000001                       '%0111 1111      
    GoTo FNDEND
    
    '------------------------------------------------
    
    FND9:
    DG = %00011001                       '%0110 1111      
    
    '================================================
    
    FNDEND:
    Return
    
    '================================================
    Last edited by joesaliba; 22nd September 2018 at 16:27.

  2. #2
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,205
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    456.72 MB

    0 Not allowed!

    Default Re: Pulse counter memory problem

    Hi Amod,
    Unfortunately I cannot figure out exactly what you are doing but I do have a couple of suggestions.

    Comment your code, you might understand it be others may not, it also helps when you come back to it 6 months and several projects later. (I know this from experience)

    Don't try to re-invent the wheel, the first place I normally look is in the examples to see if there is anything close to what I need, not for the whole project but for sections of it.

    As above, work in small steps, prove your code in sections IE do the counter first and then the 7 segment display and later EEPROM read write. The free VSM is a great tool for this, find one similar to what you need and simulate the code, if/when it goes wrong you can single step through to hopefully pinpoint the issue but more important, we all have the free VSM's so can simulate the code as well.



    Regards,
    Bob

  3. #3
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    67
    Thumbs Up
    Received: 43
    Given: 4
    Total Downloaded
    5.95 MB

    1 Not allowed!

    Default Re: Pulse counter memory problem

    Bob.
    Everything is working like counter, seven segments etc. Only problem I am facing is to store counter values on electricity failures.

  4. #4
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,205
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    456.72 MB

    0 Not allowed!

    Default Re: Pulse counter memory problem

    Hi,
    I am not that clued up on EPROM as not really used it but is it that you are writing to address 00 but reading from 03?.


    Bob

  5. #5
    Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    385
    Thumbs Up
    Received: 71
    Given: 0
    Total Downloaded
    154.34 MB

    0 Not allowed!

    Default Re: Pulse counter memory problem

    Bob beat me to it.

    Also, if you look at your main loop...
    Code:
    N=ERead 03
    
    main:
    If PORTA.3=0 Then EWrite 00,[N]
    
    If PORTA.3=1 Then EWrite 00,[N]
    goto main
    You're going to write to the eeprom at least once for each iteration of that loop which is going to eventually wear out the eeprom.

  6. #6
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    67
    Thumbs Up
    Received: 43
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Re: Pulse counter memory problem

    Then what should I do. I need memory to my counter when there is power failure. I made a temperature controller with setpoint memory, it is working fine.

  7. #7
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,205
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    456.72 MB

    0 Not allowed!

    Default Re: Pulse counter memory problem

    Then what should I do

    As tumbleweed says, you will write to the EEPROM every cycle which is probably several thousand times per second even if the data has not changed.

    What I would do is copy the data value to another variable at the end of your routine, on the line before you can then compare if if has changed and if it has then write to the EEPROM.
    something like
    If NewData <> OldData then write to EEPROM 'Data has changed so write to the EEPROM
    OldData = NewData 'Make new and old data the same so no need to write to EEPROM unless it changes.

    Regards,
    Bob

  8. #8
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    67
    Thumbs Up
    Received: 43
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Re: Pulse counter memory problem

    OK Bob. I will try and get back to you tomorrow.
    Thanks

  9. #9
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,021
    Thumbs Up
    Received: 313
    Given: 120
    Total Downloaded
    1.51 GB

    1 Not allowed!

    Default Re: Pulse counter memory problem

    That's exactly the way with eeprom Bob.

    It's something I'm contemplating building into the eeprom writing routine of the compiler. Read eeprom from the address give, and if the same as the byte being written, just return, but if different, perform the write. Maybe a new declare to enable it, but keep the default of the compiler to the way it is now. That will ensure existing code is not larger if compiled with an updated version.

    You need to be careful how many times you write to eeprom Amod. They have quite a few thousand write cycles lifespan, but that can be exhausted very quickly.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  10. #10
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,375
    Thumbs Up
    Received: 86
    Given: 23
    Total Downloaded
    4.04 GB

    1 Not allowed!

    Default Re: Pulse counter memory problem

  11. Amod,

    As suggested include as many comments as you can. I do also add a comment for an Endif!

    I know that everyone have his owns and means how to write code. But I would suggest to make it more readable and easy on the eye.

    I did a bit of editing to your original format of the code. I did not change any code. But as you can see I did some separation lines between labels and adding some spacing to numbers where required.

    Also please when posting a code wrap it around `Wrap Code' option. In this way it is more pleasant.

    Now for your original question.

    You only want the code to store to eeprom memory when there is a power OFF or when you change a number?

    If you need to store the number upon power OFF, how are you detecting a power OFF?
    Regards

    Joseph

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. [SOLVED !] Pulse counter using COUNTER command
    By amod in forum Absolute Beginners Section
    Replies: 33
    Last Post: 28th August 2018, 19:37
  2. [SOLVED !] Problem in pulse per second meter
    By amod in forum Absolute Beginners Section
    Replies: 20
    Last Post: 19th April 2018, 16:48
  3. pulse counter with single LED to display total
    By Automods in forum Proton Plus Compiler v3
    Replies: 17
    Last Post: 14th July 2011, 16:05
  4. [SOLVED !] Counter pulse width/rise time?
    By GregZ in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 22nd July 2009, 16:20
  5. Pulse counter using capture interrupts
    By HelpMe! in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 30th November 2007, 16:37

Posting Permissions

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