Yesterday 23:49
Forum: Proton Plus Compiler v3
Starter: xldaedalus
Views: 0
Replies: 11
Go to last post By: tumbleweed
Yesterday 19:54
Forum: Proton Plus Compiler v3
Starter: joesaliba
Views: 0
Replies: 4
Yesterday 18:02
Forum: Proton Studio
Starter: GAMBOA
Views: 0
Replies: 1
Yesterday 14:28
Forum: Timer Modules
Starter: See_Mos
Views: 0
Replies: 1
Yesterday 14:23
Forum: The Lounge
Starter: craig
Views: 0
Replies: 24
+ Reply to Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 30

Thread: Simple timer5 days old

  1. #11
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,188
    Thumbs Up
    Received: 16
    Given: 0
    Total Downloaded
    603.66 MB

    0 Not allowed!

    Default Re: Simple timer

    Try this, the timer counts down as long as D.7 is high

    Code:
    Dim Timer_Count As Byte    
    main:
        Print At 1,1,Dec2 Timer_Count       ' show a leading zero if less than 10
        
        If PORTD.7 = 1 And Timer_Count > 0 Then
            PORTB.1 = 0                        ' relay is off
            DelayMS 1000
            Dec Timer_Count
        Else
            PORTB.1 = 1                        ' relay is on
            DelayMS 500
            If PORTD.6 = 1 And Timer_Count < 60 Then Inc Timer_Count
        EndIf
    GoTo main
    My RAM is failing

  2. #12
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    51
    Thumbs Up
    Received: 33
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Re: Simple timer

    Dear See_Mos,

    I want when time reaches 0 then relay should on.Presently relay is on and when reaches 0 relay goes off.

    Secondly,when input pulse is break in between setpoint time should restart from setpoint ,not where when pulse is break.Set point should be in memory.

    Iam trying with different codes,i will let you my progress tomorrow.

    Thanks

  3. #13
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,346
    Thumbs Up
    Received: 83
    Given: 23
    Total Downloaded
    3.86 GB

    0 Not allowed!

    Default Re: Simple timer

    I will try to come with something tomorrow, too busy today.

    When the counter reach zero, how long should the pulse stay ON?
    Regards

    Joseph

  4. #14
    Junior Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    51
    Thumbs Up
    Received: 33
    Given: 4
    Total Downloaded
    5.95 MB

    0 Not allowed!

    Default Re: Simple timer

    Pulse will be till 0.

  5. #15
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,346
    Thumbs Up
    Received: 83
    Given: 23
    Total Downloaded
    3.86 GB

    0 Not allowed!

    Default Re: Simple timer

    I did some code, tested on real hardware and it works. It is doing what I understand what you want.

    Please note the following: -

    in my case, I had to use different pins: -

    To start the pulse press PORTC.0. Change this if you want other pin.
    To stop the pulse, press PORTC.1 or when the 45 seconds had passed. Change as you need.

    For the program to detect immediately the start or stop, you cannot use a delay of 1 second inside a loop, as you need to wait for the one second to pass.

    Instead, I used a Word variable loaded with 45000, and make a delay of 1ms. Like this no problem to start and stop pulse as you wish.

    MOST IMPORTANT! As you are not using interrupts, you CANNOT use PRINT to see the timing. The print to an LCD takes too much time to execute, and instead for example 45 seconds, it ends up with more than a minute.

    If you want to see progress on a display, it is better to use a serial terminal and use HRSout.

    This is the code. I could have done it a bit more simple but for you to understand what is going on is better like that: -

    Code:
    Dim Onn As Word = 45000     ' 45 seconds used in main routine
    Dim Run As Bit = 0          ' Flag used to indicate if pulse is ON
    
    
    '****************
    '* Main routine *
    '****************
    '>>>Main routine<<<
    
    Main:
    
    ' Note: - To make some tests I used the following code: -
        ' PORTC.0 = Start and continue pulse if PORTC.0 = 1
        ' PORTC.0 = Stop pulse and reset counter if PORTC.0 = 0
        ' PORTA.0 = Pulse output 
    
    ' Run pulse for 45 seconds
    If Run = 0 Then             ' If output pulse is OFF then
        If PORTC.0 = 1 Then     ' if PORTC.0 = 1 then
            Run = 1             ' flag that we need to output pulse and start timer
        EndIf                   ' End If...Then instruction
    EndIf                       ' End If...Then instruction
    
    '----------------------------------------------------------------------------------------
    ' Stop pulse and reload 45 seconds
    
    If Run = 1 Then                     ' If output pulse is ON then 
        If PORTC.1 = 1 Or Onn = 0 Then  ' If PORTC.1 = 1 or timer reached 0 then 
            Run = 0                     ' flag that output pulse is low
        EndIf                           ' End If...Then instruction
    EndIf
    
    '----------------------------------------------------------------------------------------
    ' Check if pulse needs to be ON or OFF
    
    If Run = 1 Then             ' If we need to output pulse then    
        PORTA.0 = 1             ' turn ON output 
        Dec Onn                 ' begin to decrease timer
        DelayMS 1               ' Delayms 1 so code is not stuck and use 45000 for 45s
                                ' therefore, if PORTC.1 is pressed it will stop output and
                                ' reload 45s in variable Onn,
        Else PORTA.0 = 0        ' turn OFF pulse
             Onn = 45000        ' reload Onn with 45000
    EndIf                       ' End If...Then instruction
        
    
    'Print At 1,1, "IN= " , Dec Onn , "  "
    
    GoTo Main 
    
    '========================================================================================
    Regards

    Joseph

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

    0 Not allowed!

    Default Re: Simple timer

    Thanks Joseph,

    But actually it is not working as what I wanted.

    I also tried many codes but failed each time.

    I think that iam not able to tell you what I wanted. This time I'll tell you in Steps.

    1)maximum seconds 60.

    2) Continuous pulse on pin to activate timer.

    3) time setted suppose 34 seconds ,which can be easily changed by a button.only single button should be there to increase time 0 to 60 then goes to 0 to 60 again.

    4) relay is off when timer is not activated.

    5)suppose a 34 second time is set by set button then a continuous pulse is given to timer ,timer starts decreasingly 34 33 32 31 30 29 till 0 when it reaches 0 then timer should stop and relay should activate.

    6)Now pulse goes low then relay should be active till again pulse is given.when again pulse is given then timer should start from 34 seconds again.

    I hope iam able to describe you what I wanted.

    Thanks

  7. #17
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,346
    Thumbs Up
    Received: 83
    Given: 23
    Total Downloaded
    3.86 GB

    0 Not allowed!

    Default Re: Simple timer

    Ok now I think understand.

    I will try something else later.
    Regards

    Joseph

  8. #18
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,346
    Thumbs Up
    Received: 83
    Given: 23
    Total Downloaded
    3.86 GB

    0 Not allowed!

    Default Re: Simple timer

    Ok. I think I came up with something you desire.

    I think I also found an anomaly within the compiler which I will be posting in another thread if my findings are correct, at least with 18F devices.

    So for now, take note of the DIM. I used DWord instead of Word. IMPORTANT! Otherwise it could not work.

    It was not an easy task because now I am used to interrupts to make such things.

    Hope that the following suites you.

    Code:
    Dim Set_Onn As Dword = 34000 ' Set ON pulse time
    Dim Onn     As Dword = 34000 ' Set ON pulse time to compare with Set_Onn
    Dim Run     As Bit = 0      ' Flag used to indicate if pulse is ON
    
    Cls                     ' Clear LCD
    
    Set_Onn = Set_Onn / 1000                ' Convert Set_Onn to decimals
    
    Print At 1,1, "IN = " , Dec Set_Onn , "  "    
    Print At 2,1, "Timer stopped"
    
    Set_Onn = Set_Onn * 1000                ' convert Set_Onn to thousands
    
    '________________________________________________________________________________________
    '****************
    '* Main routine *
    '****************
    '>>>Main routine<<<
    
    Main:
    
        ' Note: - To make some tests I used the following code: -
        ' PORTC.0 = Start / Stop 
        ' PORTC.1 = Increase counter if PORTC.0 = 0
        ' PORTA.0 = Pulse output 
    
    '----------------------------------------------------------------------------------------
    ' Start pulse if PORTC.0 is high and timer is greater 0
    
    If PORTC.0 = 1 And Onn > 0 Then ' If PORTC.1 = 1 or timer reached 0 then 
            PORTA.0 = 1             ' turn ON output
            'Run = 1                 ' flag that output pulse is high
            Dec Onn                 ' decrease Onn
            DelayMS 1               ' delayms 1
            
            If Run = 0 Then 
            Cls
            Print At 1,1, "Standby......"
            Print At 2,1, "Timer started"
            Run = 1
        EndIf                       ' End If...Then instruction
        GoTo Main                       ' goto Main routine
    Else 
        PORTA.0 = 0
         If Run = 1 Then 
            Cls
            Print At 2,1, "Timer stopped"
            Run = 0
        EndIf                       ' End If...Then instruction
    EndIf                           ' End If...Then instruction
    
    '----------------------------------------------------------------------------------------
    
    If PORTC.0 = 0 Then
        Onn = Set_Onn               ' reload Onn with value of Set_Onn    
    EndIf                           ' End If...Then instruction
    
    '----------------------------------------------------------------------------------------
    ' Set timing
    
    Set_Onn = Set_Onn / 1000                ' Convert Set_Onn to decimals
    
    Print At 1,1, "IN = " , Dec Set_Onn , "  "    
    
    If PORTC.1 = 1 Then                     ' If PORTC.1 = 1 then 
        Inc Set_Onn                         ' increase Set_Onn
        If Set_Onn = 61 Then Set_Onn = 0    ' if Set_Onn is greater 60 then clear Set_Onn
        DelayMS 150                         ' some debounce delay
    EndIf                                   ' End If...Then instruction
    
    Set_Onn = Set_Onn * 1000                ' convert Set_Onn to thousands
    
    GoTo Main                               ' Goto Main routine
    
    '=======================================================================================
    Regards

    Joseph

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

    0 Not allowed!

    Default Re: Simple timer

    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

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

    0 Not allowed!

    Default Re: Simple timer

    I knew about the 1 second delay but for this simple timer I don’t think that is a problem.

    Joseph’s second code works for me but it does not show the time remaining. I just changed the PORT pins to match my hardware.

    I read the description again and I think Amod wants the relay to be off until the timer reaches zero then the relay comes on and stays on until the input on D.7 goes low.

    Amod try this


    Code:
    Dim Timer_Count As Byte
    Dim Set_Time As Byte
    Set_Time = 10
       
    main:
        Print At 1,1,"Set Time ",Dec2 Set_Time
     
        If PORTD.7 = 1 And Timer_Count > 0 Then  ' 
            PORTB.1 = 0                         ' relay is off
           
            DelayMS 1000
            Dec Timer_Count
        Else
            PORTB.1 = 0                        ' relay is off
            DelayMS 500
            If PORTD.6 = 1 Inc Set_Time     ' increment time
            If Set_Time > 60 Then Set_Time = 0
    '        If PORTD.5 = 1 And Set_Time > 0 Then Dec Set_Time  ' decrement value
            Timer_Count = Set_Time
        EndIf
       
        Print At 2,1,"Time left ",Dec2 Timer_Count      ' show a leading zero if less than 10
            
        If PORTD.7 = 1 And Timer_Count = 0 Then  ' turn the relay on until B.7 = 0
            PORTB.1 = 1
            While PORTD.7 = 1 : Wend
            DelayMS 1
        EndIf
    GoTo main
    Last edited by See_Mos; 14th October 2018 at 16:19.
    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, 20:08
  3. Timer example
    By smclark in forum The Lounge
    Replies: 8
    Last Post: 6th September 2007, 17:04
  4. [SOLVED !] 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