Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20717

BASCOM-AVR : ADC Measurement : NEWTOPIC

$
0
0
Hi, This is my first post here so please be gentle guys.. :wink: I found a simple microcontroller based solar charger here: http://blog.amateurworld.in/archives/36 The software is written with BASCOM-AVR, I can understand most of the code (with the help of comments) but having trouble with the ADC portion.. CODE BELOW: [code:1:fa387868f4]'MICRO-CONTROLLER BASED SOLAR CHARGE CONTROLLER 'USED CHIP: ATMEGA8L WITH INTERNAL RC OSCILLATOR '*************************************************************** ' INITIAL SETTINGS '*************************************************************** $regfile = "m8def.dat" 'REGISTER FILE FOR ATMEGA8 $crystal = 1000000 'OSCILLATOR FRQUENCY=1MHZ $swstack = 40 'SOFT STACK SIZE $hwstack = 32 'HARDWARE STACK SIZE $framesize = 32 'FRAME SIZE '*************************************************************** ' DEFINE INPUT/OUTPUT PORTS '************************************************************** Config Portd.2 = Output Config Portd.3 = Output Config Portb.1 = Output Config Portb.2 = Output Config Portb.3 = Output '************************************************************** ' DEFINE ALIAS FOR GOOD READEBILITY '************************************************************** Charging Alias Portd.3 _load Alias Portd.2 Ch_led Alias Portb.3 Bat_h_led Alias Portb.1 Bat_l_led Alias Portb.2 '*************************************************************** ' SETUP ADC MODULE '*************************************************************** Config Adc = Single , Prescaler = Auto , Reference = Avcc '_2.56_nocap Start Adc '*************************************************************** ' VARIABLE DECLARATIONS '*************************************************************** Dim W As Word , W_single As Single Dim Sol_v As Single , B_high As Single Dim Bat_v As Single , B_low As Single Dim Gp1 As Byte , Gp2 As Byte '*************************************************************** ' MAIN PROGRAM LOOP '*************************************************************** Main: Gosub Check_adc If Bat_v < B_high And Sol_v > Bat_v Then Charging = 1 'CHARGING ON Ch_led = 0 'CHARGING LED ON Bat_h_led = 1 'BAT HIGH LED OFF _load = 0 'LOAD OFF End If If Bat_v >= B_high Then Charging = 0 'CHARGING STOPS Ch_led = 1 'CHARGING LED OFF Bat_h_led = 0 'BAT HIGH LED ON Bat_l_led = 1 'BAT LOW LED OFF Else Bat_h_led = 1 'BAT HIGH LED OFF End If If Sol_v < Bat_v Then Charging = 0 'CHARGING STOPS Ch_led = 1 'CHARGING LED OFF _load = 1 'LOAD ON End If If Bat_v <= B_low Then _load = 0 'LOAD OFF Bat_l_led = 0 'BAT LOW LED ON Else Bat_l_led = 1 'BAT LOW LED OFF End If Goto Main '*************************************************************** ' ADC MEASUREMENT SUB RUTINE '*************************************************************** Check_adc: For Gp1 = 2 To 5 W_single = 0 For Gp2 = 1 To 200 W = Getadc(gp1) W_single = W_single + W Next Gp2 If W_single <> 0 Then W_single = W_single / 200 Else W_single = 0 End If Select Case Gp1 Case 2 : Sol_v = W_single Case 3 : B_high = W_single Case 4 : B_low = W_single Case 5 : Bat_v = W_single Case Else End Select Next Gp1 Return '**************************************************************** End 'end program [/code:1:fa387868f4] Can somebody help me with the ADC portion.. TIA [b:fa387868f4][color=red:fa387868f4](BASCOM-AVR version : 2.0.7.8 )[/b:fa387868f4][/color:fa387868f4]

Viewing all articles
Browse latest Browse all 20717

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>