CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ACS758

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

ACS758
PostPosted: Sat Mar 16, 2013 3:01 pm     Reply with quote

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: 19552

View user's profile Send private message

PostPosted: Sat Mar 16, 2013 3:27 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Mar 16, 2013 3:33 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Mar 16, 2013 3:38 pm     Reply with quote

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: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Mar 16, 2013 4:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Mar 16, 2013 4:27 pm     Reply with quote

I correct the code accordingly but my issue how I am going to represent the Current. Just simple cross-multiplication?:

Code:
(value * 5)/1023
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Mar 16, 2013 6:05 pm     Reply with quote

What are you trying to measure?

Mean, peak, RMS current, what?

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group