View previous topic :: View next topic |
Author |
Message |
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
ACS758 |
Posted: Sat Mar 16, 2013 3:01 pm |
|
|
Dear All,
I am making another project which requires the ACS758 Hall-Effect Current sensor. Up to now I made the following code:
Code: | void main()
{
int16 counter1;
unsigned int16 value1;
unsigned int16 value2;
printf("\f");
printf("Current Monitoring using ACS758\r\n");
setup_adc_ports(PIN_A0);
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //104 ms overflow
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
do
{
value1 = read_adc();
value1 = value1 + read_adc();
value1 = value1 + read_adc();
value1 = value1/3;
if (value1 < 512)
temp = (512 - value);
else
temp = (value - 512);
value = value2/10;
printf("%Ld Current Value: %LdA\r\n" counter1 ,value);
delay_ms(1000);
}while(1);
}
|
I read the datasheet and made the code but for some reason the output is not good. Do someone has any experience on this ACS? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Sat Mar 16, 2013 3:27 pm |
|
|
Start with which acs758.
There are about ten different varieties, returning different current sensitivities, and (more importantly), with some supporting bi-directional operation. The bidirectional versions will return half the supply voltage for no current. Your code suggests a 'B' (bidirectional) device.
Then have you got the output filter?. Resistor/capacitor on the output. This is important to get good behaviour.
Then ADC_CLOCK_INTERNAL, degrades your accuracy. This is _not_ a legal ADC clock, unless your processor is running under 1MHz.
Then you need Tacq before your first ADC reading, _and between successive readings_.
You don't show your chip configuration. You need #device ADC=10.
Is your signal AC?. Your use of the B device suggests this. If so, frequency?. Remember you will only be taking three momentary samples. You need to take samples for the entire of one cycle.
Best Wishes |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Sat Mar 16, 2013 3:33 pm |
|
|
Dear temtronic,
Thanks for your prompt reply. I am using the 18f4550 with a crystal of 20mhz. I am measuring ac currents voltage of 50hz. I used this because the current is not going to exceed 30 A. Yes i have filtering n the output stage.
What do you mean by adc=10? |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Sat Mar 16, 2013 3:38 pm |
|
|
Ignore the question regarding adc = 10. I found it in the manual.
I am using the acs758 lcb 050b. Indeed the chip produce the half volatge when no current is being applied. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Mar 16, 2013 4:23 pm |
|
|
note...
1) You've enabled an interrupt without a 'handler'. NOT good programming, it'll crash or fail for some 'unknown' reason....
2) You're better to take 4,8,16,etc. readings and then average.The compiler will make efficient, accurate code for you !!
3) You're 'sampling' only 1 quick set of readings /second. Better to increase to say 3 or 4 X per second, which is similar to most DMM.
hth
jay |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Sat Mar 16, 2013 4:27 pm |
|
|
I correct the code accordingly but my issue how I am going to represent the Current. Just simple cross-multiplication?:
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Mar 16, 2013 6:05 pm |
|
|
What are you trying to measure?
Mean, peak, RMS current, what?
Mike |
|
|
|