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

Urgent Need Help A/D Conversion

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



Joined: 13 Aug 2006
Posts: 12

View user's profile Send private message

Urgent Need Help A/D Conversion
PostPosted: Sun Aug 13, 2006 9:44 am     Reply with quote

Hi Everybody,

I have a big problem.I make a system about 48V 200 A Battery Charger for forklifts.I used 18F4520 and LM358 amplifier.I connect Voltage by voltage divider to AN0 and use shunt resistor for current input.I measure 25mv on shunt resistor.The shunt is on negative site.I use LM358 to amplifie 25mvand connect AN1.System is showing current , voltage and Ah total on LCD.When system start sometimes it freezes.I think the problem is ground problem because ı dont have like a problem when connect the systems +5V voltage to AN1 but when I connect shunt ground to my ground then system starts freezing.When I touch crystal pins then system back to the normal.What can ı do? What is problem do you think

please help meeeeeeeeee

#include <18F452.h>
#fuses XT,NOPROTECT,NOLVP
#fuses WDT128
#use delay(clock=4000000)


#include <lcd.c>

#define high_start 15
byte seconds, high_count;
byte dakika=0,saat=0;
byte tasama=0;
byte d=0,test=1;
byte dg=2;
byte carpan=1;
float deger,max,maxtemp;
float ahtoplam=0;
byte asama=0;
float value,akim,gvalue;
byte start, time,ilk=0,ilk2=0;
int i,a,sistemok,biberon,sonsuz;

byte zaman=0;

float gakim2,gvalue2,gahtoplam2;
byte gsaat2,gdakika2;


SHORT int sure=0;
byte islemtamam=0;

byte ariza=0,tdurum=1;
byte gecici1=0;
byte gecici2=0;
byte x1=0;
byte kademe=0;
byte gsaat;
byte gdakika;
byte a1=0,k=0;

void akimgerilim();

void akimgerilim()
{
set_adc_channel( 0 );
delay_us(10);
value = Read_ADC();
deger=value/51;
value=value/51;
delay_us(10);
set_adc_channel( 1 );
delay_us(10);
max=Read_ADC()*2;
delay_us(10);
//max=100;
}





#INT_RTCC //Interrupt procedure
clock_isr() { //called every time RTCC
high_count -= 1; //flips from 255 to 0



if(high_count==0)
{
akimgerilim();
++seconds;
high_count=high_start;
if(islemtamam!=1)
ahtoplam=ahtoplam+(max/3600); //Inc SECONDS counter every
} //76 times to keep time
if(seconds>=60)
{
dakika++;
seconds=0;
}

if(dakika>=60)
{
saat++;
dakika=0;
}

if( input(PIN_C0)!=1 )
{
if(tdurum!=asama)
{
tdurum=asama;
seconds=0;
d=asama;
}


if(dakika==1 && d==1)
{
tasama=1;
d=2;
}
if(seconds==15 && d==2)
{
tasama=2;
d=3;
seconds=0;
}
if(seconds==10 && d==3)
{
tasama=3;
d=4;
seconds=0;
}
if(seconds==10 && d==4)
{
tasama=4;
d=5;
seconds=0;
}
if(seconds==10 && d==5)
{
tasama=5;
d=6;
seconds=0;
}
if(seconds==10 && d==6)
{
tasama=6;
d=7;
seconds=0;
}
if(seconds==10 && d==7)
{
tasama=7;
d=8;
seconds=0;
}
if(seconds==10 && d==8)
{
tasama=8;
d=9;
seconds=0;
}
if(seconds==10 && d==9)
{
tasama=9;
seconds=0;
d=10;
}
if(tasama==9)
{

if(seconds==10*carpan)
{
dg=1;

}
if(seconds==(10*carpan)+4)
{
dg=0;
carpan++;
}
if(carpan==6)
carpan=1;
}
}


if( input(PIN_C0)==1 )
{
tasama=0;
dg=2;
carpan=1;
}
}

besli() {
OUTPUT_HIGH(PIN_D7);
delay_ms(300);
OUTPUT_LOW(PIN_D7);
OUTPUT_HIGH(PIN_D6);
delay_ms(300);
OUTPUT_LOW(PIN_D6);
OUTPUT_HIGH(PIN_D5);
delay_ms(300);
OUTPUT_LOW(PIN_D5);
OUTPUT_HIGH(PIN_D4);
delay_ms(300);
OUTPUT_LOW(PIN_D4);
OUTPUT_HIGH(PIN_D3);
delay_ms(300);
OUTPUT_LOW(PIN_D3);
}
dortlu() {
OUTPUT_HIGH(PIN_D6);
delay_ms(350);
OUTPUT_LOW(PIN_D6);
OUTPUT_HIGH(PIN_D5);
delay_ms(350);
OUTPUT_LOW(PIN_D5);
OUTPUT_HIGH(PIN_D4);
delay_ms(350);
OUTPUT_LOW(PIN_D4);
OUTPUT_HIGH(PIN_D3);
delay_ms(350);
OUTPUT_LOW(PIN_D3);
}
uclu() {
OUTPUT_HIGH(PIN_D5);
delay_ms(400);
OUTPUT_LOW(PIN_D5);
OUTPUT_HIGH(PIN_D4);
delay_ms(400);
OUTPUT_LOW(PIN_D4);
OUTPUT_HIGH(PIN_D3);
delay_ms(400);
OUTPUT_LOW(PIN_D3);

}

