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.

yet another PIC12F683 ADC problem

Status
Not open for further replies.
30 day trial version? Enable it all functions? Or is it inside any limitations? Where from can I download it? Think You for this: PIC Simulator IDE with Basic Compiler, Assembler, Disassembler and Debugger ?

fejesg

hi,
Which question do you want answering first.:)

Oshon Software Homepage

Download the fully working 30 day or 30 times run, PIC IDE

Get it and load your program

BTW: now moved onto the second part of your posted program, there a big sections missing.!. References to an ISR etc, so I will stop.

Why dont you write a short program that reads the ADC, prove it OK.
then move forward to the PWM.
Always debug peripheral subr before writing a full program.

I'll look thru the MPLAB sim, personally I dont like it, maybe someone with experience will answer.
 
Sorry, Eric; I can not understand Your message:

"BTW: now moved onto the second part of your posted program, there a big sections missing.!. References to an ISR etc, so I will stop."

So. I think, the program which I wrote is a "small try" one. Can You make smaller test program?

If You can, please send me a small "test" program, with wich I can try to work ADC.

Thank You the information about Oshon Simulator.

fejesg
 
I try to make my program shorter:

;************************************************* ***********
; Processor: PIC12F683 at 4 MHz using intosc
;************************************************* ***********
LIST P=12F683, R=DEC
#include "P12F683.INC"
;
__config _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _INTOSCIO
;
CBLOCK 0x20
Loop1, Loop2, adfelso, adalso
ENDC
;
ORG 0x00
goto main

InitIO
BANKSEL GPIO
clrf GPIO
movlw b'00000111'
movwf CMCON0
CLRF TMR2 ;
CLRF T2CON ;
CLRF CCPR1L ;
BANKSEL ANSEL
movlw 0x33
movwf ANSEL
movlw 0x03
movwf TRISIO
BANKSEL GPIO
return

delay
MOVLW 60
MOVWF Loop1
Outer MOVLW 250
MOVWF Loop2
Inner NOP
NOP
DECFSZ Loop2,F
GOTO Inner ; Inner loop = 5 usec.
DECFSZ Loop1,F
GOTO Outer
RETURN

Sample
bsf ADCON0,0
movlw 0x0
call delay
bsf ADCON0,1
btfsc ADCON0,1
goto $-1
movfw ADRESH
movwf adfelso
BANKSEL ADRESL
movfw ADRESL
BCF STATUS,RP0
movwf adalso
BANKSEL PIR1
bcf ADCON0,0
return

main

call InitIO

here

call Sample

BCF STATUS,RP0 ; Bank0

goto here

end

But how I check working of ADC? With witch can I sign value of ADRESL or ADRESH?

fejesg
 
Ahoy Eric!

I downloaded Oshon, runned the program; SUCCESS! I setted up special breakpoints, stop when ADRESL or ADRESH changes - when I modified Voltage (2,39V) of GP0, the program STOPPED, ADRESL and ADRESH have values !!!!!!!!!!!

I hope, the program will works inside of PIC...

fejesg
 
Yeeeah !!!! ThanX for Eric !

When I tryed program whith Oshorn PicSim and chacked registers again, I realized, what is the error - I could modify CCP1CON, in place of CCPR1L !

I corrected ANSEL, that conversion time shall be Fosc/16, I use only GP0. And go! The circuit works; I putted in the "already workable" direction-change-unit, and the program is ready.

;*********************************************
; Processor: PIC12F683 at 4 MHz using intosc
;******************************************
list P=12F683, R=DEC
#include "P12F683.INC"
__config _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _INTOSCIO
cblock 0x20
Loop1, Loop2, adfelso, adalso
endc
org 0x00
banksel GPIO
clrf GPIO
movlw b'00000111'
movwf CMCON0
clrf TMR2
banksel ANSEL
movlw b'01010001' ; Fosc/16, only GP0 analog input
movwf ANSEL
movlw b'11001001'
movwf TRISIO
bsf STATUS,RP0
movlw b'11111111'
movwf PR2
clrf INTCON
clrf PIE1
bcf STATUS,RP0
movlw b'00000101'
movwf T2CON
clrf CCPR1L
movlw b'10001100' ; PWM on, active L upper 2 byte 00
movwf CCP1CON
movlw b'00001111'
movwf CCPR1L ; basement value
goto main
adc0
bsf ADCON0,0 ; turn on adc.
movlw 0x0
nop
nop
nop
nop
nop
nop
nop
nop
nop
bsf ADCON0,1 ; GO!
btfsc ADCON0,1 ; are we really done???
goto $-1
movfw ADRESH
movwf adfelso
banksel ADRESL
movfw ADRESL
bcf STATUS,RP0
movwf adalso
banksel ADCON0
bcf ADCON0,0
nop
nop
nop
nop
nop
return
frw
bcf T2CON,2
nop
nop
nop
nop
bsf GPIO,5
bcf GPIO,4
nop
bsf T2CON,2
goto main
;
rew
bcf T2CON,2
nop
nop
nop
nop
bsf GPIO,4
bcf GPIO,5
nop
bsf T2CON,2
goto main
main
call adc0
bcf STATUS,RP0 ; Bank0
movfw adalso
movwf CCPR1L
nop
nop
nop
btfss GPIO,1
goto frw
btfsc GPIO,1
goto rew
nop
nop
goto main
end
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top