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

[solved] A/D program returns just 0

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



Joined: 20 Aug 2014
Posts: 3

View user's profile Send private message

[solved] A/D program returns just 0
PostPosted: Wed Aug 20, 2014 10:33 am     Reply with quote

Hi Folks,

I'm quite new to PICs and currently working on a dsPIC30F6015. I got the CAN device and other stuff working but the A/D gives me issues. My program just returns 0 regardless of the used analog input, so I saw a very basic program in this forum with A/D and tried it, but returns 0 nonetheless.
The used compiler is the CCS Compiler.

On AN0 a constant 5V is applied, but the program shows still 0 if switched to AN0
On AN8 a signal between 0-5V is applied, still zero.


I'm thankful for any thoughts that might help Smile

Code:
#include <30F6015.H>
#include <stdint.h>
#device ADC=10
#case
#fuses HS2_PLL16,NOPROTECT,NOWDT,PUT16
#define CLOCK_FREQ 80000000
#use delay(clock=CLOCK_FREQ)
#use rs232(baud=115200,xmit=PIN_F3,rcv=PIN_F2, BRGH1OK)



void main()
{
   int16 r;
   setup_adc_ports(sAN8);     
   setup_adc(ADC_CLOCK_DIV_16);       
   set_adc_channel(0);   
   
   while(TRUE)
   {
      r =read_adc();         
      printf("AD value is  %4LD \r\n", r);
      delay_ms(1000);   
   }
}


Last edited by Hakk on Thu Aug 21, 2014 1:43 am; edited 1 time in total
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Wed Aug 20, 2014 10:35 am     Reply with quote

sAN8 would be channel 8 not 0 as in your set_adc_channel(8)
Hakk



Joined: 20 Aug 2014
Posts: 3

View user's profile Send private message

PostPosted: Wed Aug 20, 2014 10:51 am     Reply with quote

Sure? The datasheet suggests that there are only 4 channels and AN8 is connected to 0 and 3.
And in your case it should have worked when I applied sAN0 with channel 0
Ttelmah



Joined: 11 Mar 2010
Posts: 19341

View user's profile Send private message

PostPosted: Wed Aug 20, 2014 12:02 pm     Reply with quote

You are misunderstanding.

The 'setup_adc_ports' command, sets what pins are physically connected to the internal ADC multiplexer. There are a total of 32 different inputs that can be connected here.
The set_adc_channel then selects which of these is connected to the internal ADC channels.
Alan is correct sAN8, is adc_channel 8 at the multiplexer.
This is connected to pin B8.

Then internally the ADC has four sample and hold channels, that are used to do overlapped sampling (this is not used for the simple setup).

It should work with sAN0, and channel 0, but only when feeding B0, or sAN8, and channel 8, on B8.
Hakk



Joined: 20 Aug 2014
Posts: 3

View user's profile Send private message

PostPosted: Thu Aug 21, 2014 1:42 am     Reply with quote

Thanks a lot guys for your help Smile
Sry alan that I thought you were mistaken.

I was really confused by the 4 internal channels :D
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