View Single Post
Old Dec 08, 2012, 12:36 PM
snoopy_schulz is offline
Find More Posts by snoopy_schulz
Registered User
snoopy_schulz's Avatar
Germany, lake of constance
Joined Oct 2010
409 Posts
FrSky Voltage Sensor Calc.

Hi

Here is a tcl/tk program for the calculation of the FrSky voltage sensor (FBVS-01) digits and sensor ratio.
The program selects a best ratio (2:1-6:1) depending on battery type and cells. Also the digits and the alarm voltage
depending on Voltage Alarm per cell is displayed.

Download of the program (.exe):

snoopy-schulz.square7.ch/voltage_divider.exe

Best regards
Micha

Code:
# Michael Schulz 21.01.2012

proc calculate {} {
  global Cells Accu Ratio VD VA BV
  
  if {($Accu == "LiPo")} {set ucell 4.2}
  if {($Accu == "LiIo")} {set ucell 4.1}
  if {($Accu == "LiFePo")} {set ucell 3.6}
  if {($Accu == "NiMh")} {set ucell 1.4}
  set U [expr $Cells * $ucell]
  
  if {($Accu == "LiPo") && (($VA < 3.1) || ($VA > 3.6))} {tk_messageBox -icon error -message \
                                        "Is no valid alarm voltage!
                                        \nUse 3.1 Volt - 3.6 Volt."}
                    
  if {($Accu == "LiIo") && (($VA < 2.6) || ($VA > 3.4))} {tk_messageBox -icon error -message \
                                        "Is no valid alarm voltage!
                                         \nUse 2.6 Volt - 3.4 Volt."}      
  
  if {($Accu == "LiFePo") && (($VA < 2.2)|| ($VA > 2.6)) } {tk_messageBox -icon error -message \
                                        "Is no valid alarm voltage!
                                         \nUse 2.2 Volt - 2.6 Volt."}   
                                         
  if {($Accu == "NiMh") && (($VA < 1.0) || ($VA > 1.1))} {tk_messageBox -icon error -message \
                                        "Is no valid alarm voltage!
                                         \nUse 1.0 Volt - 1.1 Volt."}                                                                                                     
  
  
  set RA [expr $U/3.3]
  set Ra 2.0
  if {($RA > 2.0)} {set Ra 4.0}
  if {($RA > 4.0)} {set Ra 6.0}
  
  set Ra [format %1.0f $Ra]
  $Ratio delete 0 100 
  $Ratio insert 0 $Ra
  
  set Vd [expr ($VA*1.0*$Cells/$Ra/3.3)*256.0]
  set Vd [format %1.0f $Vd]
  $VD delete 0 100 
  $VD insert 0 $Vd
  
  set Bv [expr $VA*1.0*$Cells]
  set Bv [format %1.1f $Bv]
  $BV delete 0 100 
  $BV insert 0 $Bv
  
  
  if {$RA >= 6.37} {tk_messageBox -icon error -message \
                    "Not valid max voltage!
                    \nUse DIY voltage divider."}
                                      
}

proc gui {} {
      global Cells Accu Ratio VA VD BV
      wm minsize . 270 300
      wm title . "FrSky Voltage Divider V1.0"
           
      set a [labelframe .a -bd 3]
        
        set m2 [frame .a.m2]
        set f2 [frame $m2.f2]
          set lf2 [label $f2.lf2 -text "Accu Type: " -font {Arial 10 bold }]
          tk_optionMenu $f2.1 Accu LiPo LiIo LiFePo NiMh
          pack $lf2 -side left
          pack $f2.1 -side right
        pack $f2 
       pack $m2 -fill x -pady 6  
        
        set m [frame .a.m]
        set f1 [frame $m.f1]
          set lf1 [label $f1.lf1 -text "Cells: " -font {Arial 10 bold}]
          tk_optionMenu $f1.1 Cells 1 2 3 4 5
          pack $lf1 -side left
          pack $f1.1 -side right
        pack $f1 
       pack $m -fill x -pady 6
        
        set a5 [frame $a.a5]
          set al [label $a5.l -text {Voltage Alarm per Cell [V]} -font {Arial 10 bold }] 
          set ae5 [entry $a5.e -width 3 -justify right -textvariable VA -font {Arial 10 }]
          pack $al -side left
          pack $ae5 -side right
        pack $a5 -fill x -pady 6 
       
      pack $a -fill y -pady 10
   
      set b [labelframe .b -bd 3]
        set b1 [frame $b.b1] 
          set bl [label $b1.l -text {Ratio } -font {Arial 10 bold }] 
          set Ratio [entry $b1.e -width 4 -justify right -font {Arial 10 }]
          pack $bl -side left
          pack $Ratio -side right
        pack $b1  -fill x -pady 6
        
        set b2 [frame $b.b2] 
          set bl [label $b2.l -text {Value Digits } -font {Arial 10 bold}] 
          set VD [entry $b2.e -width 4 -justify right -font {Arial 10 }]
          pack $bl -side left
          pack $VD -side right
        pack $b2  -fill x -pady 6
        
        set b5 [frame $b.b5] 
          set bl [label $b5.l -text {Alarm Voltage } -font {Arial 10 bold}] 
          set BV [entry $b5.e -width 4 -justify right -font {Arial 10}]
          pack $bl -side left
          pack $BV -side right
        pack $b5  -fill x -pady 6
                     
      pack $b -fill y -pady 10    
    
      set bu [labelframe .bu] 
        button $bu.1 -text "Calc" -command {calculate} -font {Arial 10 bold } -bd 3
        pack $bu.1 
      pack $bu
       
}      

########################## Main ###############################################  
set ignore [catch {eval {wm iconbitmap . -default [file join \snoopy.ico]}}]
global VA Cells
set VA 3.4; set Cells 3
gui
snoopy_schulz is offline Find More Posts by snoopy_schulz
Reply With Quote