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 CCS Technical Support

How do I Log the lowest adc value and display it

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



Joined: 01 Jun 2005
Posts: 45
Location: UK

View user's profile Send private message

How do I Log the lowest adc value and display it
PostPosted: Mon Jan 11, 2010 12:46 pm     Reply with quote

Hi guys

I would like to log the lowest adc value and display on a set of leds.

I have coded what looks like an led bar the circuit and the code that I have done takes a voltage into the adc and then displays it on the bar of leds.

I would like to get one of the leds to flash at the lowest value that the adc sees.

Can anyone help with this part of my code or give me a hint.

Many thanks

Pete
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 11, 2010 6:38 pm     Reply with quote

To save the lowest value, you just do a simple test. Compare the
current value to the previous lowest value. If the current value
is lower, then it becomes the new "lowest" value.

The program below shows one way to do it. Once you get a low value,
you will never get anything higher than that as the output. Once you
turn the trimpot down to 0, this program will keep displaying 0, no matter
what you turn the trimpot to later. I'm not sure if that's what you want.
At least this code will give you some ideas.
Code:

#include <16F877.H>
#device adc=8
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//======================================
void main()
{
int8 current, lowest;

setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(20);


lowest = 0xFF;

while(1)
  {
   current = read_adc();
 
   if(current < lowest)
      lowest = current;

   printf("Lowest = %x \n\r", lowest);

   delay_ms(500);
  }

}
pdl



Joined: 01 Jun 2005
Posts: 45
Location: UK

View user's profile Send private message

PostPosted: Mon Jan 11, 2010 7:33 pm     Reply with quote

Hi PCM programmer

Thanks for the help. I now have some idea of how to do it. I just could not get my head around it.

I am slowly get the hang of C. Every program I try to write I learn something new.

Thanks PCM you have been helpful every time I have asked for help.

Pete
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