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

Can not get the ADC on pic 16f676 to work...

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








Can not get the ADC on pic 16f676 to work...
PostPosted: Wed Mar 03, 2004 9:13 am     Reply with quote

I�m having trouble to get the ACD on pic16f676 to work. The code is supposed to generate an output if a value between two measurements is positive.

The code is:

#include <16F676.h>
#device adc=8
#use delay(clock=4000000)
#fuses HS, NOWDT, BROWNOUT, PUT

main()
{
setup_adc_ports(sAN4|sAN5|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
While(TRUE)
{
set_adc_channel(0);
voltage1=read_adc(); //Read voltage nr. 1
delay_ms(1000);
voltage2=read_adc(); //Read voltage nr. 2
deltavoltage=( (voltage2-voltage1) & mask );
if( deltavoltage>0 ) //If voltage slope positive
{output_high(PIN_C5);}

else //If voltage slope zero or negative
{output_low(PIN_C5);}
}
}

I don�t think there is any obvious mistake in the code. It works on pic16f877a.
Since the conversion from pic to pic is rather simple in CCS, or it seems to be, so I thought it would work on the other pic as well (with some small changes for outputs, and adc setup).

Any help is appreciated.
Ttelmah
Guest







Re: Can not get the ADC on pic 16f676 to work...
PostPosted: Wed Mar 03, 2004 9:30 am     Reply with quote

Anonymous wrote:
I�m having trouble to get the ACD on pic16f676 to work. The code is supposed to generate an output if a value between two measurements is positive.

The code is:

#include <16F676.h>
#device adc=8
#use delay(clock=4000000)
#fuses HS, NOWDT, BROWNOUT, PUT

main()
{
setup_adc_ports(sAN4|sAN5|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
While(TRUE)
{
set_adc_channel(0);
voltage1=read_adc(); //Read voltage nr. 1
delay_ms(1000);
voltage2=read_adc(); //Read voltage nr. 2
deltavoltage=( (voltage2-voltage1) & mask );
if( deltavoltage>0 ) //If voltage slope positive
{output_high(PIN_C5);}

else //If voltage slope zero or negative
{output_low(PIN_C5);}
}
}

I don�t think there is any obvious mistake in the code. It works on pic16f877a.
Since the conversion from pic to pic is rather simple in CCS, or it seems to be, so I thought it would work on the other pic as well (with some small changes for outputs, and adc setup).

Any help is appreciated.

The 676, has comparators as well as the ADC. These may need to be turned off (SETUP_COMPARATORS(NC_NC_NC_NC)).
There is a slight fault in the code, in that you should wait for about 10uSec (depending on the analog source impedance), between selecting the adc channel, and taking the reading. This won't matter on latter loops since the channel doesn't change, but will result in an incorrect result on the first pass. Personally, I'd simple put the set_adc_channel outside the loop, wait for a moment, then start the loop.

Best Wishes
Guest








Using Pic16F676 wrting in C, which compiler are using
PostPosted: Thu Oct 29, 2009 8:49 pm     Reply with quote

Hi All

I'm having the same trouble with the ADC.

I noticed that your pragmas are not compiling.
Code:
SETUP_COMPARATORS(NC_NC_NC_NC);

The FUSE settings are not found.
I am using HTC which is going to expire soon.

So I have two questions. Which include file are you using to get these pragmas/functions.

Second is there a free C compiler that I can use.

Thanks a lot.
Ttelmah
Guest







PostPosted: Fri Oct 30, 2009 9:15 am     Reply with quote

The defines (not pragmas), are part of the processor include file for the CCS compiler, which is what this forum is for...
You say you are using 'HTC'. This sounds like possibly the HiTech C. If so, you are in the wrong forum.

Best Wishes
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

Re: Can not get the ADC on pic 16f676 to work...
PostPosted: Fri Oct 30, 2009 9:31 am     Reply with quote

Anonymous wrote:
I�m having trouble to get the ACD on pic16f676 to work. The code is supposed to generate an output if a value between two measurements is positive.

The code is:

#include <16F676.h>
#device adc=8
#use delay(clock=4000000)
#fuses HS, NOWDT, BROWNOUT, PUT

main()
{
setup_adc_ports(sAN4|sAN5|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
While(TRUE)
{
set_adc_channel(0);
voltage1=read_adc(); //Read voltage nr. 1
delay_ms(1000);
voltage2=read_adc(); //Read voltage nr. 2
deltavoltage=( (voltage2-voltage1) & mask );
if( deltavoltage>0 ) //If voltage slope positive
{output_high(PIN_C5);}

else //If voltage slope zero or negative
{output_low(PIN_C5);}
}
}

I don�t think there is any obvious mistake in the code. It works on pic16f877a.
Since the conversion from pic to pic is rather simple in CCS, or it seems to be, so I thought it would work on the other pic as well (with some small changes for outputs, and adc setup).

Any help is appreciated.


There is a big fault in your code.
voltage1, voltage2, deltavoltage and mask are not defined.

I expect your problem lies with the equation.
If voltage1 and voltage2 are unsigned (which is the default for CCS) then your result will never be negative. You will need to cast to signed:-

Code:

int16 voltage1, voltage2; // I presume!, both are unsigned
signed int16 deltavoltage; // I presume!
int16 mask; // ? This is very important as to what it is set to.

deltavoltage=( ((signed int32)voltage2-voltage1) & mask );
[email protected]
Guest







How to use the CCS compiler
PostPosted: Sat Oct 31, 2009 4:03 pm     Reply with quote

Can anyopne direct me to how to use the CCS compiler?

Where are the FAQS and how to docs?

Thanks
dyeatman



Joined: 06 Sep 2003
Posts: 1935
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Oct 31, 2009 4:08 pm     Reply with quote

The code library is here:
http://www.ccsinfo.com/forum/viewforum.php?f=2

The CCS Documentation is here:
http://www.ccsinfo.com/downloads.php

The FAQ is here:
http://www.ccsinfo.com/faq.php

All the CCS examples are in the PICC\Examples directory on your hard drive. More info and a listing of the examples is here:
http://www.ccsinfo.com/content.php?page=compexamples
_________________
Google and Forum Search are some of your best tools!!!!
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