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

PICDEM ADC Blues

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



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PICDEM ADC Blues
PostPosted: Tue Aug 19, 2008 4:43 pm     Reply with quote

Does any one know of problems regarding ADC with the picdem 2 plus board. My problem is i need to build a vibration system a project im working on but the adc is not functioning right or i made a code mistake some where. Im using the LIS3L02AL 3 ax accelerometer with values on flat table acc looking up:

X:1.659
Y:1.638
Z:2.212

According to the D/sheet the values are
X=1.65V (0g)
Y=1.65V (0g)
Z=2.31V (+1g)

So mine are not great but not to far off.

I am using 3.3v for the accelerometer and also using it for a vref on the board. with grounds commoned.

I was playing around just to get a basic value through the adc and onto the terminal but the values are a bit suspect.

Heres my basic code:
Code:
#include <16f877A.h>
#device *=16 ADC=10 ICD=true
#fuses HS,NOWDT,NOPROTECT, NOWRT, NOCPD, NOLVP, NOBROWNOUT

#include <hardware.h>
#include <global.h>

#use delay(clock=OSC_FREQ,RESTART_WDT)
#use rs232(baud=BAUD_RATE,xmit=TX,rcv=RX,parity=N,bits=8,RESTART_WDT,STREAM=streamed)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)

#include <Test_Pin.c>
#include <Xout.c>
#include <Yout.c>
#include <Zout.c>
#include <Xbuff.c>
#include <Ybuff.c>
#include <Zbuff.c>


#inline
void nop()
{
#asm
  NOP
#endasm
}

void init()
{
  // Start watchdog timer with default configuration
  restart_wdt();
 

  // Configure all Ports for ADC
  Setup_ADC_Ports( ALL_ANALOG );
   
  // Initialize the port output data latches
   PORT_A = 0;
   PORT_B = 0;
   PORT_C = 0;
   PORT_D = 0;
   PORT_E = 0;

   // Setup data direction registers (1 = input)
   Set_Tris_A(0b111111);
   Set_Tris_B(0b00000000);
   Set_Tris_C(0b10000000);
   Set_Tris_D(0b00000000);
   Set_Tris_E(0b111);
   
  port_b_pullups(true);
 


   // Initialize and restart watchdog timer
  setup_counters(WDT,WDT_36MS);   // Assign prescaler (DIV 2) to WDT
  restart_wdt();

  // Setup AD clock
  SETUP_ADC( ADC_CLOCK_DIV_8);

   //Usart Asysnchronous registers setup
   SPBRG = 25;
   TXSTA = 0b00100100;

}

void main()
{
   init();

   enable_interrupts(GLOBAL);
     
  // Housekeeping
   restart_wdt();
 
   while(true)
  {
   
    //Measure_Xout();
    Measure_Yout();
    
   printf("%3.5f \n\r", Yaxis);
 
  }
}


with the include
Code:
void Measure_Yout()
{

set_adc_channel(1);
delay_us(20);


  {
   adc_value = read_adc();
   Yaxis = (float)(adc_value * 3.3)/1023.0;   
   delay_ms(500);
  }
}


Just again this code is very basic. The reason im bugging the forum with my question in that on the dev board theres a little pot connected to one of the adc channels which gave me a super nice and accurate value after some adc. So thats why im struggeling a bit.
_________________
"THE ONLY EASY DAY WAS YESTERDAY"


Last edited by jacqueskleynhans on Thu Aug 21, 2008 2:14 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 19, 2008 5:29 pm     Reply with quote

Here is a test program for the A/D on the PicDem2-Plus board.
It uses the LCD, but you can slightly modify it to send the results
out the RS-232 port instead.
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

I am using similar code
PostPosted: Wed Aug 20, 2008 4:08 am     Reply with quote

I actually have a similar routine to the on that you describe but the sensor reading are very un accurate. Will there be a problem with the multiplexing of some pins and me using the adc. I saw there is a lot of info regarding the adxl330 on this forum so will not go into the "HOW" at this stage, just want to get my initial reading right before i start with the craziness of doing calibration and things to my 3 signals.

The sensitivity of the sensor is 660mv/g is that good. I need to measure vibration frequencies across the full frequency response of 1600hz.

Kind regards
Any comment will be appreciate
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
Ttelmah
Guest







PostPosted: Wed Aug 20, 2008 7:16 am     Reply with quote

Your values may well be closer than you think!.
The PIC ADC, is slightly unusual, in where it's 'steps' come over the sample range. If you read up on the MicroChip site, you will find that the design results in it reading it's full scale value, one step 'early', compared to most designs. The best 'fit' to get a reading from it, is given by dividing by 1024, not 1023. Also the vertical value when stationary, won't correspond to '1g', but typically about 0.98g (depends where you are on the Earth actually). Applying these corrections to your numbers, gives:
1.656
1.637
2.210
The expected value for 0.98g, is 2.2968v, not your 2.31.
Rounding to just two decimals (which is all that is really justified by the sensor), gives 1.66, 1.64, and 2.28. 0.6% high, 0.6% low, and 0.7% low. All nicely within the accuracy that is normally quoted for these sensors. :-)

