captura de tiempos en flancos ascendente y descendente

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

captura de tiempos en flancos ascendente y descendente

1,596 Views
magg
Contributor I

estoy tratando de capturar loss tiempos del tpm1 por input capture del mc9se8e8 de flancos ascendente y descendente y las medidas me dan erroneamente ... capturo los pulsos de un control sony y los datos del tpm1cov no concuerdan con los establecidos,,,
utilizo reloj interno 4mhz y los datosleidos del tpm1cov los envio via serial el pc
solamante estoy leyendo el flanco de subida que es el que contiene el valor tpm1cov
al leer el flanco de subida este tpm1cov contiene valor del tiempo entre el flanco de bajada y el de subida,,
lo que se debe visualizar en el hiperterminan deben ser 2400...1200...600 que son los tiempos de los pulsos que demora el start..en 1 y un cero aproximadamente--

 

estoy trabajando con reloj interno de 4MHZ

GRACIAS

 

 

 

MC9SE8SE8

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <stdio.h>


void interrupt VectorNumber_Vtpm1ch0 ISR_TPM1C0SC_CH0F( void) {

vvv=TPM1C0SC ;
TPM1C0SC_CH0F = 0;
if(PTAD_PTAD6==0){; //flanco de BAJADA


TPM1CNTH=0;
TPM1CNTL=0 ;
T1=0 ;

} else
T2=TPM1C0V ;

}



