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

PIC24 solar tracker - Need your help urgently.

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



Joined: 03 Jun 2012
Posts: 2

View user's profile Send private message

PIC24 solar tracker - Need your help urgently.
PostPosted: Sun Jun 03, 2012 1:01 am     Reply with quote

I use PIC24fj128gb110 to create solar tracker project. First we want to store the value from LDR. We tried to config A/D in CCSC but it didn't work. Analog value didn't show to LCD. and this is the code. Please help me.
Code:

#include <24FJ128GB110.h>
#fuses HS, NOWDT, NOPROTECT, NOJTAG
#device ADC = 10
#use delay(clock=8000000)
#include <LCD_flex.c>

//Button//
#define Start_button PIN_D4
#define Stop_button PIN_D5
//LED//
#define Start_LED PIN_A0
#define Stop_LED PIN_A1
#define Clockwise_direction PIN_A2
#define CounterClockwise_direction PIN_A3
//Analog//
#define LDR1   PIN_B0
#define LDR2   PIN_B1

void main(void)
{
   unsigned int16  LDR1_value;
   unsigned int16  LDR2_value;
   set_tris_a(0x00);
   set_tris_d(0xff);
   while (TRUE)
   {    
      lcd_init();  // Always call this first.
      delay_ms(200);
      if (!input(Start_button))
      {
         output_high(Start_LED);
         lcd_putc("\Solar Tracker\n");
         lcd_putc("\----Start----\n");
         delay_ms(1000);
         setup_adc_ports(sAN2);
         setup_adc(ADC_CLOCK_INTERNAL);
         set_adc_channel(2);
         while(1)
         {
            delay_us(10);
               LDR1_value = Read_ADC();
            delay_ms(100);
            printf(lcd_putc,"\fdata1=%d\n",LDR1_value);
         }
      }
      else if (!input(Stop_button))
      {
         output_high(Stop_LED);
      }
   }
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Jun 03, 2012 8:32 am     Reply with quote

Comments like this are not helpful.
Quote:
We tried to config A/D in CCSC but it didn't work.

What does not work?
What does work?
What do you expect to happen?
How are your LDR's connected?
How are your switches wired?
...........

Read the CCS forum guide.

Mike
Hong_pet16



Joined: 03 Jun 2012
Posts: 2

View user's profile Send private message

PostPosted: Sun Jun 03, 2012 10:45 am     Reply with quote

Thank you, Mike
and I very sorry that I gave you less detail in my question.

I want to get the data from LDR in integer form. First I know that PIC24FJ128GB110 has 10 bit analog, 16 channel. Then I tried to test with potentiometer and see the value change at LCD but It didn't show the correct value and moreover when I increase or decrease by turning potentionmeter, the value was still the same. After that I think it maybe have a problem about config ADC. I tried everything and see the example on your website and it all the same. Please give me some advice. Thank you and hope you will help me find the solution of this problem.

[img]http://upic.me/show/36301400
[/img]
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Jun 03, 2012 1:21 pm     Reply with quote

Quote:
I tried everything and see the example on your website and it all the same. Please give me some advice.
This is NOT my website, it's the CCS user's forum, and you have still not answered my original questions.

If you are having problems setting registers either:-

(1) Study the .h file to work out what can and cannot be done.
(2) Complain to CCS if what you should have, is not in the .h file.
(3) Complain to CCS if what is in the .h file, does not work.
(4) Use the PIC data sheet, and set the registers directly.

Mike

PS. You've now made the thread difficult to follow with your wide image.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Mon Jun 04, 2012 1:54 am     Reply with quote

As well as Mike's comments, there are quite a few others that apply:
1) An LDR, produces a resistance change, not a voltage change. There must therefore be some circuitry to generate a voltage from this (at least a resistor), and for the resistance range involved with most standard LDR's, an amplifier _will_ be needed to meet the analog input impedance requirements of the PIC.
2) Your defines in the header, refer to the LDR's being on B0, and B1, yet in the code you select AN2, which is B2. This pin is used for quite a few other things, and you need to ensure these are 'off' before trying to use it as an analog input. It is the USB -I/O pin, also the B input to comparator 2, and useable as a re-mappable peripheral I/O pin.
3) Have you actually verified your chip is actually running?. A simple toggle an I/O pin type code, doing nothing else, and verify that the pin stays at the specified level for the specified time, to ensure your oscillator is starting, running at the right frequency, and supplies are connected to the right pins. I have doubts about your clock, unless you are running off a 16MHz crystal, since the default bit patterns in the CLKDIV register give division by 2, unless you specify otherwise.

#use delay(crystal=8MHz, clock=8MHz)

Should set them, depending on your compiler version.

Best Wishes
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Jun 04, 2012 7:27 am     Reply with quote

Hi,

Umm, to the OP, it's probably also not a good idea to use (not commonly recognized) acronyms like 'LDR' if you are looking for the widest possible input from forum members.

When I read that, I wondered what your Long Distance Relationship had to do with CCS 'C' programming......??? Laughing

John
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