Autor Tema: mikroBasic Timer0 y timer1  (Leído 4831 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Skualo

  • PIC10
  • *
  • Mensajes: 42
mikroBasic Timer0 y timer1
« en: 19 de Agosto de 2008, 18:40:49 »
Wenas

Queria unir en un mismo pic el uso de los dos timers, primero hice el programa para timer0 y todo funciono bien se trata de un control para un servo, todo bien y luego utilize el timer1 para hacer el refresco de un 7segmentos triple y todo perfecto.
Luego decidi juntarlos en uno y lo simule en proteus, para mi sorpresa todo iba mas o menos bien pero la señal que generaba en el timer0 era el doble del tiempo y encima cada cierto tiempo dejaba un espacio sin pulsos y volvia a empezar que habia calculado? el timer1 afecta al timer0? supongo que no y tambien imagino que con 4Mhz un 18f4525 va sobrado para hacer todo eso?

En conclusion quiero saber 1.Tienen alguna relacion entre ellos? y 2.Va sobrado para usar los dos timers con 4Mhz?

Desconectado Skualo

  • PIC10
  • *
  • Mensajes: 42
Re: mikroBasic Timer0 y timer1
« Respuesta #1 en: 20 de Agosto de 2008, 13:26:09 »
Probando y probando vi que nose si sera el compilador pero e descubierto que el problema viene de que la interrupcion solo salta con el timer0 es decir el timer1 por ejemplo desborda en 1ms y el timer0 en 20 ms pues el timer1 en vez de hacerlo en 1 ms lo hace en 20 ms.
Y luego si desactivo el timer0 el timer1 desborda cuando toca, tambien probe hacer que el timer1 desbodara mas tarde que el timer0 y funciono es decir si el timer1 desborda en 35 ms y el timer0 en 20 ms todo va bien.

Alguien sabe algo?

dejo archivo para simular

Código: Text
  1. program central2
  2.  
  3. dim shifter, portd_index,servo1,servo2 as byte
  4.     digit, number as word
  5.     portd_array as byte[4]
  6.  
  7. sub function mask(dim num as Word) as Word
  8.   select case num
  9.      case 0
  10.        result= $88
  11.      case 1
  12.        result= $DB
  13.      case 2
  14.        result= $94
  15.      case 3
  16.      result= $91
  17.      case 4
  18.        result= $C3
  19.      case 5
  20.        result= $A1
  21.      case 6
  22.        result= $A0
  23.      case 7
  24.        result= $9B
  25.      case 8
  26.        result= $80
  27.      case 9
  28.        result= $81
  29.   end select
  30. end sub
  31. sub procedure interrupt
  32.  
  33.  
  34. if PIR1.TMR1IF = 1 then
  35.  
  36.   PIR1.TMR1IF = 0            ' clear TMR1IF
  37.   TMR1H = 200
  38.   TMR1L = 200
  39.  
  40.     PORTE = 0                             ' turn off all 7seg displays
  41.   PORTD = portd_array[portd_index]      ' bring appropriate value to PORTD
  42.   PORTE = shifter                       ' turn on appropriate 7seg. display
  43.  
  44.   ' move shifter to next digit
  45.   shifter= shifter << 1
  46.   if (shifter > 8) then
  47.     shifter = 1
  48.   end if
  49.   ' increment portd_index
  50.   Inc(portd_index)
  51.   if (portd_index > 3) then
  52.     portd_index = 0                     ' turn on 1st, turn off 2nd 7seg.
  53.   end if                     ' reset TIMER0 value
  54. end if
  55. if INTCON.INT0IF = 0 then
  56.  
  57.   TMR0L  = 178
  58.   INTCON = $20           ' set T0IE, clear T0IF
  59.  
  60.     PORTB = not PORTB
  61.   end if
  62. end sub
  63.  
  64. main:
  65. INTCON = $E0
  66.   T0CON  = 0xC7          ' set TMR0 in 8bit mode, assign prescaler to TMR0
  67.   TRISB = 200              ' PORTB is output
  68.   TRISD = 200
  69.   PORTB = $FF            ' initialize PORTB
  70.   TMR0L = 178             ' timer0 initial value
  71.             ' timer0 initial value
  72.             ' enable TMRO interrupt
  73.                   ' initialize cnt
  74.   servo1 = 182
  75.   servo2 = 182            ' Enable TMRO interrupt
  76.   T1CON  = %00000001                  ' timer1 settings
  77.   PIR1.TMR1IF = 0             ' clear TMR1IF
  78.   TMR1H  = 0               ' initialize Timer1 register
  79.   TMR1L  = 0
  80.   PIE1.TMR1IE  = 1            ' enable Timer1 interrupt
  81.                 ' set GIE, PEIE
  82.   TRISA=0
  83.   digit       =    0
  84.   portd_index =    0
  85.   shifter     =    1
  86.   PORTE       =    0
  87.   TRISE       =    0                    ' set PORTA as output
  88.   TRISB       =    %00000000
  89.   TRISD       =    0
  90.   PORTD       =    0
  91.                     ' set PORTD as output
  92.   number      = 0                    ' some initial value
  93.  
  94.   while TRUE
  95.  
  96.     digit = number / 1000               ' extract thousands digit
  97.     portd_array[3] = mask(digit)
  98.          ' and store it to PORTD array
  99.  
  100.     digit = (number / 100) mod 10       ' extract hundreds digit
  101.     portd_array[2] = mask(digit)
  102.           ' and store it to PORTD array
  103.  
  104.     digit = (number / 10) mod 10        ' extract tens digit
  105.     portd_array[1] = mask(digit)
  106.          ' and store it to PORTD array
  107.     digit = number mod 10               ' extract ones digit
  108.     portd_array[0] = mask(digit)        ' and store it to PORTD array
  109.  
  110.                         ' one second delay
  111.  
  112.     number = PORTC                         ' increment number
  113.     if (number > 999) then
  114.       number = 0
  115.     end if
  116.  
  117.        if TMR0L <= servo1 then
  118.    PORTD.5 = 1
  119.    else
  120.    PORTD.5 = 0
  121.    end if
  122.    if TMR0L <= servo2 then
  123.    PORTD.6 = 1
  124.    else
  125.    PORTD.6 = 0
  126.    end if
  127.   wend                                                  ' endless loop
  128.  
  129. end.
« Última modificación: 20 de Agosto de 2008, 13:45:12 por Skualo »

Desconectado Skualo

  • PIC10
  • *
  • Mensajes: 42
Re: mikroBasic Timer0 y timer1
« Respuesta #2 en: 21 de Agosto de 2008, 15:47:29 »
Problema solucionado  :-/
Se encuentra en la linia 55 "if INTCON.INT0IF = 0 then" en mikrobasic solo se puede tener una subrutina de interrupcion, entonces tienes que ir poniendo if a cada una de las interrupciones, pero yo como iba rapido haciendolo pues no me fije bien y puse INT0IF que varia a 1 cuando se produce la interrupcion Rb0 que nada tiene que ver con TMR0IF que varia a 0 y al cambiar eso todo funciono bien.De echo para probar puse timer0,timer1,timer2 y interrupcion por rb0 y todo genial

Saludos intentare no precipitarme en los posts  :mrgreen:



 

anything