View previous topic :: View next topic |
Author |
Message |
tom_hanks
Joined: 04 Apr 2007 Posts: 20
|
how to hold the higher value in PIC |
Posted: Wed Jul 18, 2007 5:49 am |
|
|
PIC is sampling at 20 KSPS a ADC signal (i.e volage i/p) in continous mode.
In every 200ms cycle, PIC is storing the maximum value and passing it on I2C bus.
but sometime PIC is not able to capture a peak of Analog voltage i/p succesfully.
i am using a simple compare method of the read value with store value.
Can you suggest some sophisticative method to store the maximum value in every 200ms.
Example:
Code: |
if ( AD.values.present.words[0] > AD.values.maximum[0])
// if the A-D value is bigger than the current maximum value
{AD.values.maximum[0] = AD.values.present.words[0];}
|
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Jul 18, 2007 8:50 am |
|
|
That looks pretty foolproof to me. If you are really stuck you should look at the list file and see what the compiler is telling the PIC to do. Maybe you can spot an error.
It may help if you tell us your compiler version. Someone may know of a bug. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
tom_hanks
Joined: 04 Apr 2007 Posts: 20
|
|
Posted: Wed Jul 18, 2007 9:02 am |
|
|
thank you for reply..
can u suggest some other method..
.................
this is the list version
MPLAB 7.40.00.00 Certified
ICDDB 7.30.00.00 n\a
MasterDB 2.22.60.00 n\a
PCMDB2k 2.22.01.04 n\a
PMFDB4k 2.22.02.00 n\a
DLLInfoRec 8.62.01.0 Certified
DMCI 1.0.5.0 Certified
FieldOrientedControlTI1.00.08.00 Certified
ICD2 7.31.9.0 Certified
MemGauge 1.00.00.00 Certified
MotorControl 1.00.02.00 Certified
MP4KE18E 2.40.00.00 Certified
MP4KE18X 2.40.00.00 Certified
Mp4keDSC 2.40.00.00 Certified
MPChecksum 2.22.02.00 Certified
MPDebugger 2.01.00.00 Certified
MPDevice 2.00.07.00 Certified
MPDisplays 2.40.00.00 Certified
MPE12xxx 4.40.00.00 Certified
MPE16xxx 4.40.00.00 Certified
MPE17XXX 4.40.00.00 Certified
MPE18EXX 4.40.00.00 Certified
MPE18HC3 4.40.00.00 Certified
MPE18XXX 4.40.00.00 Certified
MPEditor4 3.40.00.00 Certified
MPForum 2.40.00.00 Certified
MPI2KVerify 1.0.0.153 Certified
MPIce2K 4.40.00.00 Certified
MPICE4K 2.40.00.00 Certified
MPIceState 1.22.00.00 Certified
MPIceStopwatch 1.22.00.00 Certified
MPLAB SIM12 1.40.00.01 Certified
MPLAB SIM16 1.40.00.02 Certified
MPLAB SIM18 2.40.00.01 Certified
MPLAB SIM30 3.40.00.02 Certified
MPLoader 2.22.00.00 Certified
MPLogicDisplay 1.31.08.00 Certified
MPMemory 2.2 Certified
MPPm3 2.30.3.0 Certified
MPProgram 2.01.00.000 Certified
MPProject 2.40.00.00 Certified
MPPromate2 7.30.0.0 Certified
MPRecorder 1.01.00.00 Certified
MPSim 8.62.01.0 Certified
MPSimulator 1.20.00.0 Certified
MPStimCtrl 3.22.00.00 Certified
MPStimulus 2.52.00.00 Certified
MPStopwatch 2.1.00.0 Certified
MPTags 1.02.00.00 Certified
MPTask 1.1.1.0 Certified
MPTranslator 2.31.00.00 Certified
PICkit 1 2.0.0.3 Certified
PICkit2 0.0.0.12 Certified
Picstart 4.40.0.0 Certified
RTOSTool 1.0 Certified
SCLBuilder 3.22.00.00 Certified
Suite_dsPIC 2.1.3.0 Certified
Suite_LSCProxy 2.1.0.1 Certified
Suite_Microchip 2.1.5.0 Certified
Vault_CVS 1.2.0.0 Certified
Vault_PVCS 1.0.0.3 Certified
Vault_VSS 1.4.0.2 Certified |
|
|
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Wed Jul 18, 2007 11:30 am |
|
|
Hi
Assuming your not dropping samples (your code is always waiting for the conversion to finish) then your code will return the peak value that the converter saw. But this may not be the actual peak voltage if you have not band limited the signal (low pass filtered).
Another way is to have an analogue peak detector, and read and reset that at regular intervals.
HTH |
|
|
|