• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A/d Converter issues

Status
Not open for further replies.

tiger_prodigy

New Member
using the pic16877 I have a 4 Mhz cristal and the following codeing which should do this, the in put analog signal is a sin wave at 3 Hz with 2 Vpp. I am puting in a analog signal to pin 2 and trying to output the converted digital value to port D programing it with the PICKIT2. cplease check and respond.

Code:
list p=16F877

#include <p16F877.inc>
;SETUP CONSTANTS
status	equ	0x03
TRISA	EQU	0X85
PROTA	EQU	0X05
TRISB	EQU	0X86
PORTB	EQU	0X06
TRISD	EQU	0X88
PORTD	EQU	0X08
ZERO	EQU	0X02

;ad CONVERSION'S REGISTERS

RCIF	EQU	0X05
TXIF	EQU	0X04
ADCON0	EQU	0X1F
ADOCN1	EQU	0X9F
ADRESH	EQU	0X1E
ADRESL	EQU	0X9E
PIE1	EQU	0X8C
GO		EQU	0X02
ADIE	EQU	0X06
ADIF	EQU	0X06
COUNT1	EQU	0X31
COUNT2	EQU	0X32

ORG	0X00
GOTO MAIN
ORG 0X10



MAIN
		BCF		STATUS, 0X05
		MOVLW	0X09
		MOVWF	RCSTA
		BSF		STATUS, 0X05	;SWITCH TO BANK 1
		MOVLW	0X00
		MOVFW	TRISD
		MOVLW	0XFF
		MOVWF	TRISA
;**************************RS232*****************************
		MOVLW	0X20
		MOVWF	TXSTA
		MOVLW	0X09
		MOVWF	SPBRG
;**************************adc INITIALIZATION****************
		BCF		PIE1,	ADIE	;DISABLE ADC INTERUPT
		BCF		STATUS, 0X05	;SWITCH TO BANK0
		MOVLW	B'11000001'		;INTERNAL RC /OSC/AN0/GO/AD ON
		MOVWF	ADCON0
		BSF		STATUS, 0X05	;SWITCH TO BANK1
		MOVLW 	0X00
		MOVWF	ADCON1			;LEFT JUSTIFICATION
		BSF		STATUS, 0X05
		BCF		PIR1, 	ADIF
ADC1	
		;call 	delay1
		bcf		status, 0x05
		bsf		ADCON0, GO
ADloop
		BTFSC	ADCON0, GO
		GOTO	ADloop
		BCF		PIR1, ADIF
		MOVF	ADRESH, 0
		MOVWF	PORTD
		GOTO	ADC1


delay2	
		BCF		STATUS, 0X05
		MOVLW	0XA4
		MOVWF	COUNT2
R100us	DECFSZ	COUNT2
		GOTO	R100us
		RETURN


delay1	BCF		STATUS, 0X05
		MOVLW	0XFF
		MOVWF	COUNT1
R10ms	CALL	delay2
		DECFSZ	COUNT1
		GOTO	R10ms
		RETURN

END
 
Last edited:

ericgibbs

Well-Known Member
Most Helpful Member
hi tiger,
Had a quick look at your program,get back to you.
 
Last edited:

ericgibbs

Well-Known Member
Most Helpful Member
hi,

Look at this version of your program, it runs OK in simulation.
 

Attachments

rahman_evo7

New Member
c language for pic18f4550

how to write the c language to control the brushless motor (linix brushless motor) ???please any body help me......;-(
1) to setup pwm
2) to setup cw and ccw
3) to setup A/D
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top