This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Reading timer2 capture function

I am trying to read the timer2 capture function and then output it to the lcd screen. please advise if this code is enough to make this function operate or I should use a unit32 for val !

T2CTRL |= 0x0D;

 {
    
    
    T2MSEL |= 0x11; // T2MSEL.T2MOVFSEL = 00010001
   
     union counter2
     {
        char byte[3];
        unsigned int val;
    };
    union counter2 t2cnt;
        t2cnt.byte[0] = T2MOVF2;
        t2cnt.byte[1] = T2MOVF1;
        t2cnt.byte[2] = T2MOVF0;
       
   HalLcdWriteStringValue ("C:", t2cnt.val, 10, 1); 
   
  }

  • Hello Ali,

    The question above is asking if the val should be defined as uint32 but I am not sure what value you want to store in val. If you want to store the T2MOV0/1/2 values combined in one variable then it needs to be uint32. 

    Also, the function HalLcdWriteStringValue has the following prototype so please be careful in using this function and check the values that you pass as arguments.

    void HalLcdWriteStringValue( char *title, uint16 value, uint8 format, uint8 line )

    Regards

  • To output t2cnt.val to LCD, you can use sprintf to format the string to a char* buffer and use HalLcdWrite with buffer.