Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Multichannel ADC problem!!!

Status
Not open for further replies.

bing2005

Junior Member level 2
Joined
Feb 21, 2005
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,486
How to select multiple channel by using PIC microcontroller?
Everytimes, i try with more than 1 channel, the output will always jump around.
I used PICC to write the source code. Please help me.
Thank you, guys.

The following source code is 2 channels adc:

Code:
#include <pic.h>
#include "delay.c"
#include "delay.h"

void init_adc(void);
void select1(void);
void select2(void);
void output1(void);
void output2(void);

unsigned int result, result1, temp, temp1;

void config(void)
{
	TRISA = 0x2f;
	TRISB = 0x00;
	PORTA = 0x00;
	PORTB = 0x00;
}

void main(void)
{
	config();
	init_adc();
	while(1)
	{
		select1();
		temp = 0x00;
		DelayUs(10);
		
		select2();
		temp1 = 0x00; 
		DelayUs(10);
	}
}

void init_adc(void)
{
	ADCON1 = 0x80;
}
void select1(void)
{
	ADCON0 = 0x01;
	DelayUs(20);
	ADGO   = 1;
	while(ADGO);
	result = ((ADRESH << 8) + ADRESL) & 0x03FF;
	temp = result;
	if(result>=925 && result<=930)
	{
		output1();
	}	
}

void select2(void)
{
	ADCON0 = 0x09;
	DelayUs(20);
	ADGO   = 1;
	while(ADGO);
	result1 = ((ADRESH << 8) + ADRESL) & 0x03FF;
	temp1 = result1;
	if(result1>=925 && result1<=930)
	{
		output2();
	}
}

void output1(void)
{
	RB7 = 1;
}

void output2(void)
{
	RB6 = 1;
}
[/code]
 

You did not specify which PIC at which clockfrequency you are using.

What is inside deley.c and delay.h ?

best regards
 

I used PIC16f877a for this source code.
The clock frequency used is 4MHz.
delay.h and delay.c is program that used to delay time.
Thanks.
 

OK try using other values for ADCON0 as the A/D clock source should be switched to 8 Tosc between 2.5 and 5 MHz clock frequency

So you new values for ADCON0 would be 0x41 and 0x49.

hope this helps and best regards
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top