void ikili() {

OUTPUT_HIGH(PIN_D4);
delay_ms(450);
OUTPUT_LOW(PIN_D4);
OUTPUT_HIGH(PIN_D3);
delay_ms(450);
OUTPUT_LOW(PIN_D3);
}

void tekli()
{
OUTPUT_HIGH(PIN_D3);
delay_ms(500);
OUTPUT_LOW(PIN_D3);
delay_ms(500);
}

void main()
{


lcd_init();
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
setup_port_a( AN0_AN1_AN3 );
setup_adc( ADC_CLOCK_DIV_32 );
high_count = high_start;
setup_timer_0( RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT );
set_timer0(0);
// setup_wdt(WDT_OFF);


do {

lcd_putc("\f");
delay_ms(1);
lcd_putc("\f ** M K P Micro **\n");
lcd_putc(" Akuyu Baglayiniz");
delay_ms(200);
ilk2=0;
do {

output_high(PIN_D2);
delay_ms(250);
output_low(PIN_D2);
delay_ms(250);

}while (deger<1);

OUTPUT_HIGH(PIN_D2);


lcd_putc("\f");
delay_ms(1);
lcd_putc("\f Aku Baglandi\n");
lcd_putc(" Bekleyiniz");




for(a=0;a<3;a++)
{

OUTPUT_D(0xff);
delay_ms(450);
OUTPUT_D(0x00);
delay_ms(450);
}


OUTPUT_HIGH(PIN_D2);
OUTPUT_HIGH(PIN_C1);

if(deger<1>2.40)
{
ariza=3;
goto ariza10;
}



delay_ms(1500);
// setup_wdt(WDT_ON);

//
asama=1;
dakika=0;
saat=0;
seconds=0;
ahtoplam=0;
ilk=0;
kademe=0;



do {

ariza=0;

if(ilk==0)
{
ilk=1;
if(max<2)
{
ariza=5;
break;
}
}



if(max<2)
{
islemtamam=0;
a1=0;
ariza=4;
break;
}

lcd_gotoxy(1,1);
printf(lcd_putc,"V:%01.2f Ah:%2f.1\n", value,ahtoplam);
lcd_gotoxy(1,2);
printf(lcd_putc,"I:%03.1f T:%02u:%02u:%02u",max, saat,dakika,seconds);



if(value<2>=2.10 && value<2>=2.20 && value<2>=2.30 && value<2.40 && kademe==0)
{
OUTPUT_HIGH(PIN_D7);
OUTPUT_HIGH(PIN_D6);
OUTPUT_HIGH(PIN_D5);
ikili();
................
.........
............
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 13, 2006 4:54 pm     Reply with quote

Urgent help means it's a student project. You didn't use the Code
format buttons when you posted your code. You didn't disable HTML
when you posted, so the lines near the bottom are trashed. You didn't
read your code after you posted it. If you did, then you would have
noticed that the bottom lines are trashed.

If you do a search on http://www.google.com for these keywords, you
will get many articles (with source code) for a lead acid battery charger:
"lead acid" "battery charger" #define int main

I quickly found Microchip appnotes AN626 and AN1015. Atmel has
appnote AVR450.

After looking at the list of hits, you can see that Circuit Cellar appears
often, so get those articles by changing the list of keywords to this:
"lead acid" "battery charger" "Circuit Cellar"

There are tons of sample projects out there.
ekocakaya



Joined: 13 Aug 2006
Posts: 12

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 10:44 am     Reply with quote

I didnt give rest of program.The program is not important .As you said I looked google but I found nothing for microcontroller project.

If you can give me more detail .I will be very pleased
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 12:04 pm     Reply with quote

I think the problem is that the "Ground" of the 200A shunt is bound to be dozens of millivolts away from the "Ground" of the PIC A/D. You will get ground loop currents that will mess up the PIC.
The solution is to use a difference amp to isolate the 200A ground from the PIC ground. Then small differences in ground potentials won't affect the PIC. An instrumentation amp would be best, but four resistors and half the LM358 will do for low accuracy work. Maybe you can use one LM358 section for the diff amp at a gain of 5 or 10, and the second section to get the rest of the gain you need.
_________________
The search for better is endless. Instead simply find very good and get the job done.
ekocakaya



Joined: 13 Aug 2006
Posts: 12

View user's profile Send private message

PostPosted: Mon Aug 14, 2006 3:44 pm     Reply with quote

any other idea?? or do you have any circuit for this?
jfk1965



Joined: 21 Oct 2003
Posts: 58

View user's profile Send private message

PostPosted: Mon Aug 21, 2006 2:17 am     Reply with quote

For currents of that magnitude I usually find there is too much power dissipation in the shunt resistor so use a hall effect sensor instead, the output of this can be fed directly into your A/D.

This also tends to eliminate any ground loop effects.

JFK
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