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

Help with ADC

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



Joined: 23 Jul 2013
Posts: 8

View user's profile Send private message

Help with ADC
PostPosted: Mon Sep 09, 2013 8:36 am     Reply with quote

Hello

I'm trying to work with the ADC now but I have some problems.
I want that a LED lights if the value is under half. But the LED lights allways. So I hope that someone can help me.

I use the dsPIC33FJ256MC710A, the PCD compiler from CCS and the dsPICDEM MCLV development boar.
Code:

#include <33FJ256MC710A.h>
#include <stdio.h>
#include <stdlib.h>

#fuses XT,NOWDT
#use delay(clock=8000000)

#define LED PIN_E1

void main()
{
    int x;

    set_tris_e(0);      //LED output
    set_tris_b(1);      //input
    setup_adc_ports(sAN8);
    setup_adc(ADC_CLOCK_INTERNAL);
    set_adc_channel(0);
    delay_ms(10);

    while(1)
    {
        x=read_adc();
        if(x<511)
        {
            output_high(LED);
        }
        else
        {
            output_low(LED);
        }
        delay_ms(500);
    }
}
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Sep 09, 2013 8:52 am     Reply with quote

two comments
1) normally you don't use adc_clock_internal, check the datashet for when you should...

2) what's the resolution of the ADC ? Normally you have to specify how many bits( 8, 10, 12 depending on the PIC type)

also confirm that your ADC source is 'active' and not 'stuck' either high or low.

hmm..
setup_adc_ports(sAN8);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);


you've setup AN8 but select channel 0 .....

again , check the datasheet, but that just looks wrong...
I'd think set_adc_channel(8); might be right...

hth
jay
Martin_P



Joined: 23 Jul 2013
Posts: 8

View user's profile Send private message

PostPosted: Mon Sep 09, 2013 9:00 am     Reply with quote

thank you
that was the mistake
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