Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 25, 2024, 03:39:43 15:39


Login with username, password and session length


Pages: [1]
Print
Author Topic: very simple question ( I suppose) Mikrobasic and timer  (Read 8409 times)
0 Members and 1 Guest are viewing this topic.
orpheedulogis
Junior Member
**
Offline Offline

Posts: 72

Thank You
-Given: 10
-Receive: 2


« on: December 30, 2009, 11:29:49 23:29 »

So this is my second question.
Actually I use delay(x) to send an (electrical) command like relay.
The problem is that ... I have to wait  Grin

I would like to use a timer to do so but I don't understand how to prepare timer.
My PIC is a PIC18F4450 with a 16Mhz clock.
I would like to do something like that:

1) send a on command to pin and set a timer to 2 or 3 seconds
2) when timer arrive to zero, some pins reseted to zero.

I just need to understand how I can use timer.

Thanks

Logged
pickit2
Moderator
Hero Member
*****
Online Online

Posts: 4668

Thank You
-Given: 834
-Receive: 4322


There is no evidence that I muted SoNsIvRi


« Reply #1 on: December 31, 2009, 12:00:18 00:00 »

This is in proton
Code:
  Device = 18F4450
  Xtal = 16
   
  Symbol Relay = PORTB.1    ' Alias PORTB.1 to Relay
  DelayMS 500 ' Wait for PICmicro to stabilise
  TRISB = %00000000           ' Set PORTB to all output

 Start:
  Relay = 1           ' Relay on
  DelayMS 2000            ' Delay for 2 seconds
                                           'Reset some pins to zero
  DelayMS 3000           ' Delay for 3 seconds
     GoTo Start    ' Go back to Start
       
Logged

Note: I stoped Muteing bad members OK I now put thier account in sleep mode
orpheedulogis
Junior Member
**
Offline Offline

Posts: 72

Thank You
-Given: 10
-Receive: 2


« Reply #2 on: December 31, 2009, 01:02:17 01:02 »

Ok

Thanks for your answer but my english must be very poor  Wink

Actually I use delay function (in Mikrobasic delay_ms(2000) if I want to wait two seconds)
But this wait and I would like to continue so I can do other things.
My sofware is like this:

...
While true
    ...
    PortA.1=1          ' set relay on
    Delay_ms(1000)  ' wait for mechanic position
    PortA.1=0          ' set relay off
    ...

Wend

But I woulf like to have something like this

interrupt:
...
if TimerInterruptFlag then
   PortA.1=0
end if

...


While true
   
    ...
    PortA.1=1          ' set relay on
    DoSomethingElseWithoutWaiting
    ...
wend
Logged
orpheedulogis
Junior Member
**
Offline Offline

Posts: 72

Thank You
-Given: 10
-Receive: 2


« Reply #3 on: December 31, 2009, 04:49:36 16:49 »

Founded ! What I was waiting for:

Declarations
Symbol
TMR0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable
Symbol TMR0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag
Symbol TMR1IE = PIE1.0   ' TMR1 Overflow Interrupt Enable
Symbol TMR1IF = PIR1.0   ' TMR1 Overflow Interrupt Flag
Symbol TMR2IE = PIE1.1   ' TMR2 to PR2 Match Interrupt Enable
Symbol TMR2IF = PIR1.1   ' TMR2 to PR2 Match Interrupt Flag


'--------------------------------------------------------------------


sub procedure interrupt


dim CarTab as string[1]
RCIE_bit = 0 'interdiction interruption UART

Donnee=""
CarTab=chr(10)
if (UART1_Data_Ready() = 1) then        ' si Donnee prĂȘte
     UART1_Read_Text(Donnee,CarTab, 255)  ' attend la chaine terminant par "OK"
end if

If TMR2IF then ' on met à zéro les fonctions
  TMR2=0
  PR2=190'5
  tck=tck+1
  If tck=200 Then 'dĂ©lai avant remise Ă  zĂ©ro des relais
    tck=0
    if SortieTest1=0 then SortieTest1=1 else SortieTest1=0 end if 'sortie clignote
    AlimBobine=0
    SensBobine=0
  End If
  TMR2IF=0
end if
end sub


'--------------------------------------------------------------------
How to use it



sub procedure PassagePhare
        SensBobine=0
        delay_ms(100) ' pour activer le relai de position avant courant bobine
        TMR2=0 ' on remet Ă  zĂ©ro le timer de reset
        AlimBobine=1
        NiveauFeu=2
        Bips(2)
end sub

'--------------------------------------------------------------------
In "main"


'configuration de l'interrupt du timer2
T2CON = %01111111 ' Set T2CON.2
TMR2IF=0
TMR2IE=0
TMR2=0
PR2=190'5
INTCON=$C0        ' set GIE and PEIE bits %110000000


..................


if PhareIn then
   AlimBallast=1
   PassagePhare
   DonneeCodee[5]=11 ' passage phare
end if
« Last Edit: December 31, 2009, 05:00:18 17:00 by orpheedulogis » Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC