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

measuring 60VDC to 0V DC using PIC18f87k22

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



Joined: 14 Oct 2006
Posts: 27
Location: islamabad,pakistan

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

measuring 60VDC to 0V DC using PIC18f87k22
PostPosted: Tue Aug 27, 2013 12:11 am     Reply with quote

hi
How to measure the 60V DC to 0V DC and with threshold of 47.5V DC Lower limit and there no check on upper limit.
Using ADC, from 0v to 5v dc. range.
regard


ihsan
>>>>>>>>>>>>>>>>>>>>>>
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 1:24 am     Reply with quote

This is a question outside the scope of this forum.
Have you even tried searching the internet? I did and found several promising links, for example this one: http://electronics.stackexchange.com/questions/32318/how-can-i-measure-voltage-in-range-15v-to-50v-with-adc-in-microcontroller-in-a
It is not exactly what you are looking for but will get you going and has links to similar questions.
Mike Walne



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

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 4:16 am     Reply with quote

I'm confused as to what you really want.

Do you want to:-

1) Measure 0 to 60V DC.
OR
2) Only test for being above or below the 47.5V threshold?

Mike
temtronic



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

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 5:19 am     Reply with quote

Sounds like he's got to 'test' a Telco battery feed or POE system.
One way is to have a voltage divider feeding one of the ADC pins.Then simple read adc..some math( >47.5VDC)...carry on

Easy to implement, just design/tets using say 3.5V as the 47.5 and cut code to work for you, then design a voltage divider to use on the 47.5 value.

hth
jay
ihsanbu



Joined: 14 Oct 2006
Posts: 27
Location: islamabad,pakistan

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

PostPosted: Tue Aug 27, 2013 5:57 am     Reply with quote

thank you for response ....
_________________
ihsan ullah khan
Embedded Designer Since 2003
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 7:17 am     Reply with quote

Also need to address what, if any, isolation is required between the measurement system and where the results go or are displayed. Is this some sort of floating supply or what? Isolation is often a very important question that seems to be overlooked until the test circuit lets the magic smoke out Rolling Eyes

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Ttelmah



Joined: 11 Mar 2010
Posts: 19399

View user's profile Send private message

PostPosted: Tue Aug 27, 2013 7:50 am     Reply with quote

and (of course), even if no isolation is needed, add an external trap diode, so that the PIC pin will never be taken over 5v.
ihsanbu



Joined: 14 Oct 2006
Posts: 27
Location: islamabad,pakistan

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

I got help... PIC18F87K22 & ADC 16bit, for telecom volta
PostPosted: Wed Aug 28, 2013 1:06 am     Reply with quote

Dear all

Thank all 4 guidance
>> Special Thanks to PCM Programmer code samples at forum
I did calculation for my telecom Voltage controlling project.....
may be helpful for some one ...

I am doing a work on Telecom voltage controlling using PIC18F87K22 & ADC 16-bit, with 16MHZ crystal, using EasyPIC ProV7, i did modify the flex_lcd driver for it by masking its RW and its second line comment and PCW 4.130V
Code:

Input Voltage Selected = from 5VDC---->100VDC
i am using Voltage divider for it,
////////////////////////////////////////////////////////////////////////////
       
Vin     R1 =100K                 Va                      R2 =5K
    o---^^^^^^^^^^---0-----^^^^^^^^^-----||~   

////////////////////////////////////////////////////////
// Voltage Divider circuit produce :
     Va =(0.04761904761904761904761904761905)* Vin
        // Also
>>Vin = 1/(0.04761904761904761904761904761905)* Vin
=>
>>>Vin = Va * 21<<<< // useful to get Vin Value
       
// Resolution =Va/digital Counter > Resolution: 5V/65536 = 0.0000762939453125

/////////////////////////////////////////////////////////////////////////////////////////
                                             
  #include <adctest02.h>
  #include <float.h>
  #include <math.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  #include "flex_lcd.c"



int16 value;
float volts;
float vin;
 

void main()
{

 lcd_init(); 
 //lcd_gotoxy(1,1);
 //printf(lcd_putc,"\nBISMILLAH !");
 //delay_ms(1000);
 
   setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4);
   setup_adc(ADC_CLOCK_DIV_32|ADC_TAD_MUL_16);
   //setup_adc_ports(AN0);
   //setup_adc(ADC_CLOCK_DIV_8);
   set_adc_channel(0);
   delay_us(20); 



   
   

    while(TRUE)
    {
// Voltage Divider circuit produce :
// Va = (0.04761904761904761904761904761905)* Vin
// Also Vin = 1/(0.04761904761904761904761904761905)* Vin
// => Vin = Va * 21
// Resolution =Va/digital Counter >
//Resolution: 5V/65536 = 0.0000762939453125
 ////////////////////////////////////////////////////////////////////
        value = read_adc();
        lcd_putc('\f');
        lcd_gotoxy(12,2);
        printf(lcd_putc,"%ld",value);
       
         lcd_gotoxy(7,2);
         volts = (float)(value * 4.999999999)/65536.0000;   
         printf(lcd_putc,"%3.2f", volts);
         ///// Vin = 21 * Va///////////////
          vin = (float)volts * 21;
         lcd_gotoxy(1,2);
         printf(lcd_putc,"%3.2f",vin);

         
        delay_ms(1000);
    }



The Voltage i require at 2.09=46.32,208,and son on..
but i require its stable state value at 47.7 at 2.13V at ADC value 29504 ...
can any one suggest me ... regard to ADC.....
_________________
ihsan ullah khan
Embedded Designer Since 2003
Ttelmah



Joined: 11 Mar 2010
Posts: 19399

View user's profile Send private message

PostPosted: Wed Aug 28, 2013 2:23 am     Reply with quote

Where are you getting a 16bit ADC from?....

The 87K22, has a _12bit_ ADC. If you select the output to be '16bit', it is just justified to be the top 12bits of the value. You don't miraculously gain resolution.

Then accuracies will be dependant on the resistors in the divider. Unless you are paying a huge amount for calibrated resistors, the 'best' you are likely to have is 0.2%.

Then you have the Vref. You are using the power supply. You'll be lucky to get even close to 7bits using this, let alone 12bit. Every spike and ripple on the rail, will degrade the ADC performance.

You need to learn that the best accuracy you can get is limited by the worst component in the entire circuit.

To get even close to 12bit, you need to be using low noise design throughout. Good ground planes with power routing away from the analog circuit. Low noise components, high accuracy separate Vref, then probably oversample the ADC.
Mike Walne



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

View user's profile Send private message

PostPosted: Wed Aug 28, 2013 2:37 am     Reply with quote

Why not replace this
Quote:
Va = (0.04761904761904761904761904761905)* Vin
With Va = Vin/21


I don't understand this
Quote:
>>Vin = 1/(0.04761904761904761904761904761905)* Vin


Is this telling us you're not getting stable readings?
Quote:
The Voltage i require at 2.09=46.32,208,and son on..
but i require its stable state value at 47.7 at 2.13V at ADC value 29504 ...
can any one suggest me ... regard to ADC.....


My copy of the data sheet shows the PIC you're using has a 12bit ADC.
Where have you got your 16bit ADC device from?

Mike
ihsanbu



Joined: 14 Oct 2006
Posts: 27
Location: islamabad,pakistan

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

PostPosted: Wed Aug 28, 2013 6:57 am     Reply with quote

hi mike Walne and ccs forum helper team

i catch my mistake which are device configured as 16 bit adc... i correct it now work OK ..

thank for great help

regard
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