Loading ...
Sorry, an error occurred while loading the content.

7 Segment Counter

Expand Messages
  • donald1343
    Hello all. I am completely new to all things JAL and PIC, so please bear with me if my problem seems so simple to the rest of you ! Please find my code : --JAL
    Message 1 of 6 , Feb 1, 2011
    • 0 Attachment
      Hello all. I am completely new to all things JAL and PIC, so please bear with me if my problem seems so simple to the rest of you ! Please find my code :
      --JAL 2.4
      include 16F877A_bert
      include 7segmentCommonCathode
      pin_d1_direction=output --pin 20 units 7segment
      pin_d2_direction=output --pin 21 tens 7segment
      --variables
      var byte unit
      var byte unitseg1
      var byte unitseg2
      var bit unitseg is pin_d1
      var bit tenseg is pin_d2
      unit=0
      tens=0
      forever loop
      delay_1s(1)
      unit=unit+1
      if unit==20 then --not critical
      unit=0
      end if
      unitseg1=unit/10 --tens
      unitseg2=unit-(unitseg1*10) --units
      for 10 loop
      unitseg=1
      segnumber(unitseg2)
      delay_10ms(1)
      unitseg=0
      tenseg=1
      segnumber(unitseg1)
      delay_10ms(1)
      tenseg=0
      end loop
      end loop
      It works, but will not update without flashing both segments. How can I get it to update smoothly? ( have looked through previous questions and tried lots of combinations, but feel as though I am missing something fundamental ).
      Many thanks
    • Bert van Dam
      ... The 1 second delay is too long. The loop already contains two 10 ms delays, so you may use these to update the unit counter. So remove the 1 second delay
      Message 2 of 6 , Feb 1, 2011
      • 0 Attachment
        >It works, but will not update without flashing both
        >segments. How can I get it to update smoothly? (

        The 1 second delay is too long. The loop already contains two 10 ms delays,
        so you may use these to update the unit counter. So remove the 1 second
        delay and reset the unit counter not at 20 but at 100 or so.

        Have fun,
        Bert


        www.vandam.tk
      • donald1343
        ... Thanks Bert My fault...this counter is to increment at 1 second intervals ( I was hoping that by repeating the code for minute and hours and using 4 7seg
        Message 3 of 6 , Feb 1, 2011
        • 0 Attachment
          --- In jallist@yahoogroups.com, "Bert van Dam" <bymco.bv@...> wrote:
          >
          > >It works, but will not update without flashing both
          > >segments. How can I get it to update smoothly? (
          >
          > The 1 second delay is too long. The loop already contains two 10 ms delays,
          > so you may use these to update the unit counter. So remove the 1 second
          > delay and reset the unit counter not at 20 but at 100 or so.
          >
          > Have fun,
          > Bert
          >
          >
          > www.vandam.tk
          >
          Thanks Bert
          My fault...this counter is to increment at 1 second intervals ( I was hoping that by repeating the code for minute and hours and using 4 7seg displays (then not displaying the seconds), I could make a simple clock ). Removing the 1 sec delay works great but the timing is now incorrect. I have combined the code for your lcd clock ( works fine using the lcd )and the 2 7segment displays.
        • Bert van Dam
          ... I think your timing is incorrect already because your current looplength is 1 second + 10 times (10 mS + 10 mS) = 1.2 seconds, which makes your clock slow.
          Message 4 of 6 , Feb 1, 2011
          • 0 Attachment
            >Removing the 1 sec delay works great but the timing is now incorrect.

            I think your timing is incorrect already because your current looplength is
            1 second + 10 times (10 mS + 10 mS) = 1.2 seconds, which makes your clock
            slow. So what you need is a delay of 0.8 seconds, but in small pieces to
            keep the display updated.

            For example replace:

            delay_1s(1)
            unit=unit+1
            if unit==20 then --not critical

            By (declare counter as a byte):

            -- delay_1s(1)
            counter = counter+1
            if counter == 4 then
            unit=unit+1
            counter=0
            end if
            if unit==20 then --not critical

            Now the looplength is 4 times 10 times (10 mS + 10 mS) = 1 second.

            >I have combined the code for your lcd clock ( works fine using the lcd )and
            >the 2 7segment displays.

            Excellent idea.

            Have fun,
            Bert


            www.vandam.tk
          • donald1343
            ... Have put the revised code together...it works ! Thank goodness for your feedback.I ve been at this now for a month and just hit a brick wall. It looked
            Message 5 of 6 , Feb 1, 2011
            • 0 Attachment
              --- In jallist@yahoogroups.com, "Bert van Dam" <bymco.bv@...> wrote:
              >
              > >Removing the 1 sec delay works great but the timing is now incorrect.
              >
              > I think your timing is incorrect already because your current looplength is
              > 1 second + 10 times (10 mS + 10 mS) = 1.2 seconds, which makes your clock
              > slow. So what you need is a delay of 0.8 seconds, but in small pieces to
              > keep the display updated.
              >
              > For example replace:
              >
              > delay_1s(1)
              > unit=unit+1
              > if unit==20 then --not critical
              >
              > By (declare counter as a byte):
              >
              > -- delay_1s(1)
              > counter = counter+1
              > if counter == 4 then
              > unit=unit+1
              > counter=0
              > end if
              > if unit==20 then --not critical
              >
              > Now the looplength is 4 times 10 times (10 mS + 10 mS) = 1 second.
              >
              > >I have combined the code for your lcd clock ( works fine using the lcd )and
              > >the 2 7segment displays.
              >
              > Excellent idea.
              >
              > Have fun,
              > Bert
              >
              >
              > www.vandam.tk
              >
              Have put the revised code together...it works ! Thank goodness for your feedback.I've been at this now for a month and just hit a brick wall. It looked like a timing problem but I had no idea what was happening.
              Many Thanks for your help.
            • a_b_aldus
              Don, We recently had similar topic here and I posted somehow lengthy explanation of the approach to this kind of tasks. Here is the thread reference:
              Message 6 of 6 , Feb 1, 2011
              • 0 Attachment
                Don,

                We recently had similar topic here and I posted somehow lengthy
                explanation of the approach to this kind of tasks. Here is the
                thread reference:
                http://tech.groups.yahoo.com/group/jallist/message/30053

                Arcady

                --- In jallist@yahoogroups.com, "donald1343" <don.langley@...> wrote:
                >
                >
                >
                > --- In jallist@yahoogroups.com, "Bert van Dam" <bymco.bv@> wrote:
                > >
                > > >Removing the 1 sec delay works great but the timing is now incorrect.
                > >
                > > I think your timing is incorrect already because your current looplength is
                > > 1 second + 10 times (10 mS + 10 mS) = 1.2 seconds, which makes your clock
                > > slow. So what you need is a delay of 0.8 seconds, but in small pieces to
                > > keep the display updated.
                > >
                > > For example replace:
                > >
                > > delay_1s(1)
                > > unit=unit+1
                > > if unit==20 then --not critical
                > >
                > > By (declare counter as a byte):
                > >
                > > -- delay_1s(1)
                > > counter = counter+1
                > > if counter == 4 then
                > > unit=unit+1
                > > counter=0
                > > end if
                > > if unit==20 then --not critical
                > >
                > > Now the looplength is 4 times 10 times (10 mS + 10 mS) = 1 second.
                > >
                > > >I have combined the code for your lcd clock ( works fine using the lcd )and
                > > >the 2 7segment displays.
                > >
                > > Excellent idea.
                > >
                > > Have fun,
                > > Bert
                > >
                > >
                > > www.vandam.tk
                > >
                > Have put the revised code together...it works ! Thank goodness for your feedback.I've been at this now for a month and just hit a brick wall. It looked like a timing problem but I had no idea what was happening.
                > Many Thanks for your help.
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.