Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

most efficient way to perform ncd

Status
Not open for further replies.

sheepdog

New Member
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

Hi Sheepdog,

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

return
 
Last edited:
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.
 
I don't quite understand.
You want to sort the adc values from highest to lowest?

Or you want to know which ADC values have the highest order bit set, this won't tell u very much as many can have bit7 set from value 128 thru 255.

The bit 7 u mention above is a 0, when counting bits 7,6,5,4,3,2,1,0. It's not set so I am confused as to what you want.
 
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
 
Last edited:
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.

Do they really count 1 to 8 rather than 0 to 7?

Mike.
 
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
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top