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

ADC and Seven segment

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



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

ADC and Seven segment
PostPosted: Tue Aug 31, 2010 2:03 am     Reply with quote

Hi,

I'm trying to display ADC value using Pot of 1K on 3 seven segments.
I'm getting values which are recurring like 222 or 555, 000 etc.
I am not able to troubleshoot the exact problem.
My code is as follows.

Code:

#include <16f877a.h>
#device ICD=TRUE ADC=8
#fuses HS,NOLVP,NOWDT
#use delay (clock=40000000)
#use rs232 (baud= 9600,xmit = PIN_C6)

const char TABLE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0X82,0XF8,0X80,0X98};
 
void display(int x)         
   {
     int  i,j,k,temp;   //define four temporary variable
     temp=x;                 //temporary keep AD convert result
     i=temp/0x64;         //get display hundred bit
     j=(temp%0x64)/0xa;    //get display ten bit
     k=(temp%0x64)%0xa;     //get display Entries bit
     output_d(TABLE[i]);   //get the display hundred bit code from table
     output_low(PIN_A3);
     delay_ms(10);                //delay some time,ensure display brightness
     output_d(TABLE[j]);       //get the display ten bit code from table
     output_low(PIN_A4);             //RA4 OUTPUT low,light ten bit display
     delay_ms(10);                //delay some time,ensure display brightness
     output_d(TABLE[k]);        //get the display Entries bit code from table
     output_low(PIN_A5);             //RA5 OUTPUT low,light Entries bit display
     delay_ms(10);                //delay some time,ensure display brightness
   }
void main ()
{

 long int z; 
 setup_adc_ports(AN0);
 setup_adc(ADC_CLOCK_INTERNAL);


while(1)
{
   OUTPUT_LOW(PIN_c0);
  set_adc_channel( 0 );

   z = read_adc();
   display(z);
   output_high(PIN_C0);
   delay_ms(50);
   
}
}


Please let me know where i'm going wrong.
Thanks in advance.[/code]
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Aug 31, 2010 3:56 am     Reply with quote

I assume you are latching the output for your 7 seg displays :-

Code:

     output_d(TABLE[i]);   //get the display hundred bit code from table
     output_low(PIN_A3);
     delay_ms(10);                //delay some time,ensure display brightness
     output_d(TABLE[j]);       //get the display ten bit code from table
     output_low(PIN_A4);             //RA4 OUTPUT low,light ten bit display
     delay_ms(10);                //delay some time,ensure display brightness
     output_d(TABLE[k]);        //get the display Entries bit code from table
     output_low(PIN_A5);             //RA5 OUTPUT low,light Entries bit display
     delay_ms(10);                //delay some time,ensure display brightness


using PIN_A3, PIN_A4 and PIN_A5, should you be taking these high then low to latch after you have set the output ?
once set low they curently remain low!
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Tue Aug 31, 2010 6:31 am     Reply with quote

thanks for your input but now that i have tried the high-low logic. the values are not constant.

like the segments switch on and off....i know its quite embarrassing Embarassed but the segment displays the value and switches off.

i'm want to keep the values constant unless there is any change in the ADC input. Sad

how do i do that..i tired playing with the delay logic but its not helping much.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Aug 31, 2010 8:19 am     Reply with quote

I think we need a little more info on your hardware. I am starting to think that you need to constantly update your display as there is no persistance, no latch for each display.

Pins A3, A4 and A5 look like they switch each one on and off either by directly providing power or via a transistor or fet.

If this is the case then you will need a routine to update each display inturn which you will call constantly in your main loop or preferably via an interrupt. You will then need to write your code so you get a decent refresh rate whilst maintaining a suitable brightness.

we need some hardware info.

Have fun Smile

*edit*
I have just realised that this is the case.

You just need to place your lines in the correct place :-

Code:

     output_d(TABLE[i]);   //get the display hundred bit code from table
     output_low(PIN_A3);
     delay_ms(10);                //delay some time,ensure display brightness
     output_high(PIN_A3);
     output_d(TABLE[j]);       //get the display ten bit code from table
     output_low(PIN_A4);             //RA4 OUTPUT low,light ten bit display
     delay_ms(10);                //delay some time,ensure display brightness
     output_high(PIN_A4);
     output_d(TABLE[k]);        //get the display Entries bit code from table
     output_low(PIN_A5);             //RA5 OUTPUT low,light Entries bit display
     delay_ms(10);                //delay some time,ensure display brightness
     output_high(PIN_A5);
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Aug 31, 2010 9:15 am     Reply with quote

I read your code at a glance:

1) #use delay (clock=40000000) 40Mhz
The maximum Operating Speed in a PIC16F877a is 20Mhz

2) #device ICD=TRUE ADC=8
The resulting AD conversion is stored in a 8 bit variable, you a using:
long int z; and displaying its value.

Humberto
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Tue Aug 31, 2010 11:36 pm     Reply with quote

Hi,
Thank you all for your reply.

Well I'm using transistor for switching on the segments. I guess I would I have to write the routine for the same.

However, I'm not sure how to begin, and also can anyone tell me if there are other ways of latching the segments? I read about the decoder but I'm not sure if I would be able to work with it.
Please do reply with your suggestions.

Sad
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Sep 01, 2010 1:53 am     Reply with quote

Did you read my post and try the code ?
Notice the location on the output_high instructions, AFTER the delay!

What this code now does is:-

Set the output for the first 7 seg display
Turn the first display on
Wait 10 ms (this gives it enough time to go to full brightness)
Turn the first display off.
Repeat this for each display.

Assuming this routine gets called freaquently enough there should be enough persistance in the leds to keep it lit for long enough until you re-enable it. The longer your code takes to call the routine again the more chance there will be flicker.

I would also use a #define for the delay values so you can trim the timing to get the best results. If possible, reduce the delays!

Using 3 x 8 bit latches, one for each display would mean you don't need to keep refreshing the output. Use the A3, A4 and A5 pins to latch the output for each latch (code similar to what I posted but the delays may be reduced). Requires more hardware but you don't need to worry about refresh rates or flicker.
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Wed Sep 01, 2010 3:55 am     Reply with quote

Thanks Wayne...

I tried decreasing the delay and its working perfectly fine.
Feels so good :D
Thanks alot!!!
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Tue Sep 07, 2010 6:47 am     Reply with quote

Ok, now when I try with different voltages, i.e with .18v to .94v I get values which are moving extremely fast.
The values are not constant. It was working fine with pot of 1K. :(

thanks
sid
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