I tried also with the command count
Count PortB.0,1000,Value, and it gives the correct value