Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 15th January 2008, 09:31 PM   (permalink)
Default PIC12F675 ADC Circuit help.

Hi, I have revisited a simple ADC project using 12f675. I've set GPIO,0 as analogue in, & GPIO,1 & 2 as outputs connected to two led's used to indicate input level < or> depending on value set in ADC reading (e.g. 2volts) I set a DC value between 0v (Vss & 5v = Vdd) using a 10k pott. ADC set up for ext ref 5v vdd. The circuit works_accept as I advance the pott in either direction the led's alternatively switch on and off as the voltage increases or decreases at several intervals. The adc voltage value = 102 (2 volts) for 8 bit convertion. One led should be lit only when > 2v & the other lit < 2v. I'm using the pott only to prove my circuit, and eventually use either a temp sensor (resistive) or an LDR device with one of the GPIO's to switch a relay.
This is the first time I've used this PIC and come accross this problem.
I have included the asm listing. Note very new to programming_most gratefull again for any assistance.
[
;************************************************* *********************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; *
; *
; *
;************************************************* *********************
; *
; Files required: *
; 12F675.lkr *
; *
; *
;************************************************* *********************
; *
; Notes: *
; *
; *
; *
; *
;************************************************* *********************

list p=12f675 ; list directive to define processor
#include <p12f675.inc> ; processor specific variable definitions

errorlevel -302 ; suppress message 302 from list file

__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.



;***** VARIABLE DEFINITIONS (examples)

; example of using Shared Uninitialized Data Section
INT_VAR UDATA_SHR 0x20
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving


;************************************************* *********************
RESET_VECTOR CODE 0x000 ; processor reset vector
goto main ; go to beginning of program


INT_VECTOR CODE 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt


; these first 4 instructions are not required if the internal oscillator is not used

call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
; set file register bank to 0

; ======================= DELAY =================================
DELAY1
CLRF TMR0 ; START TMR0
LOOPBB MOVF TMR0,W ; READ TMR0 INTO W
SUBLW .200 ; TIME -W
BTFSS STATUS,Z ; CHECK TIME W = 0
GOTO LOOPBB
RETLW 0 ; RETURN AFTER TMR0 = 100

main
bsf STATUS,RP0 ; select bank 0
movlw .9 ;B'00001001' ; SET BIT 0 as input ;
movwf TRISIO


movlw B'00000111'
movwf OPTION_REG


movlw B'00010001' ;set bit 0 as analogue input
movwf ANSEL

bcf STATUS,RP0
movlw B'00000111'
movwf CMCON


bcf STATUS,RP0
movlw B'00000001' ; left justified (bit7=0) /255
movwf ADCON0
clrf GPIO
;======================== START OF PROGRAM ============================
BEGIN

bsf ADCON0,GO
WAIT btfsc ADCON0,GO
goto WAIT
bsf STATUS,RP0
movf ADRESL,W
sublw .102 ; 8 bit ADC convertion = 255/5 x 2v = 102
; == 10 BIT ADC CONVERTION _ 2volts
btfsc STATUS,C ; 1,023 / 5volt vdd = 204.6 x voltage in
goto LED1 ; e.g_ 2volts x 204.6 = 409
goto LED2
LED1 bcf STATUS,RP0
bsf GPIO,1
bcf GPIO,2
goto BEGIN
LED2 bcf STATUS,RP0
bsf GPIO,2
bcf GPIO,1
goto BEGIN


END ]
MERV is offline  
Old 15th January 2008, 11:25 PM   (permalink)
Default

Check out the thread called "ADC in assembly" Today january 15, 2008 it is still on the second page of the forum. I put a code and a circuit diagram that work really well and are a good starting point for newbie ADC. Tonight I'll post another code with how to move a servo based on ADC. I hope this helps you in the right dirrection.
__________________
jeremy
jeremygaughan is offline  
Old 16th January 2008, 01:34 AM   (permalink)
Default

Check out the second post in this thread.

Mike.
Pommie is offline  
Old 16th January 2008, 09:04 PM   (permalink)
Default

Quote:
Originally Posted by jeremygaughan
Check out the thread called "ADC in assembly" Today january 15, 2008 it is still on the second page of the forum. I put a code and a circuit diagram that work really well and are a good starting point for newbie ADC. Tonight I'll post another code with how to move a servo based on ADC. I hope this helps you in the right dirrection.
Thanks Jeremy, and others for assistance. I have since solved my problem caused by an instruction (bsf STATUS,RP0) inserted after "WAIT" in my ADC convertion code listing. omitting his instruction has cleared my problem. Being very new to programming, I'm still learning_and probably have a long way to go. I can cope with Pic assembly code, but haven't got a clue regarding "C"
I have been an electronics eng for over 50 years, and must admit it's easy using Micro's_but only if you can program them! Cheers Folks.
MERV is offline  
Old 16th January 2008, 09:06 PM   (permalink)
Default

Cheers Mike, solved it_ see my reply. Kind Regards Merv
MERV is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Circuit Help skeeterb Electronic Projects Design/Ideas/Reviews 7 5th May 2008 07:10 PM
Analog circuit works until a I hook to Adc. jnnewton Electronic Projects Design/Ideas/Reviews 2 7th January 2008 11:50 AM
Help! Adc On A Pic12f675 UrabnBadger Micro Controllers 13 25th November 2007 09:36 PM
Circuit auto OFF feature after no events design Uman Electronic Projects Design/Ideas/Reviews 2 3rd May 2004 06:34 AM
Circuit functioning very strange. Why? Cyclone Electronic Projects Design/Ideas/Reviews 12 4th November 2003 01:31 AM



All times are GMT. The time now is 09:16 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker