hi i require a fast way to check several sensors and obtain the highest value from them all, using the ncd command if it were available would be ideal for this. So i am thinking of rotating the bits of each value and checking if the bit is set then comparing the results. For speed i was going to code it in assembly.
Do you think this method would be the best way forward, or would xoring the values etc be more expedient.
many thanks
hi i require a fast way to check several sensors and obtain the highest value from them all, using the ncd command if it were available would be ideal for this. So i am thinking of rotating the bits of each value and checking if the bit is set then comparing the results. For speed i was going to code it in assembly.
Do you think this method would be the best way forward, or would xoring the values etc be more expedient.
many thanks
You don't specify how you obtain sensor data, so I am only able to generalize, but doing it in Basic, I don't think you will notice much difference in speed vs. ASM with this compiler. But the simulator will tell you how many clock cycles it takes for "data polling", so you can compare methods.
Dim i as byte
Dim highval as long
Const maxsensors = 4
Exec:
For i = 0 to maxsensors
gosub pollsensor
Next i
'do other stuff here
goto exec
end
pollsensor:
'maybe use i to point to sensor port
If iportdata > highval then highval = iportdata
'highval will now contain the highest data value read from a sensor
thanks for the reply, the data is sampled via numerous adc`s then each averaged, i was going along the ncd route as it also gave me the highest value of a magnitude of 2 or more over the next highest reading which would then be acted upon, if less than 2 no action needs to be taken.
many thanks
Hi Mike, ncd returns the highest bit of a byte, ncd %01111110 would return 7. Useful if you have say 2 light sensors and only want to move position if one result is higher than the other i.e each bit is double the magnitude of the previous bit.
Hi, the number returned relates to the bit number but plus 1 to cater for a no bit set which returns zero. Most basic compilers have the function, easily enabling large differences to be detected, and acted upon say via a select case. I managed to achieve the same by decreasing the w reg by 1,rlf the file reg and waiting for the status.c flag then exiting.
Cheers
Hi Mike, ncd returns the highest bit of a byte, ncd %01111110 would return 7. Useful if you have say 2 light sensors and only want to move position if one result is higher than the other i.e each bit is double the magnitude of the previous bit.
has to be that way to cater for no bit being set, 8 to 1 leaves zero if the byte = 0, if it was 7 to 0 then if ncd returned 0 you would not know if the byte was 0 or bit 0 was set