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.

ADC in assembly

Status
Not open for further replies.

trvo

New Member
Hi All,

I'm pretty new to PIC's and have a fairly basic understanding of how to program in them. At the moment I'm playing around with a 12F675. I would like to find some information that would teach me how to use the built in ADC in assembly but all I can find is C and PBasic based tutorials. I want to read the input value of a Pot through AN0. At the moment I understand that I will get a digital value between 0 and 1023 on the 10bit ADC. But how to get at it is the issue.

Can anyone point me in the right direction of some up-to-date learning resources for assembly or explain what I need to do and why in order to get an analogue signal into digital format? I am looking to learn, not copy and am self taught.

Many Thanks - Trev
 
Thanks Nigel, will take a look at all the tutorials on your site :) - I think this is the one I'm after at the moment though:

Many Thanks - Trev
 
Hey trvo I just finished learning the basics of ADC using a 12f675. Here is what I learned. This program will fade an led based on the position of the pot. the big pot is to fade the light, the little pot is to trim the voltage so you have from off to full. without it you will go from full to off and the it will get bright again going in a circle. The big pot is 10k the little one is 5k. Tell me if you have any problems with it.



Code:
;fade

	list P=12f675
#include <p12f675.inc>
	__config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF 
	ERRORLEVEL -302
	
	cblock		20h
	timer1,timer2,timer3,slow,pwm
	endc
	
	bsf	STATUS,RP0		;bank 1
	movlw	0x38
	movwf	ANSEL
	movlw	0x38
	movwf	TRISIO		
	bcf	STATUS,RP0
	
	movlw	0x07		;turn off comparitors
	movwf	CMCON
	movlw	0x0d
	movwf	ADCON0

start
	bsf		ADCON0,1
waiting
	btfsc	ADCON0,1
	goto	waiting
start1
	movlw	0x0f
	movwf	timer3
start2
	movf	ADRESH,0
	movwf	timer1
	movwf	timer2
start3
	movlw	0x01
	movwf	GPIO		;turn on
	decfsz	timer1,1
	goto	start3
pause1
	movlw	0x00
	movwf	GPIO
	incfsz	timer2,1
	goto	pause1
	decfsz	timer3,1
	goto	start2
	goto	start
	end
 

Attachments

  • fade.JPG
    fade.JPG
    15.5 KB · Views: 530
Last edited:
Great, thanks...

I managed to get my own working fairly well but I went for an on / off switch at a certain position on the pot. Yours will prove very useful. Thanks :)

Trev
 
12f683

Hello, it's me again.

I think my situation might be a little bit different than yours. First, i'm using a 12F683, as opposed to 675 and i plan on using only one pot. I want to use it in conjunction with an LED driver chip where the pic will be connected to the dimmer. The reason i'm using the pic is that the constant current regulator i'm using(LM3404) needs a PWM signal fed into the dimmer in order to use the dimmer. So my code has to be able to provide this signal and let the regulator control the brightning or dimming of the LED. Any suggestion, please feel free to jump in.
 
I read a little about your switch and it seems that it just needs the pwm to adjust the voltage. Duty cycle of 50% means half of the voltage of your power supply when run through the regulator. The two potentiometers are pretty necessary in my opinion. They are super cheap and I also don't know another way to get the system trimmed without them. Post a diagram of what you got so far.
 
Push button dimming

Hi! guys,

I want to use push buttons to dim/bright LED with 12f675.
Can any one help with codes?
Thx
 
your right birdman, I was just about to run a few software pwm's with the buttons calling folders with different values. If he gets back on the forum we should continue in a new thread.
 
Thx Jeremy,

Kindly help me with PWM duty cycle control from 0-100% with 2% increment with two push buttons. dim/ bright
PWM frequency 100 hz/ 200 hz

Please help me
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top