Yesterday 20:34
Forum: Website / Forum Issues
Starter: rcurl
Views: 0
Replies: 6
Yesterday 14:15
Forum: Absolute Beginners Section
Starter: amod
Views: 0
Replies: 29
Yesterday 14:11
Forum: The Lounge
Starter: pic-ignorant
Views: 0
Replies: 2
Closed Thread
Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30

Thread: Simple timer40 days old

  1. #21
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,359
    Thumbs Up
    Received: 85
    Given: 23
    Total Downloaded
    4.03 GB

    0 Not allowed!

    Default Re: Simple timer

    See Mos,

    As I said earlier you cannot do the Print in the loop to show the remaining time as this is time consuming and instead of say, 45 seconds, you end up with 80 seconds. I know because I tried it.

    Having said that, it could be done to just update the display every second, and timing will be out with a couple of seconds.

    Regarding my code, I tried it in real hardware, and as See Mos said it works. If you want that the output is reversed just change: -

    PORTA.0 = 1 ' turn ON output

    to

    PORTA.0 = 0

    and

    PORTA.0 = 0 ' turn OFF output

    to

    PORTA.0 = 1
    Regards

    Joseph

  2. #22
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,359
    Thumbs Up
    Received: 85
    Given: 23
    Total Downloaded
    4.03 GB

    0 Not allowed!

    Default Re: Simple timer

    Quote Originally Posted by amod View Post
    Every thing is working but not relay pls ckeck,

    Dim in As Byte
    Dim innt As Byte


    TRISA=1
    TRISC=%11111111
    TRISB=0
    TRISD=%11111110
    TRISE=0


    main:
    If PORTD.6=0 Then Inc innt 'increase count when portd.6 is high
    If PORTD.7=0 Then Dec in ' decrease count when portd.7 is high
    If innt>60 Then innt=0 'count not more then 60
    DelayMS 250
    If in=innt Then 'relay logic
    PORTB.1=0
    Else
    PORTB.1=1
    EndIf

    Print At 1,7,Dec2,innt
    Print At 1,1,"IN=",Dec2,in
    GoTo main
    I am sorry but I cannot help you with this code. I did my best to come up with a working code and believe me I spent quite some time, I know the code I posted works so not going to see this code.
    Regards

    Joseph

  3. #23
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,209
    Thumbs Up
    Received: 16
    Given: 0
    Total Downloaded
    614.99 MB

    0 Not allowed!

    Default Re: Simple timer

    No, I couldn't work out that last bit of code either
    My RAM is failing

  4. #24
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    65
    Thumbs Up
    Received: 39
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Re: Simple timer

    By this code i got my work done. Thanks all.IMG_20181014_212932.jpgIMG_20181014_212932.jpgIMG_20181014_212932.jpg

    Dim in As Byte
    Dim innt As Byte


    TRISA=1
    TRISC=%11111111
    TRISB=0
    TRISD=%11111110
    TRISE=0


    in=0
    main:
    If PORTD.6=1 Then innt=ERead 01
    If PORTD.6=0 Then Inc innt 'increase count when portd.6 is high
    If PORTD.6=0 Then EWrite 01,[innt]
    If PORTD.7=0 Then Inc in ' decrease count when portd.7 is high
    If innt>60 Then innt=0 'count not more then 60
    DelayMS 250


    If in=innt Then 'relay logic
    PORTB.1=0
    Else
    PORTB.1=1
    EndIf


    Print At 1,7,Dec2,innt
    Print At 1,1,"IN=

  5. #25
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,209
    Thumbs Up
    Received: 16
    Given: 0
    Total Downloaded
    614.99 MB

    0 Not allowed!

    Default Re: Simple timer

    There are still problems with Amods code but now I understand, it is not a timer, it is a pulse counter

    By the way Joseph, I would never use a software timer for more than a couple of seconds. I would always use a variation of a piece of code I call Tim's Timer which uses timer interrupts. Thanks Tim
    My RAM is failing

  6. #26
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,359
    Thumbs Up
    Received: 85
    Given: 23
    Total Downloaded
    4.03 GB

    0 Not allowed!

    Default Re: Simple timer

    Quote Originally Posted by See_Mos View Post
    I would always use a variation of a piece of code I call Tim's Timer which uses timer interrupts. Thanks Tim
    Exactly. See my comment in post #18.

    This week I just done a controller / timer for a jacuzzi. As I am using the same button to start or stop before the time elapse I use a couple of timers within an interrupt to make the debounce of the push button, (a piezo push button!).

    Once you get used to interrupts, and I am no expert at them, the first thing I do in a code is setup an interrupt and see if it fires.
    So if I ever need it, which is a 95% of all cases, I use it.
    Regards

    Joseph

  7. #27
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,209
    Thumbs Up
    Received: 16
    Given: 0
    Total Downloaded
    614.99 MB

    0 Not allowed!

    Default Re: Simple timer

    duplicate post removed
    My RAM is failing

  8. #28
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,359
    Thumbs Up
    Received: 85
    Given: 23
    Total Downloaded
    4.03 GB

    0 Not allowed!

    Default Re: Simple timer

    Quote Originally Posted by See_Mos View Post
    duplicate post removed
    I had seen what you wrote before you edited the post.

    Have a look at my comment in post #15 regarding printing and interrupt. You are all correct in what you are saying.
    Regards

    Joseph

  9. #29
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    65
    Thumbs Up
    Received: 39
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Re: Simple timer

    Thanks all. I will be back with new problems.

    My new project is usb temperature data logger.
    Last edited by amod; 14th October 2018 at 19:16.

  10. #30
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,209
    Thumbs Up
    Received: 16
    Given: 0
    Total Downloaded
    614.99 MB

    0 Not allowed!

    Default Re: Simple timer

    Just had a look on the forum to see if I could find Tim's post and I see that Les also posted an interrupt timer. If anyone wants to know more search the forum for 'stopwatch'
    My RAM is failing

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. simple timer query
    By staffstony in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 18th July 2008, 09:11
  2. How to turn 8-bit timer into 16-bit timer?
    By HelpMe! in forum Proton Plus Compiler v3
    Replies: 6
    Last Post: 29th October 2007, 21:08
  3. Timer example
    By smclark in forum The Lounge
    Replies: 8
    Last Post: 6th September 2007, 17:04
  4. Timer
    By FabioPedro in forum The Lounge
    Replies: 5
    Last Post: 9th June 2007, 21:49
  5. simple second timer
    By crankshaft in forum Proton Plus Compiler v3
    Replies: 17
    Last Post: 27th May 2007, 01:14

Posting Permissions

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