Shop OBEX P1 Docs P2 Docs Learn Events
Measuring battery voltage with Bs1 and ADC0831 — Parallax Forums

Measuring battery voltage with Bs1 and ADC0831

icepuckicepuck Posts: 466
edited 2012-01-08 16:49 in BASIC Stamp
I started off with ad_conv.bas form the bs1appnotes in chapter 2 along with that same circuit. I have it all working on a breadboard.The problem I'm having is with converting the bs2 code from BAADv1.3.pdf to give a voltage.
I started to convert the following code..
Calc_Volts:
  v = 16 * adcBits / 255
  r = 16 * adcBits // 255
  v2 = 100 * r / 255
  v3 = 100 * r // 255
  v3 = 10 * v3 / 255
  IF (v3 >= 16) THEN v2 = v2 + 1  '<-- syntax check makes it this far when it expects
  IF (v2 >= 100) THEN             ' a variable
    v = v + 1
    v2 = 0
  ENDIF
RETURN

I think it may have something to do with the "()" for rounding.
IF (v3 >= 16) THEN v2 = v2 + 1  
  IF (v2 >= 100) THEN             
    v = v + 1
    v2 = 0
  ENDIF

Trying to rewrite that segment of code is were I'm getting confused.

I included the original working code and the non working code
-dan.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-01-06 21:02
    The BS1 does not allow anything other than a label after the THEN and I'm not sure parentheses are allowed in the IF expression. ENDIF is also not allowed. You'd need:

    IF v3 < 16 THEN label1
    v2 = v2 + 1
    label1:
    IF v2 < 100 THEN label2
    v = v + 1
    v2 = 0
    label2:
  • icepuckicepuck Posts: 466
    edited 2012-01-08 16:49
    thanks, all I have to do now is figure out how to display the output the way I want.
    -dan
Sign In or Register to comment.