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 support@ccsinfo.com

dspic30f4013

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



Joined: 27 Apr 2009
Posts: 50

View user's profile Send private message AIM Address

dspic30f4013
PostPosted: Wed Jan 23, 2013 6:30 am     Reply with quote

Hi i want to read analog input from acs712 using dspic30f4013.Is there any diffrence in setup reading the analog input from pic. because the reading I obtained convert to current is different from the multimeter reading. FYI I already tried the same prog for pic18f2480 and it works great

I'm using PCWHD 4.140

Code:

#include <30f4013.h>
#device adc=10
#use delay(clock=20000000) // A 20 Mhz crystal is used
#fuses hs,noprotect,nowdt
#use rs232(baud=9600,xmit=PIN_F5,rcv=PIN_F4, ERRORS)

#include <stdlib.h>

int main()
{
   
   unsigned int16 value;
   unsigned int16 temp;
   unsigned int16 Factor = 264;

   setup_port_a(ALL_ANALOG);
   setup_adc(ADC_CLOCK_DIV_16);
   SETUP_ADC_PORTS(sAN1);
   set_adc_channel(1);
   delay_us(10);

   do
   {
      value = read_adc();
      value = value + read_adc();
      value = value + read_adc();
      value = value/3;
     
      if (value < 512)
         temp = (512 - value);
      else
         temp = (value - 512);
      temp = (temp*Factor) ;
      value = temp/10;
      printf("Current is %ld mA\n", value);
      delay_ms(500);
   }while(1);
}

temtronic



Joined: 01 Jul 2010
Posts: 9207
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 23, 2013 8:10 am     Reply with quote

hmm.. you don't say what the readings are,which is kinda important!
Are they 'off' by 2-3 bits or 'random'?

some things to consider

1)You've set port A 'all_analog' but only use 1 input. Noise can easily be transferred to the reading.Normally you only 'enable' those ADC pins you really need.This might cause some 'random' nosie.

2) You've setup the adc_clock with /16. Is this correct for THAT PIC at the 20MHz clock speed? Datasheet will tell what is best configuration.

3)You read 3 times then compute average. It is 'better' programming to take 4 readings( or 8,16,etc) then average.The PIC will just right shift x4,x8,etc. It's faster and more accurate.

4)Hardware ? PCB, wirewrap,breadboard? 'floating' wires in the air? Improper grounds? EMI from welders,cellphones, coffee pot?

5) DVMs only sample about 3-4 readings per second, you do it in a few microseconds.

6) source noise. What's an ACS712 and what is it measuring?

The more information you supply the better we can try to figure out what's going on.

hth
jay
nasbyc



Joined: 27 Apr 2009
Posts: 50

View user's profile Send private message AIM Address

PostPosted: Wed Jan 23, 2013 9:05 am     Reply with quote

ACS712 is a current sensor which I used to measure the current consume by dspic and several devices. this is the result I get where on multimeter 0.05A or 0.04A. I already change setup_port_a(sAN1) and take 4 values into average but still the same result

Code:

Current is 73 mA
Current is 54 mA
Current is 34 mA
Current is 80 mA
Current is 93 mA
Current is 100 mA
Current is 60 mA
Current is 80 mA
Current is 60 mA
Current is 67 mA
Current is 60 mA
Current is 40 mA
Current is 54 mA
Current is 73 mA
Current is 47 mA
Current is 67 mA
Current is 100 mA
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Wed Jan 23, 2013 9:19 am     Reply with quote

nasbyc wrote:
ACS712 is a current sensor which I used to measure the current consume by dspic and several devices. this is the result I get where on multimeter 0.05A or 0.04A. I already change setup_port_a(sAN1) and take 4 values into average but still the same result


Are you kidding? The ACS712 is a 20A full scale device. You're trying to resolve 40 or 50mA.

What you're trying to do is akin to using a 10 ton scale to weigh a housefly.
temtronic



Joined: 01 Jul 2010
Posts: 9207
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 23, 2013 8:00 pm     Reply with quote

I just downloaded the Allegro specs....and it gets worse !!

That device is + and - 20 Amps ! So full range is 40 amps....

There is a +-5 amp device but really ,it's totally wrong for measuring <100ma current draws.

Far better to use a simple resistor and diff opamp or 'instrumentation amplifier' system. Heck even a simple PIC with a resistor between 2 analog pins will work(actually very well...).

Depending on the project a simple $5 DVM will do the job,right out of the box!

hth
jay
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