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.

How to code ADC to PIC18f4550??

Status
Not open for further replies.

SkyLeFt

Newbie level 3
Newbie level 3
Joined
Nov 21, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,316
I am now doing my project which is pc-based oscilloscope..
but i am facing an ADC problem in my project..
someone can kindly teach me??
 

yeah it's called Google do a search yourself and you will find. Were not here to do your work for you.
what have you done yourself ?
 

yeah it's called Google do a search yourself and you will find. Were not here to do your work for you.
what have you done yourself ?

so we better close this EDABOARD FORUM..

skyleft:

can you specific with your problem..i mean a problem with code or anything else?
 

so we better close this EDABOARD FORUM..

skyleft:

can you specific with your problem..i mean a problem with code or anything else?
I did not state we need to closse EDA, All that I stated was we are not here do to do the work for him. He has given us so little information to go on and work he has already worked on where is he stuck, he has given us nothing to work on.
Like what language is he using,
We have it here so many times of first time posters I want want PLZ send.

Skyleft
Good luck with your project
 

Hi,
First of all, download the 18F4550 datasheet -> ww1.microchip.com/downloads/en/DeviceDoc/39632b.pdf
Go to section 21 ADC, page 261. Read the section thoroughly.
Read this: **broken link removed**
If you are still unsure search for the PIC18 Reference Manual (I can't seem to find it now) and read ADC section.
I am sure after this, you'll have enough knowledge to go on to program the ADC of the PIC.
Then, start coding, then we'll help you when you need further help or if you are stuck somewhere.

Hope this helps.
Tahmid.
 

i have some problem with my ADC program..
because i need to use ETS to accumulate the data..below is my program..take a look..
volatile int adc_count;

/* assumes you can't use DMA to drive the ADC */
void adc_interrupt(void)
{
store_value();

if(--adc_count) {
start_adc();
}
}

do {
int offset;
offset = 0; /* offset from trigger to first ADC sample */

do {
adc_count = 256; /* arbitrary, how many samples per trigger */

load_timer(offset); /* set timer value */
arm_timer(); /* timer will now start when the trigger occurs */
} while(adc_count);

offset += 10; /* arbitrary, how much to "move over" each trigger */
} while(offset < 100); /* arbitrary, how many triggers to use for an ETS capture */
 

Who are you to decide what should be done?

i dont mean to decide that..what i really mean is, if we are here going to tell someone to google himself, i think this forum is not important to exist..
i am also join this group to help and request for help.. if someone not state their problem really well, just tell them to be more specific..
dont treat people like he is really stupid..myb he is not really familiar yet with forum environment.. and this is his first post..if he find out the first answer is "find it yourself at google" myb he will said "what stupid forum is this".. did u get what i mean???
 

void main()
{
unsigned long Vin, mV;
unsigned char op[12];
unsigned char i,j,lcd[5];
TRISC = 0; // PORTC are outputs (LCD)
TRISA = 0xFF; // PORTA is input
//
// Configure LCD
//
Lcd_Init(&PORTC); // LCD is connected to PORTC
Lcd_Cmd(LCD_CLEAR);
Lcd_Out(1,1,"VOLTMETER");
Delay_ms(2000);
//

// Configure A/D converter. AN0 is used in this project
//
ADCON1 = 0x80; // Use AN0 and Vref=+5V
//
// Program loop
//
for(;;) // Endless loop
{
Lcd_Cmd(LCD_CLEAR);
Vin = Adc_Read(0); // Read from channel 0 (AN0)
Lcd_Out(1,1,"mV = "); // Display "mV = "
mV = (Vin * 5000) >> 10; // mv = Vin x 5000 / 1024
LongToStr(mV,op); // Convert to string in "op"
//
// Remove leading blanks
//
j=0;
for(i=0;i<=11;i++)
{
if(op != ' ') // If a blank
{
lcd[j]=op;
j++;
}
}
//
// Display result on LCD
//
Lcd_Out(1,6,lcd); // Output to LCD
Delay_ms(1000); // Wait 1 second
}
}
 

is it a tutorial only??
because i need to use this ADC coding and send to LAbview..
because i am doing pc-based oscilloscope..

---------- Post added at 22:04 ---------- Previous post was at 22:03 ----------

is it a tutorial only??
because i need to use this ADC coding and send to LAbview..
because i am doing pc-based oscilloscope..
void main()
{
unsigned long Vin, mV;
unsigned char op[12];
unsigned char i,j,lcd[5];
TRISC = 0; // PORTC are outputs (LCD)
TRISA = 0xFF; // PORTA is input
//
// Configure LCD
//
Lcd_Init(&PORTC); // LCD is connected to PORTC
Lcd_Cmd(LCD_CLEAR);
Lcd_Out(1,1,"VOLTMETER");
Delay_ms(2000);
//

// Configure A/D converter. AN0 is used in this project
//
ADCON1 = 0x80; // Use AN0 and Vref=+5V
//
// Program loop
//
for(;;) // Endless loop
{
Lcd_Cmd(LCD_CLEAR);
Vin = Adc_Read(0); // Read from channel 0 (AN0)
Lcd_Out(1,1,"mV = "); // Display "mV = "
mV = (Vin * 5000) >> 10; // mv = Vin x 5000 / 1024
LongToStr(mV,op); // Convert to string in "op"
//
// Remove leading blanks
//
j=0;
for(i=0;i<=11;i++)
{
if(op != ' ') // If a blank
{
lcd[j]=op;
j++;
}
}
//
// Display result on LCD
//
Lcd_Out(1,6,lcd); // Output to LCD
Delay_ms(1000); // Wait 1 second
}
}
 

i use PIC 18f4550, i want use adc pic 18f4550 to be active, i work with MPlab
. :sad:
I'm confused friends.please give me the code with MPlab!
 

Hi,
Have you gone through the datasheet and reference manual(DS39500A)? Please go through the ADC sections in those and you will be clear regarding their operation.
You can get started with this code:

Code:
;PROGRAM WRITTEN BY SYED TAHMID MAHBUB
;DATED - 29 DECEMBER 2010
;PROGRAMMING LANGUAGE - ASSEMBLER
;COMPILER - MPASM
;IDE - MPLAB v8.30

	LIST P=18F4550
	#INCLUDE "P18F4550.INC"
	
	__CONFIG _CONFIG1H, _FOSC_XT_XT_1H
	__CONFIG _CONFIG2L, _BOR_OFF_2L & _PWRT_OFF_2L
	__CONFIG _CONFIG2H, _WDT_OFF_2H
	__CONFIG _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L
	__CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
	__CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
	__CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
	__CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
	__CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
	__CONFIG _CONFIG7H, _EBTRB_OFF_7H

	ORG 0					;RESET VECTOR
	GOTO MAIN				;START EXECUTING FROM MAIN
	
	CBLOCK					;GENERAL PURPOSE REGISTERS
		D1
	ENDC					;END DECLARATION BLOCK

DELAY						;ACQUISITION DELAY
	MOVLW	30
	MOVWF	D1
	DECFSZ	D1
	BRA		$-1
	RETURN					;RETURN FROM SUBROUTINE

MAIN
	BSF		TRISA,1 		;RA0 INPUT
	CLRF	TRISB			;PORTB OUTPUT
	CLRF	PORTB			;CLEAR INITIAL PORTB STATE
	MOVLW	0x3E			;8-BIT, 20TAD, FOSC/64
	MOVWF	ADCON2			;LOADED INTO ADCON2
	MOVLW	0x0E			;VDD AND VSS REFERENCE, CH0 ANALOG, REST DIGITAL
	MOVWF	ADCON1			;LOADED INTO ADCON1
	CLRF	ADCON0			;CH0, ADC OFF
	BSF		ADCON0,ADON		;ADON = 1, ADC RUNNING
LOOP
	RCALL	DELAY			;CALL ACQUISITION DELAY
	BSF		ADCON0,GO_DONE	;START CONVERSION
	BTFSC	ADCON0,GO_DONE	;CHECK IF GO_DONE = 0, IE, CONVERSION COMPLETE
	BRA		$-1				;IF NOT CHECK AGAIN
	MOVFF	ADRESH, LATB	;WHEN COMPLETE, LOAD CONTENTS OF LATB (PORTB) WITH ADC RESULT
	BRA		LOOP			;REPEAT CONVERSION
END

But you need to go through the datasheet and reference manual as mentioned to understand what is going on.

Hope this helps.
Tahmid.
 

thanks :grin:

---------- Post added at 23:32 ---------- Previous post was at 23:13 ----------

I have a project to make an animation that is controlled by PIC
I use C # for animation
pic in use as the hardware that controls
communication I use is USB
my usb program has been completed
but I need an adc to control the speed of my animation
I also use MPLAB for PIC
to download pic 18f4550 I use PICprogramer
 

Hope the provided code helps. But you won't be able to put it to use, unless you understand how to make use of ADC.

Tahmid.
 
  • Like
Reactions: waroko

    waroko

    Points: 2
    Helpful Answer Positive Rating
i just explain my project
thanks tahmid
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top