Now, you ask whether 660mV/g is 'good'. This depends on what the range of values you expect to deal with 'is'. If the vibrations are only say 0.1g, then you would only see +/-66mV of variation. Given the 'step' size of the ADC, is 3.22mV, you would only see about 20 steps change in the reading. If your expectations are in this sort of area, you will really need to amplify the signals.

1600Hz, would require sampling at at least twice this frequency (3200*/sec). To do this for three channels, given that the ADC, requires 20uSec acquisition time, and 12 AD clock cycles for each acquisition, is going to be hard. How are you going to store the values?.
If your master clock is 5MHz (the maximum supported by an Fosc/8 ADC clock), the whole acquisition, is going to take just on 40uSec, plus the time needed to read the value, and write it to whatever memory you are using (I am assuming you will use external memory, since otherwise the internal memory of the chip would only allow storage of about 19mSec of data at this speed). Say perhaps another 10 to 20uSec to store the data. This is achievable, but would be a lot easier on one of the latter chips with faster ADC's...

Best Wishes
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

ADC
PostPosted: Wed Aug 20, 2008 10:51 am     Reply with quote

Hi Ttelmah,

I need to measure the vibration of an high voltage transformer so i suspect the vibration will be small so im going to need to pump up the value. Iam using a 4Mhz crystal atm but to bump that up to atleast 10 is not an issue. The project im doing requires 5 boards each with its own accelerometer and magnetometer on to condition monitor a h/v trans former.

I recently bought an dspic33 dev board so i was thinking of using one of those beace they have 32 analog inputs which i can use than desgn a sort of data logger with some sd ram "maybe " and clock that out wirelessly through a mote. Sorry i made another post on the form of my project details eg vibration and magnetic flux monitoring.

Whats your views on the success with a project like this rather using a more beefier dspic than a normal 16f87**.

Kind regards
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
Ttelmah
Guest







PostPosted: Thu Aug 21, 2008 2:32 am     Reply with quote

A faster processor will help in a lot of things, and in particular the faster ADC on these chips will help a lot.
You have not answered about how you intend to store the data, or how much is likely to be involved?. Using 3200 samples per second, 16bits per sample, on say 30 inputs, will give you 192000 bytes per second. Handling storing this is the hardest part. Memories like EEPROM, take too long to write for this sort of data rate. You need RAM, or FRAM, and if you are going to store more than a very short period of samples, a _lot_ of it. You talk about SDRAM, have you thought about how hard this is to drive, and the fact that you will need to maintain power to this?.
The PIC's, only have one or two ADC's. Hence only one or two readings can be done _at once_. They then have multiplexers, to allow these to be connected to a number of inputs (up to 32), _but_ if an external Vref is being used, one or two of these inputs are lost. The really 'good' thing about the DSPICs, is that they can automatically perform a sequence of readings for you, and transfer the data into a small area of the chip's RAM, allowing you to use the same time for other jobs (like saving the last set of readings).
Now, realistically, you are _not_ going to be able to process the data 'on the fly'. Either the PIC, or a PC, will have to latter go through the data, and perform a Fourier transform to identify the frequencies present, and the size of each component.
You need to quantify your inputs a lot better. How many channels?. What accuracy do you actually _need_ (you can save a lot of storage, if you can amplify the signal, and scale the values to fit in 8bits/sample). How long are you going to sample for?.
Seriously, is this going to be for a 'one off', or low production design. If so, consider saving a _huge_ amount of work, and using an off the shelf 'embedded' PC. Run a minimum Linux, and a PC104 data acquisition card, and you have the whole system, and it'll be cheaper than going 'DIY', for anything under perhaps 100 off quantities. Something like the RPC632 card (a little 'old' now, there may well be better alternatives), should do what you need.

Best Wishes
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

adc
PostPosted: Thu Aug 21, 2008 4:47 am     Reply with quote

Hi Ttelmah,

I appreciate your comment, well this project is for my final year thesis in elec eng, it consists of me measuring the vibration and the magnetic flux of high voltage transformers.

* i need 30 channels of adc (might look into external adc's)

* atleast 10bit resolution (beacause tha data will later be used in n mesh matlab model to visualize the reading)

*i have thought about sdram which will probably be the best option to store the arrays in temp before sensing them out wirelessly.

*This will be a onceoff product maybe 3 more to form a wsn of monitoring these transformers.

*
Quote:
Now, realistically, you are _not_ going to be able to process the data 'on the fly'
Data will be preprocesed at a later stage to find the fft and model what the data reprents

* data is sampled once every every 3-5 min then systematically send or send as packet which ever is a better option.

*there are sdram option for low voltage application might look into that

Sensors will be hardwired to an central control "box" and then info will be send out through to the mote for sending.

Kind regards
Jacques Kleynhans
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
Ttelmah
Guest







PostPosted: Thu Aug 21, 2008 7:12 am     Reply with quote

The comment 'data will be sampled once every 3-5 minutes', does not make sense. Do you mean the data will be sampled 'for' 3-5 minutes?. If it only for a period every 3-5 minutes, then how long is the period?.
SDRAM is hard, since it needs to be refreshed. It is not a simple memory to use with a PIC. Seriously look at something easier to drive.
Do you have to design the board?. Otherwise just use an embedded PC...

Best Wishes
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

its not going to work
PostPosted: Thu Aug 21, 2008 9:39 am     Reply with quote

Hi Ttelmah,

I going to ask you to forget everthing on this post. Having one central station connecting all the sensors to with long pieces of wire is not going to work because of the vast amount of interferance im dealing with in the power plant enviorment. All the amount of screenedwire im going to need i might as well go wireless. I have decided to go a new route im am gona develop 6 diffrent boards each with an magnetometer, acceleromter, pic and a zigbee module. Then congigure them in a star formation "speaking to a central unit wirelessly then sending the data away to the gateway.

In this case outside noise will be reduce beace im having my accelrometer basically next to my pic and no wires. So now i will be needing something simplar each sensor will have 6 adc channels, ill get away with 10 bit ill try for 8. ill will sample data a couple of times to get an average then send, sleep for 3-5min and do the process again(guesstamate ill sample for 10sec every 5min or so) but something in that range. Unfortuanatly i have to design them a board.
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

a bit confused about the sampling
PostPosted: Thu Aug 21, 2008 11:23 am     Reply with quote

I am a bit confused about the sampling Confused. For instance in the vibration I'm measuring there are harmonics at certain increment of the fundamental at 300Hz, 500, 700, 900Hz, until 1500. Do i need to sample the vibration at the maximum of my bandwidth of the accelerometer at 1600 to be able to see these harmonics or how do i go about doing this. Also the harmonics it after the data has been analyzed by matlab not "on the fly"

Kind regards

Sorry for the double post was not my intention
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
SherpaDoug



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

View user's profile Send private message

PostPosted: Thu Aug 21, 2008 11:41 am     Reply with quote

For sampling rate, you must decide the highest frequency you want to measure and sample more than 2x that frequency. Say the highest harmonic you are interested in is 1500Hz. You should filter the signal to kill all higher harmonics and sample at twice the filter cut-off frequency. If the filter passes 1500 well, 1800 poorly, and 2000Hz not at all, then you should sample at 4000 samples/second.

If you could make a filter that passed 1500 Hz and blocked 1501, then you could sample at 3002, but that filter is impossible to build.

The "filter" in this case includes the bandwidth on the accelerometer. If it starts to roll off at 1600 you can use that to help the anti-alias filter of the A/D.
_________________
The search for better is endless. Instead simply find very good and get the job done.
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

bw of sensor
PostPosted: Thu Aug 21, 2008 12:21 pm     Reply with quote

The frequency response of the accelerometer on goes up till 1500 not 1600 as i said previous ly sorry bout that. So for real world ill be able measure up to 1300 hz "component values and other thing taken into account. But then as you said twice the max f in hz. So about 3000 will do the trick or is my asumption wrong??

Kind regards
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
SherpaDoug



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

View user's profile Send private message

PostPosted: Thu Aug 21, 2008 12:35 pm     Reply with quote

Sampling at 3000 will work as long as the bandwidth really stops at 1500. If there is some signal at 1800 that leaks through the filter it will combine with signal at 1300 (it sort of "reflects" off of the Nyquist frequency of 3000/2 = 1500) and there is no mathematical way to separate the 1300Hz data from the 1800Hz data after it has been digitized.

With care it should not be hard to build a filter that passes 1300Hz well and kills 1800Hz.
_________________
The search for better is endless. Instead simply find very good and get the job done.
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

dspic
PostPosted: Thu Aug 21, 2008 1:19 pm     Reply with quote

Thanks for the advice ill keep all the filtering things im mind when i design

I have a couple of questions, is it overkill to use a dspic for this application of mine solely for the faster speed and higer accurate adc on them. I am thinking about using the MRF24j40MA in my sensing project any comment/advice regarding that chip for wireless communication.

When the data sheet says bandwidth of 1500hz how accurate is that reading in fact is it save to say -+50hz or 100hz. Have you worked with the abovementioned wireless ic?

Kind regards
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
SherpaDoug



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

View user's profile Send private message

PostPosted: Thu Aug 21, 2008 1:52 pm     Reply with quote

If a manufacturer specs a bandwidth of 1500Hz I would interpret that as a Minimum bandwidth. It could be quite a bit higher, but they won't guarantee it. Or it may distort or have resonances above 1500Hz. Being an EE I would trust my own filter, not count on the sensor limiting bandwidth unless the manufacturer specifically said so, or I had tested it and knew the technology well enough to be comfortable.

I have never used the DSPics or the wireless chip, but the software will probably cost more than the hardware for low volume production. So if a few dollars of hardware will save programming time it may be a wise investment.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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