Shop OBEX P1 Docs P2 Docs Learn Events
Count every other second instead of every second with a DS1302 Time Chip ....>> — Parallax Forums

Count every other second instead of every second with a DS1302 Time Chip ....>>

sam_sam_samsam_sam_sam Posts: 2,286
edited 2009-06-21 19:41 in General Discussion
Hi EveryOne

This is a project that I have been ·ask to do·by employer Updated

As of right now I can not give all of the details.......................
................·but when the Project is done I will share with all of you on the Forum


We have a process that we do that we need to keep track of how much product·is left in the ·silo
so we can call the vendor to order more product there is NO WAY to put a scale to weight the silo

The only way is to do this is time how much ·product is used in one minute and keep track of it that way

Here·is my new Problem

Because our Silo hold 50,000 pounds and seconds that I am using roll over before I get to 50,000 count
so· is there a way to count every other second instead of every second

This is what i am using right now

PD = PDSecs */102··············· ·' PD = P Basic Math· 0.4 Pound Per Seconds 256 X 0.4 = 102
SL = SLSecs */102··············· ·' SL = P Basic Math· 0.4 Pound Per Seconds 256 X 0.4 = 102

IF oldsecs <> secs THEN······ · ' This Routine Compars the oldsecs to secs
·· oldsecs = secs················· ·' This Routine is so that Counter Update once a Seconds
·· PDSecs = PDSecs + 1········ ·' These Couter is need so math can be done
·· SLSecs = SLSecs + 1

ENDIF

Is there an easy way to do this





▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 6/21/2009 8:31:48 PM GMT

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2009-06-19 01:12
    Sam

    How do You know that the feed rate is .4 pounds per sec?


    _________$WMc%______

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············································ BoogerWoods, FL. USA
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-19 01:24
    Because the test that we did

    We put 300 pound· in the hoper and time how long took to empty hoper which was 12 minutes and 40 seconds

    took that 12 x 60 = 720 + 40 = 760

    300 / 760 = .3947 which I used 0.4



    When you·run the timer after 12 minutes and 41· it shows 300 pounds which is close enough

    Now I could do this routine but is there another way to this, the part in RED

    IF oldsecs <> secs THEN····· · ' This Routine Compars the oldsecs to secs
    ··· oldsecs = secs············ ·· ·' This Routine is so that Counter Update once a Seconds

    ··· b = b + 1

    ··· ELSEIF b = 2 THEN
    ··· b = 0
    ····SLsecs· =· SLsecs· + ·1

    ··· PDsecs· =· PDsecs· +· 1

    ·ENDIF

    I know that would need this change to

    ·
    PD = PDSecs */102··············· ·' PD = P Basic Math· 0.4 Pound Per Seconds 256 X 0.4 = 102
    SL = SLSecs */102··············· ·' SL = P Basic Math· 0.4 Pound Per Seconds 256 X 0.4 = 102

    PD = PDSecs */204·················' PD = P Basic Math· 0.8 Pound Per 2 ·Seconds 256 X 0.8 = 204
    SL = SLSecs */204·················' SL = P Basic Math· 0.8 Pound Per 2 ·Seconds 256 X 0.8 = 204


    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/19/2009 2:30:52 AM GMT
  • SRLMSRLM Posts: 5,045
    edited 2009-06-19 03:18
    You could add every other second in a single line like this (pseudo code):

    total += current_seconds (MOD) 2
    



    This will create a running total that keeps track of all the odd seconds (1,3, ..., 57, 59, 1, ...) that pass by. It assumes that current_seconds is in the range of 0 to 60.
  • mosquito56mosquito56 Posts: 387
    edited 2009-06-19 15:39
    Can't u just reconfigure the timer chip to fire every 2 seconds instead of 1 sec. I don't know what a ds1302 is.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·······

    ······· "What do you mean, it doesn't have any tubes?"
    ······· "No such thing as a dumb question" unless it's on the internet
    ········
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-06-19 17:42
    Every other second implies an unspecified starting point. If you really want every 2 second you can just read BIT 0 of the seconds register. When it is 0 the seconds are even, when it is 1 they are odd. So if you do you event whenever BIT 0 is set you will do it every odd second or every 2 seconds. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-20 02:09
    Chris

    Thank You for your reply

    I can read the (0) and (1) but it advances the counter every second

    Which help me a lot Thank You for your help in this project

    DO
    GOSUB Get_secs

    ·DEBUG HOME,HEX secs,CR,· DEC3 s························ ·' To Read The Seconds
    LOOP

    Get_secs:····················································· · ' DS1302 Reads the Read the Seconds Register
    · HIGH CS1302··············································· · ' Select DS1302
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdSecs]
    · SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs.BIT0]
    · LOW CS1302················································ · ' Deselect DS1302
    · RETURN


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/21/2009 8:59:10 PM GMT
  • $WMc%$WMc% Posts: 1,884
    edited 2009-06-20 05:54
    SAM3

    s = s + 2

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············································ BoogerWoods, FL. USA
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-20 20:17
    I think you are missing what I am trying to do

    I am using the DS1302 for two thing one is to save the data in ram

    The other thing that I am using is the second register as a triggering point for the counters that I· am using

    they are·seconds that have gone by but that is the only way you can do this

    That is why I was hoping there was a way to this with the DS1302 Time Chip to not have a third counter·like I had posted earlyer



    This with using every second

    1·second =·.4 pound··· to··· 65535 seconds =··26214 pounds · which mean that my counter has roll over

    Now if I could use every other second

    1·seconds = .8 pounds· to··· 40000 seconds = 50000 pounds· which mean that counter would not roll over






    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/20/2009 8:37:36 PM GMT
  • SRLMSRLM Posts: 5,045
    edited 2009-06-20 23:33
    What's wrong with my method or the idea that Chris posted?
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-21 00:33
    SRLM

    Thank You for your reply

    I must not have done something right with what·I try ed because the seconds would update every seconds

    ether that or I am not understanding how to write the code to do it that why I posted one of thing I try ed

    Could you give an example of how to write it

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/21/2009 12:38:55 AM GMT
  • SRLMSRLM Posts: 5,045
    edited 2009-06-21 01:08
    total = total + (current_seconds <> 2)
    



    That would be the PBASIC version. Total is a running total of the number of odd seconds. current_seconds is the current second in the range of 0-59.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-21 01:29
    SRLM

    I will try tomorrow Thank You for your help

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-21 19:41
    SRLM

    Thank You for your reply and ALL the help that you have give in the past

    It did not work for me......>>>>>..BUT..>>>>

    You got me thinking about a Project that I·also was·working on for the company that I work for
    and some help that I got from·......>>>>

    I want to Thank Tracy Allen for sharing this code routine with me and all of his help in the the past

    ·Tracy Allen .....>>>> State Machine Logic For InPut Pin

    ····························· So I·thought about this, if this would work for me in this case·and· it works very well

    This where Tracy help with this other ·Project

    It update The PDSecs· and SLSecs every two seconds just what I was looking for




    xbit··········· VAR···· Bit············ ' current state
    x0············· VAR···· Bit············ ' previous state
    xx············· VAR···· Bit············ ' change of state from·0 to 1

    ·
    ·
    xbit = secs.BIT0
    · xx = xbit ^ x0 & x0
    · x0 = xbit


    · PDSecs = PDSecs + xx······ ' These Counter's are need so math can be done
    · SLSecs = SLSecs + xx

    PD = PDSecs */204········ ' PD = P Basic Math· 0.4 Pound Per Seconds 256 X 0.4 = 102· or ·0.8 Pounds·Per ·every two seconds 256 X 0.8 =·204
    SL = SLSecs */204········ ' SL = P Basic Math· 0.4 Pound Per Seconds 256 X 0.4 = 102· ·or ·0.8 Pounds·Per ·every two seconds 256 X 0.8 =·204

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/21/2009 8:56:46 PM GMT
Sign In or Register to comment.