I think this can help some newbie to get started to read current with hall sensor ACS785, the accuracy is 98%
; ==============================================================
; ACS758-100B SENSOR TEST TOOL
; Target: PIC16F886 (20MHz)
; By Samco, maker-brainy
; ==============================================================
chip 16F886, 20
option explicit
; --- LCD Setup (Change if your pins differ) ---
define LCD_IO 4
define LCD_NO_RW
define LCD_Speed fast
define LCD_RS PORTB.2
define LCD_Enable PORTB.3
define LCD_DB4 PORTB.4
define LCD_DB5 PORTB.5
define LCD_DB6 PORTB.6
define LCD_DB7 PORTB.7
; --- Sensor Setup ---
; AN1 is Pin 3 on PIC16F886
define SENSOR_PIN AN1
Dir PORTA.1 In
; --- ADC Configuration ---
; Fosc/32, AN0-AN4 Analog
ADCON0 = 0b00000001
ADCON1 = 0b10000010
Wait 20 us
; --- Variables ---
Dim RawADC As Word
Dim AvgADC As Word
Dim ZeroPoint As Word
Dim ADC_Diff As Word
Dim Amps_Tenths As Word
Dim Calc_Temp As Long
Dim i As Byte
Dim Sign As String * 1
; --- CONFIGURATION ---
; Theoretical Zero for ACS758-100B is 512 (2.5V).
; CHANGE THIS to the "RAW" value you see on screen when 0A flows.
ZeroPoint = 512
; --- Main Loop ---
Cls
Print "ACS758 Test Tool"
Locate 1,0
Print "GREAT COW BASIC "
Wait 1 s
Cls
Do
; 1. Average 50 readings to remove noise (Crucial for Hall Sensors!)
Calc_Temp = 0
For i = 1 To 50
RawADC = ReadAD10(SENSOR_PIN)
Calc_Temp = Calc_Temp + RawADC
Wait 1 ms
Next
AvgADC = Calc_Temp / 50
;2.CalculateDifferencefromZeroIfAvgADC>=ZeroPointThenADC_Diff=AvgADC-ZeroPoint;forPOSreadingSign="+"ElseADC_Diff=ZeroPoint-AvgADC;forNEGreadingSign="-"EndIf;3.CalculateAmps(ACS758-100B);Sensitivity:20mV/A.ADCStep:4.88mV.;StepsperAmp=20/4.88=4.1;Formula:Amps=Steps/4.1;ScaledMath:Amps*100=(Steps*100)/4.1->(Steps*1000)/41;Simplifiedapprox:Steps*24.4Calc_Temp=ADC_Diff*244Amps_Tenths=Calc_Temp/10;Resultisinhundredths(e.g.250=2.50A);4.DisplayLocate0,0Print"RAW ADC: ":PrintAvgADCLocate1,0Print"I: ":PrintSignPrintAmps_Tenths/100:Print".";Padthedecimalpart(e.g.turn"5"into"05")If(Amps_Tenths%100)<10ThenPrint"0"PrintAmps_Tenths%100Print" A "Wait200ms
Loop
it can also be called as subroutine
; ==============================================================
; ACS758-100B SENSOR TEST TOOL
; Target: PIC16F886 (20MHz)
; Using subroutine
; By Samco, maker-brainy
; ==============================================================
chip 16F886, 20
option explicit
; --- LCD Setup (Change if your pins differ) ---
define LCD_IO 4
define LCD_NO_RW
define LCD_Speed fast
define LCD_RS PORTB.2
define LCD_Enable PORTB.3
define LCD_DB4 PORTB.4
define LCD_DB5 PORTB.5
define LCD_DB6 PORTB.6
define LCD_DB7 PORTB.7
'#define LCD_WIDTH 16 ' FOR 4X16 LCD
; --- Sensor Setup ---
; AN1 is Pin 3 on PIC16F886
define SENSOR_PIN AN1 ' connect to PIN3 of the hall sensor
Dir PORTA.1 In
; --- ADC Configuration ---
; Fosc/32, AN0-AN4 Analog
ADCON0 = 0b00000001
ADCON1 = 0b10000010
Wait 20 us
; --- Variables ---
Dim RawADC As Word
Dim AvgADC As Word
Dim ZeroPoint As Word
Dim ADC_Diff As Word
Dim Amps_Tenths As Word
Dim Calc_Temp As Long
Dim i As Byte
Dim Sign As String * 1
; --- CONFIGURATION ---
; Theoretical Zero for ACS758-100B is 512 (2.5V).
; CHANGE THIS to the "RAW" value you see on screen when 0A flows.
ZeroPoint = 512
; --- Main Loop ---
Cls
Print "ACS758 Test Tool"
Locate 1,0
Print "GREAT COW BASIC "
Wait 1 s
Cls
DO
CALL Read_DC_Current
;4.DisplayLocate0,0Print"RAW ADC: ":PrintAvgADCLocate1,0Print"I: ":PrintSignPrintAmps_Tenths/100:Print".";Padthedecimalpart(e.g.turn"5"into"05")If(Amps_Tenths%100)<10ThenPrint"0"PrintAmps_Tenths%100Print" A "Wait200ms
Loop
Sub Read_DC_Current
'! 1. Average 50 readings to remove noise (Crucial for Hall Sensors!)
Calc_Temp = 0
For i = 1 To 50
RawADC = ReadAD10(SENSOR_PIN)
Calc_Temp = Calc_Temp + RawADC
Wait 1 ms
Next
AvgADC = Calc_Temp / 50
I have adapted for inclusion in the Demos. Can you please review and potentially test if you have time.
The ADC setup is not need as the ADC reads does this for you. And, this would look complicated to a new user.
I added header etc.
Change LCD to SLOW to ensure it works on breadboards.
Changed variable i to indexCounter as i can cause issues on chips with a bit called i.
Other changes are format.
I think this can help some newbie to get started to read current with hall sensor ACS785, the accuracy is 98%
; ==============================================================
; ACS758-100B SENSOR TEST TOOL
; Target: PIC16F886 (20MHz)
; By Samco, maker-brainy
; ==============================================================
chip 16F886, 20
option explicit
; --- LCD Setup (Change if your pins differ) ---
define LCD_IO 4
define LCD_NO_RW
define LCD_Speed fast
define LCD_RS PORTB.2
define LCD_Enable PORTB.3
define LCD_DB4 PORTB.4
define LCD_DB5 PORTB.5
define LCD_DB6 PORTB.6
define LCD_DB7 PORTB.7
; --- Sensor Setup ---
; AN1 is Pin 3 on PIC16F886
define SENSOR_PIN AN1
Dir PORTA.1 In
; --- ADC Configuration ---
; Fosc/32, AN0-AN4 Analog
ADCON0 = 0b00000001
ADCON1 = 0b10000010
Wait 20 us
; --- Variables ---
Dim RawADC As Word
Dim AvgADC As Word
Dim ZeroPoint As Word
Dim ADC_Diff As Word
Dim Amps_Tenths As Word
Dim Calc_Temp As Long
Dim i As Byte
Dim Sign As String * 1
; --- CONFIGURATION ---
; Theoretical Zero for ACS758-100B is 512 (2.5V).
; CHANGE THIS to the "RAW" value you see on screen when 0A flows.
ZeroPoint = 512
; --- Main Loop ---
Cls
Print "ACS758 Test Tool"
Locate 1,0
Print "GREAT COW BASIC "
Wait 1 s
Cls
Do
; 1. Average 50 readings to remove noise (Crucial for Hall Sensors!)
Calc_Temp = 0
For i = 1 To 50
RawADC = ReadAD10(SENSOR_PIN)
Calc_Temp = Calc_Temp + RawADC
Wait 1 ms
Next
AvgADC = Calc_Temp / 50
Loop
it can also be called as subroutine
; ==============================================================
; ACS758-100B SENSOR TEST TOOL
; Target: PIC16F886 (20MHz)
; Using subroutine
; By Samco, maker-brainy
; ==============================================================
chip 16F886, 20
option explicit
; --- LCD Setup (Change if your pins differ) ---
define LCD_IO 4
define LCD_NO_RW
define LCD_Speed fast
define LCD_RS PORTB.2
define LCD_Enable PORTB.3
define LCD_DB4 PORTB.4
define LCD_DB5 PORTB.5
define LCD_DB6 PORTB.6
define LCD_DB7 PORTB.7
'#define LCD_WIDTH 16 ' FOR 4X16 LCD
; --- Sensor Setup ---
; AN1 is Pin 3 on PIC16F886
define SENSOR_PIN AN1 ' connect to PIN3 of the hall sensor
Dir PORTA.1 In
; --- ADC Configuration ---
; Fosc/32, AN0-AN4 Analog
ADCON0 = 0b00000001
ADCON1 = 0b10000010
Wait 20 us
; --- Variables ---
Dim RawADC As Word
Dim AvgADC As Word
Dim ZeroPoint As Word
Dim ADC_Diff As Word
Dim Amps_Tenths As Word
Dim Calc_Temp As Long
Dim i As Byte
Dim Sign As String * 1
; --- CONFIGURATION ---
; Theoretical Zero for ACS758-100B is 512 (2.5V).
; CHANGE THIS to the "RAW" value you see on screen when 0A flows.
ZeroPoint = 512
; --- Main Loop ---
Cls
Print "ACS758 Test Tool"
Locate 1,0
Print "GREAT COW BASIC "
Wait 1 s
Cls
DO
CALL Read_DC_Current
Loop
Sub Read_DC_Current
'! 1. Average 50 readings to remove noise (Crucial for Hall Sensors!)
Calc_Temp = 0
For i = 1 To 50
RawADC = ReadAD10(SENSOR_PIN)
Calc_Temp = Calc_Temp + RawADC
Wait 1 ms
Next
AvgADC = Calc_Temp / 50
END SUB
Very good work and thank you for sharing.
I have adapted for inclusion in the Demos. Can you please review and potentially test if you have time.
The ADC setup is not need as the ADC reads does this for you. And, this would look complicated to a new user.
I added header etc.
Change LCD to SLOW to ensure it works on breadboards.
Changed variable i to indexCounter as i can cause issues on chips with a bit called i.
Other changes are format.
Ok, thank you Anobium for the point out ;correction. i have tested it and it works i attached the reading pictures for more verifications
Ok, thank you Anobium for the point out ;correction. i have tested it and it works i attached the reading pictures for more verifications
all in zip
Thank you!
All uploaded to https://github.com/GreatCowBASIC/Demonstration_Sources/tree/main/Hall_Effect_Solutions/ACS758LCB-100B_Solutions