Counter1 Resetting when not asked | LabJack
 

Counter1 Resetting when not asked

3 posts / 0 new
Last post
JonNCL
JonNCL's picture
Counter1 Resetting when not asked

I've been programming in c and have come across a problem with the counter resetting when not requested (it must be somewhere but I am missing it). I've got Timer0 and Counter1 set (Timer0 has a frequency of 24kHz) and Counter1 is counting the rising edges of the timer. It's a basic loop for the moment that reads the counter but should not reset it and loops every second:

 

    sendBuff[1] = (uint8)(0xF8);  //Command byte
    sendBuff[2] = 1.5;  //Number of data words (.5 word for echo, 1 word for
                       //IOTypes)
    sendBuff[3] = (uint8)(0x00);  //Extended command number

    sendBuff[6] = 0;  //Echo

    sendBuff[7] = 55;  //IOType is Counter1
    sendBuff[8] = 0;  //Reset (bit 0) is not set
    
    extendedChecksum(sendBuff, SendNo);

When I write this, I get a count of roughly 24k (which is expected) but then every count after that is roughly the same figure instead of incrementing as n*24e3 (n=iteration). Am I missing something obvious?

(I can get around it by just using a cumulative sum but this is more out of interest)

 

Cheers in advance

LabJack Support
labjack support's picture
Are you getting an error in

Are you getting an error in your response?

The command is incorrect in regards to the size of the packet and byte 2 (number of data words). The Feedback packet size needs to be an even number, and the number of data words cannot have a half of a word. An extra byte needs to be added to the command. Your current command is rounding down the number of data words to 1, so that may be causing some unexpected functionality since that only accounts for bytes 6 and 7.

Try this command and see if it helps the resetting:

    SendNo = 10;
    unsigned char sendBuff[10];

    sendBuff[1] = (uint8)(0xF8);  //Command byte
    sendBuff[2] = 2.0;  //Number of data words (.5 word for echo, 1 word for
                        //IOTypes)
    sendBuff[3] = (uint8)(0x00);  //Extended command number
    sendBuff[6] = 0;  //Echo
    sendBuff[7] = 55;  //IOType is Counter1
    sendBuff[8] = 0;  //Reset (bit 0) is not set
    sendBuff[9] = 0;  //Padding byte

    extendedChecksum(sendBuff, SendNo);

The response to this command will be 14 bytes. Bytes 9-12 will have the 32-bit counter reading, and byte 13 is the padding byte.

JonNCL
JonNCL's picture
Brilliant, thank you! Works a

Brilliant, thank you! Works a treat.

I was assuming that since I had SendNo set to 10, the padding byte was taken care of (I wasn't getting an error and I assume it was something to do with the SendNo setting?). And I didn't recognize that the number of data words had to include the information from the padding! Silly mistake, but thank you so much for the clarity. As you said, it would have just been rounding and not running some of the information.