void main(void) {

/* CONFIGURACION DEL SOPT1
SOPT1_COPT = 00 disable perro guardian copt es desabilitado;
SOPT1_STOPE =0 stop modo desabilitado //( SOPT1 & 0x3F );
SOPT1_TPM1PS=1 Configuración de pin entrada de input capture pta6 canal 0 */
SOPT1= 0B00000100 ;

/*CONFIGURACION DEL TPM1SC
TPM1SC_TOIE =0 No habilitamos interrupciones por overflow
TPM1SC_CPWMS=0 Todo canal input capture
TPM1SC_PS =2 ;PS=2 División 1/4
TPM1SC_CLKSB =0 Frecuencia para modulo bus 4 mhz ;rate clock
TPM1SC_CLKSA =1 Frecuencia para modulo bus 4 mhz ;rate clock */
TPM1SC=0B00001010 ;


/*CONFIGURACION DEL TPM1C0SC
TPM1C0SC_CH0IE=1 Habilitada interrupción por input capture por canal 0
TPM1C0SC_MS0A= 0 Input capture
TPM1C0SC_MS0B= 0 Input capture
TPM1C0SC_ELS0B=1 Captura flanco de subida y bajada
TPM1C0SC_ELS0A=1 Captura flanco de subida y bajada */
TPM1C0SC=0B01001100 ;

serial transmicion
SCIBDH =0X00 ; /* Hardware interrupts from LBKDIF disabled,
Hardware interrupts from RXEDGIF disabled */
SCIBDL =0X1F ; /* When BR = 1 to 8191, the SCI baud rate = BUSCLK/(16×BR).
See also BR bits in */
SCIC1 =0X00 ; /*RxD and TxD use separate pins,USO NORMAL.
Provided LOOPS = 1, Rsrc=0 selects internal loop;
Normal- start + 8 data bits (LSB first) + stop.
No hardware parity generation or checking.Even parity.*/
SCIC2 =0X0C ;/*Hardware interrupts TDRE,TC,RDRF,IDLE disableds.


for(; {


asm wait;//modo de bajo consumo

DIEZMIL= T2/10000+48;
AUX= T2%10000;
MIL= AUX/1000+48;
AUX2= AUX%1000;
CENTENAS= AUX2/100+48 ;
AUX3=AUX2%100;

DECENAS = AUX3/10+48;
UNIDADES = AUX3%10+48;

SCID=DIEZMIL;
while(!(SCIS1 &0X80));
SCID=MIL;
while(!(SCIS1 &0X80));
SCID=CENTENAS;
while(!(SCIS1 &0X80));
SCID=DECENAS;
while(!(SCIS1& 0X80));
SCID=UNIDADES ;
while(!(SCIS1& 0X80));


SCID= 10;
while(!(SCIS1& 0X80));
SCID= 13;
while(!(SCIS1& 0X80));
}
}

Labels (1)
0 Kudos
9 Replies

939 Views
bigmac
Specialist III

Hola! Bienvenido al foro.

 

Your code snippet appears to attempt to read the period of an external signal that is pulsing low for a period of 600us to 2400us.  However, you are then attempting to output the result to the SCI module, as a sequence of seven ASCII characters per reading.  You seem to have a "non-standard" baud rate of 8065 bits/s, and the transmission time will be just under 9ms, to which must be added the ASCII conversion time, probabably a few more milliseconds.

 

Your existing code makes no attempt to inhibit further period measurement until the output of the previous measurement has been completed.  For the following code, it is possible that the value of variable T2 is altered within the ISR code, between the first and second usage of the variable.

 

DIEZMIL = T2 / 10000 + 48;
AUX= T2 % 10000;

I am not sure that it is valid to test the state of GPIO pin PTAD_PTAD6 whilst TPM input capture mode is selected.  The TPM module will normally take precedence when input capture is enabled - I am not sure whether the GPIO input remains connected.

 

To determine the polarity of the edge that caused the current interrupt, I would suggest a different approach.  Rather than input capture on both edges, alternatively set for input capture on only one edge at a time.  The current edge polarity can then be determined by the current TPM1C0SC value.

 

Writing to TPM1CNT to clear this register will reduce the timing accuracy because of the latency between the capture edge and the ISR processing.  This is unnecessary for input capture operation - the TPM counter should remain continuously free-running.  The period is determined by a simple subtraction of two 16-bit values.

 

The following untested code demonstrates how the input capture operation might be synchronised with the SCI output of each result.  There will obviously be numerous pulses that are ignored during each data output.

 

#include <hidef.h>       /* for EnableInterrupts macro */#include "derivative.h"  /* include peripheral declarations */#include <stdio.h>// Global variables:volatile word t;volatile byte flag;/*********************************************************************/void main(void){  word t1;    SOPT1 = 0x04;  // Setup SCI module:  SCIBD = 0x001F;    // Baud rate 8065 bit/s for 4 MHz bus frequency  SCIC1 = 0x00;  SCIC2 = 0x0C;      // No interrupts  // Setup TPM1 module:  TPM1MOD = 0x00;    // Ensure free-running mode  TPM1C0SC = 0x48;   // Next capture interrupt on falling \_ edge  TPM1C0SC_CH0F = 0; // Ensure flag is clear  TPM1SC = 0x0A;     // Enable TPM - bus clock, prescale 4  flag = 0;  __asm cli;         // Enable interrupts    for ( ; ; ) {        __asm wait;        if (flag) {      // Test for result complete      flag = 0;            // Send result to SCI      t1 = t;      send_char( t1 / 10000 + '0');      t1 %= 10000;      send_char( t1 / 1000 + '0');      t1 %= 1000;      send_char( t1 / 100 + '0');      t1 %= 100;      send_char( t1 / 10 + '0');      send_char( t1 % 10 + '0');      send_char( \r);      send_char( \n);      TPM1C0SC_CH0F = 0; // Clear TPM channel flag      TPM1C0SC = 0x48;   // Next capture on falling \_ edge    }  }}/*********************************************************************/// Send character to SCIvoid send_char( val){  while (!(SCIS1 & 0x80));  // Wait until ready to send  SCID = val;}/*********************************************************************/void interrupt VectorNumber_Vtpm1ch0 ISR_TPM1C0SC_CH0F( void){  TPM1C0SC_CH0F = 0;     // Clear flag  if (TPM1C0SC_ELS0A) {  // This interrupt for rising _/ edge    t = TPM1C0V - t;     // Pulse period    flag = 1;            // Flag period completed    TPM1C0SC = 0x00;     // Disable further interrupts  }  else {                 // This interrupt caused by falling edge    t = TPM1C0V;         // Start of pulse    TPM1C0SC = 0x44;     // Capture on next rising _/ edge  }}

 

Regards,

Mac

 

0 Kudos

939 Views
magg
Contributor I

SR gracias por las aclaraciones probare el programa y les contare lo sucedido..

 

 

 

0 Kudos

939 Views
magg
Contributor I

 bigmac

el programa presenta varios errores

gracias

 

void send_char( val)
{
  while (!(SCIS1 & 0x80));  // Wait until ready to send
  SCID = val;
  t1 = t;
      send_char( t1 / 10000 + '0');
      t1 %= 10000;
      send_char( t1 / 1000 + '0');
      t1 %= 1000;
      send_char( t1 / 100 + '0');
      t1 %= 100;
      send_char( t1 / 10 + '0');
      send_char( t1 % 10 + '0');
      send_char( \r);
      send_char( \n);




0 Kudos

939 Views
bigmac
Specialist III

Hello,

 

I found some silly minor errors.  The code should compile when these are fixed.  I had also not shown a prototype for the send_char() function.  This should be added prior to the first use of the function.

 

      send_char( '\r');
      send_char( '\n');

 

 

// Send character to SCI
void send_char( byte val)
{
  while (!(SCIS1 & 0x80));  // Wait until ready to send
  SCID = val;
}


 

Regards,

Mac

0 Kudos

939 Views
magg
Contributor I

hola bigmac ha sido muy amable de tu parte en atender las inquietudes 

la verdad es estado ensayando el programa y los errores en esta parte persisten en esta parte.. adjunto imagen del eerror

 

// Send character to SCI
void sendchar(byte val)
 {
  while (!(SCIS1 & 0x80))  // Wait until ready to send
  SCID = val;
}

 

 

en esta parte no se presentan errores pero tengo dudas en esta parte si de pronto influyen sobre los errores..

 

 t1 = t;
    send_char ( t1 / 10000 + '0');
      t1 %= 10000;
      send_char ( t1 / 1000 + '0');
      t1 %= 1000;
       send_char( t1 / 100 + '0');
      t1 %= 100;
       send_char( t1 / 10 + '0');
      send_char( t1 % 10 + '0');
       send_char( '\r');
     send_char( '\n');

 

 

El problema del desface en el  contador tpm1 se podra solicionar con la configuracion del reloj externo?

y como se podria configurar este reloj..

 

saludos y gracias por la colaboracion en las dudas

0 Kudos

939 Views
bigmac
Specialist III

Hola,

 

The corrected code compiled for me, without any error or warning.  Did you add a prototype for the send_char() function?

 

void sendchar( byte val);

 

The binary-to-ASCII decimal conversion process also seemed to work as expected, certainly with the t1 test value that I used (0x8010 = 32786 decimal), under simulation.

 

I am not sure that I understand the nature of the timing problem that you refer - maybe due to Google translation.

 

Regards,

Mac

 

0 Kudos

939 Views
magg
Contributor I

HOLA BMAC

me di por vencido con el programa propuesto puesto que no pude corregir el error

#include <hidef.h>       /* for EnableInterrupts macro */
#include "derivative.h"  /* include peripheral declarations */
#include <stdio.h>

void send_char(byte var) ;

volatile byte flag;

//este se debe decretar al principio

void main(void)

{

}

send_char( 5000/55l);

//si no se decreta la funcion void send_char(byte var) el programa presenta error

void send_char(byte var)
{
 SCID =var; //t9;
  while (!(SCIS1 & 0x80)) ; // Wait until ready to send
     
}


POR OTRO LADO creo que  el error  de los tiempos es por impresicion del TPM1 por el reloj interno..

en esta parte yo registro 8 tiempos de los flancos ascendentes y despues visualizo por hiperterminal los 8 tiempos t1,t2,t3...t8 para no afectar los tiempos del PMP1 Y AUN ASI SIGUE EL ERROR .  
presscaler 4000000/4=1000000HZ

PERIODO=1/1000000=1uS

TIEMPO MAXIMO DEL CONTADOR PARA EL DESBORDE ES 1us*65535=65,535mS

para 2,4mS TPM1COV=2400
para 1,2mS TPM1COV=1200
para o,6mS TPM1COV=600

 
    

void interrupt VectorNumber_Vtpm1ch0 ISR_TPM1C0SC_CH0F( void)
{
byte  ch_tpm1;
     ch_tpm1= TPM1C0SC ;
  TPM1C0SC_CH0F = 0;     // Clear flag
  if (TPM1C0SC_ELS0A) {  // This interrupt for rising _/ edge
    t = TPM1C0V - t;    // Pulse period
    flag = 1;
      n_entradas++;           // Flag period completed
    TPM1C0SC = 0x00;     // Disable further interrupts
 
 
  }
  else {  
    byte  ch_tpm1;
     ch_tpm1= TPM1C0SC ;            // This interrupt caused by falling edge
    t= TPM1C0V;         // Start of pulse
    TPM1C0SC = 0x44;     // Capture on next rising _/ edge
  }


 for ( ; ; ) {
    
    __asm wait;
    
    if (flag) {      // Test for result complete
      flag = 0;
   
      if(n_entradas==1){
      t1=t ;
        }
       if(n_entradas==2){
      t2=t  ;
        }
         if(n_entradas==3){
      t3=t   ;
        }
            if(n_entradas==4){
      t4=t    ;
        }
              if(n_entradas==5){
      t5=t     ;
        }
                if(n_entradas==6){
      t6=t      ;
        }  
                  if(n_entradas==7){
      t7=t       ;
        }
                    if(n_entradas==8){
      t8=t;
 }

 

 ESTA PARTE NO INTERFIERE EN LA TOMA DE TIEMPOS DEL TPM1 ESTA PARTE SE EJECUTA SI SE  HA CAPTURADO LOS 8 TIEMPOS DE LOS COMANDOS DEL CONTROL.

 t9='T';
    send_char();
      t9=49;
   send_char();
    t9=61;
   send_char( );
   
        
     t9=  t1 / 10000+48 ;
     send_char() ;
    t1 %=10000;
    t9=t1/1000+48 ;
    send_char() ;
     t1%=1000;
      t9=t1/100+48 ;
      send_char() ;
      t1%=100;
    t9=t1/10+48 ;
    send_char() ;
      t1%=10;
     t9=t1+48;
     send_char() ;
        t9=10;
    send_char( );
      t9=13;
   send_char( );
     
   
     t9='T';
    send_char( );
      t9=50;
   send_char( );
    t9=61;
   send_char( );
   
   
    
  t9=  t2 / 10000+48 ;
     send_char() ;
    t2 %=10000;
    t9=t2/1000+48 ;
    send_char() ;
     t2%=1000;
      t9=t2/100+48 ;
      send_char() ;
      t2%=100;
    t9=t2/10+48 ;
    send_char() ;
      t2%=10;
     t9=t2+48;
     send_char() ;
     
        t9=10;
    send_char( );
      t9=13;
       send_char( );
       
      
       t9='T';
    send_char( );
      t9=51;
   send_char( );
   t9=61;
   send_char( );
   
    
   t9=  t3 / 10000+48 ;
     send_char() ;
    t3 %=10000;
    t9=t3/1000+48 ;
    send_char() ;
     t3%=1000;
      t9=t1/100+48 ;
      send_char() ;
      t3%=100;
    t9=t3/10+48 ;
    send_char() ;
      t3%=10;
     t9=t3+48;
     send_char() ;
        t9=10;
    send_char( );
      t9=13;
   send_char( );  
   
   
      t9='T';
    send_char( );
      t9=52;
   send_char( );
   
    t9=61;
   send_char( );
   
 
   t9=  t4 / 10000+48 ;
     send_char() ;
    t4 %=10000;
    t9=t4/1000+48 ;
    send_char() ;
     t1%=1000;
      t9=t4/100+48 ;
      send_char() ;
      t4%=100;
    t9=t4/10+48 ;
    send_char() ;
      t4%=10;
     t9=t4+48;
     send_char() ;
        t9=10;
    send_char( );
      t9=13;
   send_char( );  
   
   
       t9='T';
    send_char( );
      t9=53;
       send_char( );
        t9=61;
   send_char( );
   
   
    
   t9=  t5 / 10000+48 ;
     send_char() ;
    t5 %=10000;
    t9=t5/1000+48 ;
    send_char() ;
     t5%=1000;
      t9=t5/100+48 ;
      send_char() ;
      t5%=100;
    t9=t5/10+48 ;
    send_char() ;
      t5%=10;
     t9=t5+48;
     send_char() ;
        t9=10;
    send_char( );
      t9=13;
   send_char( );  
   
   
   
        t9='T';
    send_char( );
      t9=54;
   send_char( );
    t9=61;
   send_char( );
   
   
   t9=  t6 / 10000+48 ;
     send_char() ;
    t6 %=10000;
    t9=t6/1000+48 ;
    send_char() ;
     t6%=1000;
      t9=t6/100+48 ;
      send_char() ;
      t6%=100;
    t9=t6/10+48 ;
    send_char() ;
      t6%=10;
     t9=t6+48;
     send_char() ;
        t9=10;
    send_char( );
      t9=13;
   send_char( );
   ...


..

 

...

 

...    
    n_entradas=0;
        
 void send_char(void)
{
        SCID =t9; //t9;
  while (!(SCIS1 & 0x80)) ; // Wait until ready to send
     
}


        
        }

 

 

LOS VALORES QUE REGISTRA EL SERIAL  PARA UN PRESCALER DE 4000000/4
T1=00907                
T2=00873
T3=00067
T4=00863
T5=03011
T6=00898
T7=00863
T8=00861
T1=031´9
T2=01039
T3=01016
T4=00993
T5=00982
T6=03042
T7=00984
T8=°0966
Ô1=00895
T2=00885
T3=°3012
T4=00897
T5=00892
T6=00859
T7=00882
T8=°³°±±Š


LOS VALORES QUE DEBE REGISTRAR EL SERIAL PARA EL CANAL 1

T1=02400                
T2=00600
T3=00600
T4=00600
T5=00600
T6=00600
T7=00600
T8=00600

LOS VALORES QUE DEBE REGISTRAR EL SERIAL PARA EL CANAL 2
T1=02400   
T2=01200
T3=00600
T4=00600
T5=00600
T6=00600
T7=00600
T8=00600

LOS VALORES QUE DEBE REGISTRAR EL SERIAL PARA EL CANAL 3
T1=02400   
T2=00600
T3=01200
T4=00600
T5=00600
T6=00600
T7=00600
T8=00600

seguimos con el error de los tiempos

 


0 Kudos

939 Views
bigmac
Specialist III

Hola,

 

It appears that you require to read a sequence of 8 pulse periods, and on completion to display all 8 values to the SCI.  Your code will not achieve this, primarily because 'flag' is set, within the ISR, after each period.  So afer the first period is obtained, you attempt to display all of the periods - random data will be displayed for most.

 

One solution is to store each pulse period within the ISR code, and set 'flag' only after all the 8 pulses are completed.  To achieve this, the period data should be stored within a single, global array variable, rather than eight separate variables.

 

I have not seen your initialisation code for the ICS module.  You have stated that you have a bus frequency of 4 MHz, but this will not be accurately achieved unless the internal reference within the ICS is trimmed with an appropriate value.  Otherwise the bus frequency error can be very large.  The non-volatile (NV) trim value needs to be determined and programmed during the programming process for the MCU.  Your code then requires to read this value, and transfer to the ICS trim register.

 

My suspicion that this may not have been done was alerted by your baud register setting for the SCI module.  In all probability, you would require 9600 bits per second, but your current baud register setting would be erroneous if the bus frequency were actually 4.00 MHz.  The bus frequency error would also give period measurement errors.

 

Your present code is very difficult to understand, and will be very inefficient, such as the following instances -

.

  1. The use of the global variable 't9' within the send_char() funcion, in lieu of using a function parameter.  I cannot see any reason for this.
    .
  2. Your reluctance to make use of ASCII character constants.  The use of '0' is more meaningful than either 48 or 0x30.
    .
  3. Your reluctance to make use of "backslash character constants" to represent ASCII control characters. '\r' is more meaningful than 13 or 0x0D.
    .
  4. The use of multiple variables, rather than a single array variable, for the various period data.
    .
  5. The "inlining" of your display code (within main() function) requires a large amount of code and is very repetitive.  This should be handled as separate functions.  One function would display a single result.  Another function could then call this function, to consecutively display all eight results from within a 'for' loop.
    .
  6. I notice that you have modified the send_char() function so that a wait for the completion of the current character transmission occurs before the function exits.  Previously, there was a wait until the previous character was completed, prior to sending the current character.  The second method is more efficient, as other operations outside of the function may occur during the character transmission period, thus reducing the wait period.
    .
  7. Your additional read of TPM1CH0SC register, prior to TPM1CH0SC_CH0F = 0; is unnecessary.  This is because the latter is actually a "read-modify-write" process.

Here is a code example that takes into account my various comments -

 

#define MAXDATA  8// Global variables:volatile byte flag;volatile word timedat[MAXDATA];// Function prototypes:void disp_data( void);void send_period( word n);void send_char( byte val);void MCU_init( void);/*************************************************?********************/void main(void){  MCU_init();            // Initialise MCU registers  EnableInterrupts;  for ( ; ; ) {          // Main loop        __asm wait;    __RESET_WATCHDOG();        if (flag) {          // Test for period data complete      disp_data();       // Display period data to SCI      flag = 0;      TPM1C0SC_CH0F = 0; // Clear TPM channel flag      TPM1C0SC = 0x48;   // Next capture on falling \_ edge    }  }}/*********************************************************************/// Display period data to SCIvoid disp_data( void){  byte i;    for (i = 0; i < MAXDATA; i++) {    send_char( 'T');    send_char( i + '0');    send_char( '=');    send_period( timedat[i]);  }}/*********************************************************************/// Send period result to SCIvoid send_period( word n){  send_char( n / 10000 + '0');  n %= 10000;  send_char( n / 1000 + '0');  n %= 1000;  send_char( n / 100 + '0');  n %= 100;  send_char( n / 10 + '0');  send_char( n % 10 + '0');  send_char( '\r');  send_char( '\n');}/*********************************************************************/// Send character to SCIvoid send_char( char val){  while (!(SCIS1 & 0x80));  // Wait until ready to send  SCID = val;}

 

// ISR functions:// TPM1 module, channel 0:__interrupt VectorNumber_Vtpm1ch0 void ISR_TPM1CH0( void){  static byte count = 0;  static word t;    TPM1C0SC_CH0F = 0;       // Clear flag    if (TPM1C0SC_ELS0A) {    // This interrupt for rising _/ edge    timedat[count++] = TPM1C0V - t; // Pulse period        if (count < MAXDATA) { // Data table is not full      TPM1C0SC = 0x48;     // Capture on next falling \_ edge    }    else {                 // Data table is full      count = 0;           // Ready for next set of data      flag = 1;            // Flag data complete      TPM1C0SC = 0x00;     // Disable further interrupts    }  }  else {                   // This interrupt for falling \_ edge    t = TPM1C0V;           // Start of pulse    TPM1C0SC = 0x44;       // Capture on next rising _/ edge  }}

 

I also used a separate function for the MCU initialisation.  This is more complete than the previous code, and is more extensively documented.  It contains the initialisation for the ICS module.  Initialisation to this extent, or more, is probably necessary for most projects.

 

// Initialise MCU registersvoid MCU_init( void){  // Initialise GPIO:  PTAPE = 0xFF;   // Enable pullups  PTADD = 0x00;   // All pins are inputs  PTBPE = 0xFF;   // Enable pullups  PTBDD = 0x00;   // All pins are inputs  PTCPE = 0xFF;   // Enable pullups  PTCDD = 0x00;   // All pins are inputs  //---------------------------------------------------  // Write-once registers:  SOPT1  = 0b10100110;  /*         |||  ||+-- RSPTE    No reset pin             |||  |+--- BKGDPE   BGGD/MS pin enabled             |||  +---- TPM1PS   TPM1 -> PTA6,PTA7             ||+------- STOPE    STOP instr. enabled             ++-------- COPT     COP period ~256 ms  */  SOPT2  = 0b00000000;  /*         |+-------- COPW     Normal COP operation             +--------- COPCLKS  1kHz clock source  */  SPMSC1 = 0b00011100;  /*         |||||| +-- BGBE     Band gap disabled             |||||+---- LVDE     LVD enabled             ||||+----- LVDSE    LVD enabled in STOP             |||+------ LVDRE    LVD reset             ||+------- LVWIE    No LVW interrupt             |+-------- LVWAK    Acknowledge LVW flag (W)             +--------- LVWF     LVW flag (R)  */  SPMSC2 = 0b00100000;  /*           |||| +-- PPDC     No partial power-down               |||+---- PPDACK   Acknowledge PPD flag (W)               ||+----- PPDF     PPD flag (R)               |+------ LVWV     LVW trip level 4.3V               +------- LVDV     LVD trip level 4.0V  */  //---------------------------------------------------  // ICS module:  // FEI mode - bus frequency 4-5 MHz, depending on trim  // Internal reference trimmed to 31.25kHz for 4 MHz bus    ICSC1  = 0b00000110;  /*         |||||||+-- IREFSTEN             ||||||+--- IRCLKEN   Clock O/P for RTC module             |||||+---- IREFS     Internal reference             ||+++----- RDIV      No ext. reference             ++-------- CLKS      FLL output  */  ICSC2  = 0b01000000;  /*         |||||||+-- EREFSTEN             ||||||+--- ERCLKEN             |||||+---- EREFS     Not external reference             ||||+----- LP             |||+------ HGO             ||+------- RANGE             ++-------- BDIV      FLL O/P divide by 2  */  ICSSC  = 0b00000000;  /*         |||||||+-- FTRIM     Fine trim bit             ||||||+--- OSCINIT   (R)             ||||++---- CLKST     (R)             |||+------ IREFST    (R)             ||+------- DMX32             ++-------- DRST      (R)             ++-------- DRS       Low range (W)  */  // Test whether NV trim value has been programmed  if (NVICSTRM == 0xFF) {        // Action here for unprogrammed NV trim value, e.g. flash LED          for ( ; ; );     // Wait for watchdog timeout reset  }  // Trim reference oscillator - NV values for 31.25kHz  ICSTRM = NVICSTRM;  ICSSC_FTRIM = NVFTRIM_FTRIM;      //---------------------------------------------------  // SCI module:  SCIBD = 26;        // Baud rate 9600bit/s with 4 MHz bus  SCIC1 = 0x00;  SCIC2 = 0x0C;      // No interrupts    //---------------------------------------------------  // TPM1 module:  TPM1MOD = 0x00;    // Ensure free-running mode  TPM1C0SC = 0x48;   // Next capture interrupt on falling \_ edge  TPM1C0SC_CH0F = 0; // Ensure flag is clear  TPM1SC = 0x0A;     // Enable TPM - bus clock source, prescale 4  flag = 0;          // Global variable}

 

I have also attached the full CW project (V6.3) for the above code, to see if you have any compiler problems.

 

Regards,

Mac

0 Kudos

939 Views
magg
Contributor I

hola bigmac

para que el programa funcione tengo que eliminar esta parte del programa

 /*
if (NVICSTRM == 0xFF) {
    
    // Action here for unprogrammed NV trim value, e.g. flash LED
      
for ( ; ; );     // Wait for watchdog timeout reset
}
  // Trim reference oscillator - NV values for 31.25kHz
ICSTRM = NVICSTRM;
ICSSC_FTRIM = NVFTRIM_FTRIM;

  */

 

ya con el programa funcionando

esta es la informacion que se observa por hiperterminal y sigue la toma erronea de los tiempos

0927
T0=00886
T1=00886
T2=00883
T3=01595
T4=00882
ŠT6=00880
T7=00880
T0=00874
T1=00871
T2=00870
T3=02961ŠÔ4=00882
T5=00882
T6=00881
T7=00880







T5=00980
T6=00975
T7=00970

T5=00875
T6=00875
T7=00875
T0=03139
T1=01713
T2=00991
T3=00987
T4=00983
T5=00980
T6=00977

2=01004
T3=00995
T4=00995
T5=00987
T6=00979
T7=00976
T0=00893
T1=00893
T2=01599
T3=00889
T4=00886
T5=00886
T6=008¸5
T7=03027
0973
T0=00890
T±=00889
T2=00887
T3=01598
T4=00884
T5=00883
T6=00882
T7=00882

T7=00959
T0=00883
T1=00881
T2=00879
T3=01588
T4=00878
T5=00875
T6=00872
T7=00873

T0=03103
T1=00932
T2=00927
T3=00927
T4=00¹22
T5=00915
T6=00907
T7=0°9°2
T0=00855
T1=00855
T2=00853
T3=01563
T4=00878
T5=00855
T6=00854
T7=00853

 

adjunto el montaje del circuito


0 Kudos