Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Power measurement with Atiny85 and small OLED

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
Insanity

Bascom Member



Joined: 25 Apr 2021
Posts: 8

germany.gif
PostPosted: Mon Apr 26, 2021 10:48 am    Post subject: Power measurement with Atiny85 and small OLED Reply with quote

I have a little project here with OLED
For my 12V LED lighting I built a small current, voltage and power measurement.
Evaluation runs via an Atiny85. Supplied from the 12V with 78L05.
Voltage with voltage divider from 12k to 1k
Current with a shunt of 10mOhm
Internal reference = 1.1V
There is no circuit diagram.
Have made adjustments for voltage and current in the program.

Code:


' Insanity

' Test mit OLED

$Regfile="M328pdef.dat"
$Crystal=8000000
$hwstack=64
$swstack=64
$framesize=64

' Spannungsteiler mit 12K zu 1K
' Bei 12V = 859 Digits
Const Spannung_Faktor = 12/885

' Shunt mit 0.01 Ohm
' Bei 15A = 140 Digits
Const Strom_Faktor =  15/120

'I2C Config

CONFIG I2CBUS= 0 , SCL=Port , SDA=sda
Config Scl = PortB.2
Config Sda = PortB.0

'Display Config
$lib "glcdSSD1306-I2C.lib"                                  ' SSD1306 LIB einbinden

Config I2cdelay = 1
I2cinit
Waitms 10

Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306"       'SSD1106 oder SSD1306

Cls

' Anlogfunktionen
Declare Function Analog(byval Kanal As Byte , Byval Anzahl As Word ) As Word

Config Adc = single , Prescaler = Auto , Reference = INTERNAL_1.1
Start Adc

Config Single = Scientific , Digits = 1

Wait 1

Dim Wert_U as Integer
Dim Wert_I as Integer

Dim Ergebnis As Single
Dim Ergebnis_U As Single
Dim Ergebnis_I As Single
Dim Dummy as String * 8

Setfont font12x16
Cls
Lcdat 1 , 1 , "Volt"
Lcdat 4 , 1 , "Amp."
Lcdat 7 , 1 , "Watt"
Lcdat 1 , 117 , "V"
Lcdat 4 , 117 , "A"
Lcdat 7 , 117 , "W"

Setfont Digital11x16

Do

  Wert_U = Analog(3,1000)
  Wert_I = Analog(2,1000)

  Ergebnis_U = Wert_U * Spannung_Faktor
  Dummy = Str(Ergebnis_U,1)
  Ergebnis_U = Val(Dummy)
  Dummy = "    " + Dummy
  Dummy = Right(Dummy,4)
  Lcdat 1 , 70 , Dummy

  Ergebnis_I = Wert_I * Strom_Faktor
  Dummy = Str(Ergebnis_I,1)
  Ergebnis_I = Val(Dummy)
  Dummy = "    " + Dummy
  Dummy = Right(Dummy,4)
  Lcdat 4 , 70 , Dummy

  Ergebnis = Ergebnis_I * Ergebnis_U
  Dummy = Str(Ergebnis,1)
  Dummy = "    " + Dummy
  Dummy = Right(Dummy,5)
  Lcdat 7 , 59 , Dummy

Loop


' Analog messen
Function Analog(Kanal , Anzahl)

  Local Schleife As Word
  Local Analogmesswert As Word
  Local Analogmesswert_summe As Long
  Local Analog_mittel As Long

  If Anzahl = 0 Then Anzahl = 1
  Analogmesswert_summe = 0

  For Schleife = 1 To Anzahl
    Analogmesswert = Getadc(Kanal)
    Analogmesswert_summe = Analogmesswert_summe + Analogmesswert
  Next

  Analog_mittel = Analogmesswert_summe / Anzahl

  Analogmesswert = Analog_mittel
  Analog = Analogmesswert

End Function


'LCD-Font
$include "font12x16.font"
$include "Digital11x16.font"
 
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum