Continue to Site

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.

  • 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.

PIC12F675 ADC Circuit help.

Status
Not open for further replies.

MERV

New Member
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 ]
 
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.
 
jeremygaughan said:
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.
 
In my application i cant use the opamp as the input voltage is not constant, it varies from 1 v to 4 v so i am left with no other option than to use ADC. Can u tell me how this can be done with ADC.
When the input is 0 v the output at GP1 and 2 should produce an alternate on/off pulse whose ON time is 5us and OFF time of 15us.
Otherwise the output at GP1 and 2 should produce an alternate on/off pulse whose ON time is 10us and OFF time of 20us.

Moreover since the duty cycle is not 50%
so when the GP1 is ON for the first time for 5us and after that it goes off for 15us, at that moment GP2 should not go ON immediately but after 5us it should go ON for
5us and OFF while the GP1 completes its cycle such that the pulses remain synchroized with each other.

And same thing with 10us and 20us

I am attaching an image from the oscilloscope of the pulse. Please see to it

Some1 please provide the schematic to this
 
In my application i cant use the opamp as the input voltage is not constant, it varies from 1 v to 4 v so i am left with no other option than to use ADC. Can u tell me how this can be done with ADC.

The whole point of an analogue is that it's not constant - 1V-4V variation is perfectly fine for using the ADC without an opamp, assuming the source impedance is low enough, if not use an opamp as a buffer to provide a low impedance output.
 
It takes 5 uS for ADC cap to charge on the adc and 2 to 4 uS to check it how are you going to use it for
When the input is 0 v the output at GP1 and 2 should produce an alternate on/off pulse whose ON time is 5us and OFF time of 15us.
That's with the 12f675 that imrankh posted.
 
Here what the data sheet said
Code:
TACQ
TC
TACQ
=
=
=
=
=
=
=
=
Amplifier Settling Time +
Hold Capacitor Charging Time +
Temperature Coefficient
TAMP + TC + TCOFF
2μs + TC + [(Temperature -25°C)(0.05μs/°C)]
CHOLD (RIC + RSS + RS) In(1/2047)
- 120pF (1kΩ + 7kΩ + 10kΩ) In(0.0004885)
16.47μs
2μs + 16.47μs + [(50°C -25°C)(0.05μs/°C)
19.72μs
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top