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

PIC18F4520 Development Kit Comment & Question Exercise 7

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



Joined: 11 Feb 2007
Posts: 5
Location: Santa Clara University

View user's profile Send private message

PIC18F4520 Development Kit Comment & Question Exercise 7
PostPosted: Sun Feb 11, 2007 6:23 pm     Reply with quote

First of all, I just bought the development kit with the student discount and am really enjoying it. I'm working through the exercise book, and am have a few troubles with example 7.
The example reads a POT on A0 and looks like this:
Code:
#include <prototype.h>
#include <utility.c>

#define cutoff 128      //2.5 volts
#define neutral_zone 25 // .5 Volts

void main() {
   int reading;
   
   setup_adc_ports( RAO_ANALOG );
   setup_adc( ADC_CLOCK_INTERNAL);
   set_adc_channel( 0 );

   while(true) {
      reading = read_adc();
      if(reading<cutoff>(cutoff+neutral_zone/2))
         light_one_led(RED);
      else
         light_one_led(YELLOW);
   }
}

I believe that RA0_ANALOG is an error because it is not defined in the H file, after doing some digging, replacing RA0_ANALOG with AN0 makes the program work correctly (FUN!), I thought I should let you know for the next printing.

Here is my real question:
Also with the Further Study in Exercise 7 part A, it suggests adding ADC=16 to the #device ICD=TRUE line. "this will change the range to 0-1023".
I did that, but the range is definitely not 0-1023. Putting a watch on the reading variable, I get various values with the POT between 0-192. I am guessing this is because the reading variable is a INT (maximum 255, right?), so I change int reading; to long reading;, but then I get values between 128-38976.

Can someone help me with this?

Thanks,
Todd
The_Todd



Joined: 11 Feb 2007
Posts: 5
Location: Santa Clara University

View user's profile Send private message

PostPosted: Sun Feb 11, 2007 7:05 pm     Reply with quote

So with a little more digging i've found that the answer to my question is that there is another error in exercise 7. Anyways, it should suggest adding ADC=12, as this will return a range of 0-1023, while ADC=16 will return 0-65472. It should also suggest changing reading to a long.

CCS was having some trouble "stepping over" reading = read_adc(), but "run to cursor" to the next line returned good values.

Todd
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

PostPosted: Sun Feb 11, 2007 7:33 pm     Reply with quote

you have to ask yourself, are the question deliberately incorrect so you have to debug/find the fault to make it work.

forces you to understand the answer over parrot fashion learning.

I have always learn't more by mistakes than getting it right 1st time.

Andrew
_________________
What has been learnt if you make the same mistake? Wink
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Sun Feb 11, 2007 7:36 pm     Reply with quote

Storic wrote:
I have always learn't more by mistakes than getting it right 1st time.

Andrew


Amen.
dyeatman



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

View user's profile Send private message

PostPosted: Sun Feb 11, 2007 8:24 pm     Reply with quote

The_Todd,
Thanks for the info for those here who might benefit. It sounds like you are coming along nicely!

However, as you might have noticed at the top of the web page, it says CCS doesn't monitor this page and to send bug reports to support@ccsinfo.com

I think they might appreciate the feedback on the kit....

Hang in there and, as you said earlier, have fun!!!
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