Voltage level detection

Hi,

I used the following example code from the Arc32 data sheet:

ENABLEHSERVO2
Volts Var Byte
Main
Volts = HSERVOSTATE P33
serout s_out, i19200, [REAL (TOFLOAT Volts/51.2)\2]
Goto Main

I also tried this for pins 32&34 as I am trying to monitor voltages on and S1/S2, as well as the logic voltage, however when I run this all I get for a result is 0.00 .

Has something changed that wasn’t updated in the manual??

Thanks

Yes, the Arc32 manual is wrong! I sort-of detected this awhile ago when I was figuring out my C implementation as well as other information that I have received from Nathan,

I believe the three voltages are logically connected as IO pins P56-P58 and are directly hooked up to analog pins 0-2. So try something like:

Volts1 Var word
Volts2 var word
Volts3 var word
sethserial1 H38400

Main
	;Volts = HSERVOSTATE P33
	adin 56, volts1
	adin 57, volts2
	adin 58, volts3
	;serout s_out, i19200, [REAL (TOFLOAT Volts/51.2)\2]
	hserout [dec (volts1*1000)/512, " ", dec volts2, " ", dec volts3, 13]
	pause 100
	Goto Main

Note: I displayed the values as 100s of a volt.
Kurt

P.S. - ENABLEHSERVO and ENABLEHSERVO2 I believe are not needed/used anymore in the latest version of studio.

Hey Kurte!!

I tried the code and I get 78 0 0

I am currently testing using a variable dc power supply set at 5vdc, just curious, where did you find reference to pins 56,57,&58?? Looking that the manual they show:
P32 - Detects S1 Voltage
P33 - Detects Logic Voltage
P34 - Detects S2 Voltage

Since I was one of the very first persons to try out a Beta version of the Arc32 board Nathan (and Dale) of Basic Micro sent me a text file that had the planned pin numbers for the board. So I had that to rely on. Then later when I was working on making my C library code work on the Arc32, I was trying to figure out what the pins really are. So I did code to dump the pin / port table… I then deduced what as what. More details on the thread: viewtopic.php?f=45&t=6677&p=66037&hilit=arc32+pin#p66037

By writing the a C version of Hservo2 for that Arc32, I gained a lot of knowledge on what pin goes where…:laughing:

Kurt

I am wondering if this is a bug in the latest release of studio, I still cannot get readings off of those pins, and I wasn’t able to find anything off of the bm forums.

Hi Charley,

Nathan, is probably better to answer this than I am. (He can see the real code). It appears like from his earlier TXT file with data that maybe HSERVOSTAT of 32-35 would mirror doing a simple AtoD on thos pins plus another pin…

Not sure if that works or not…

But back to task at hand. The AtoD gives you a value between 0-1023 so first issue you had with your program is that you only used a byte with can only go from 0-255.

I know that they put some voltage divider into the battery test circuit. Why, because if you give the AtoD pin > 5V it can damage the processor. So first trying to figure out what that is. So I modified the program to simply print out the AtoD value. I was getting values of around 358. Which gives us a voltage of 356/1024 * 5v = 1.73V. I measured mine and it was near 6.54. so if you take 6.54/1.73 = 3.78 so probably a 1/4 divider. So to print out the approx voltage in 100ths of a volt you would do something like:
Volts = (atodvalue * 100 * 20)/1024.

Or you could use real values if you wish. For failsafe things I would simply find what value you don’t wish to go below…

Kurt

Hi Kurte,

I actually did Email Nathan earlier about this, I did change the variable from a byte to word, I have tried all sorts of things, Nathan also said to make sure I was using studio 2.0 as well as changing the byte to a variable which I did, but I am in the same boat, and you are right about the voltage divider it is divided by four for the three battery readings (from Nathan)

All three battery readings are divide by 4(via voltage dividers).
P32 is for VS1
P33 is for VL
P34 is for VS2
P35 is for pin 6 of the AUX1 header.

Again my problem is that I still get 0 for a reading no matter which pin(32-35) that I try.

So why not simply use the adin for 56-58, like I did in the test program? Maybe his wrapper for the new API is not working…s

adin 56, volts1 adin 57, volts2 adin 58, volts3

Hi Kurte,

Actually I did try that earlier and got less than expected results (57 and 58 was 0, and 56 was showing 0.80v) however I did download and install the older mbide ver 1.0.0.3.5 on another pc, made changes to the code so that it would work with the older version and it is now working great…

I let Nathan know as well what I found…