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
 
Tools
Old 28th June 2009, 04:23 PM   #16
Default

Ok Just to make sure I have the right

movlw _1VOLT This puts 0x33 in W

subwf ADRESH, w This Subtract W from f

BNC LessThan1V This branch on no carry

So the way this works forget it I see now that wrote it out like this.

This puts 0x33 in W Subtract W from f branch on no carry
So it keeps stepping up till it finds the one that it is smaller then
Thanks a bunch Kchriste
Some thing like this
Code:
Start:
	movlw _1VOLT
	subwf ADRESH, w
	BNC LessThan1V    ; if adc = 33or less run code at LessThen1V
	
	
LessThen1V:
				;run code I want to run here

Last edited by be80be; 28th June 2009 at 04:50 PM.
be80be is offline  
Old 28th June 2009, 06:04 PM   #17
Default

Now I'm getting some where this turns on the leds by the voltages
But it think it's set for 10 bit conversion
Code:
list		p=16f684		; list directive to define processor
	#include	<P16F684.inc>		; processor specific variable definitions
	errorlevel -302 ; Turn off banking message
                            ; known tested (good) code

	__CONFIG    _CP_OFF & _CPD_OFF & _BOD_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _FCMEN_OFF & _IESO_OFF
	


	CBLOCK 		0x020
	endc
	#define _1VOLT 0x33
	#define _2VOLT 0x66
	#define _2_5VOLT 0x7F
	#define _3VOLT 0x99
	#define _4VOLT 0xCC
	#define _5VOLT 0xFF




	ORG			0x000		; processor reset vector
  	goto		init		; go to beginning of program


	ORG			0x004	    ; interrupt vector location

init:
     bsf       STATUS,RP0     ; select Register Page 1
     movlw     0xFF
     movwf     TRISA          ; Make PortA all input
     clrf      TRISC          ; Make PortC all output
     movlw     0x10           ; A2D Clock Fosc/8
     movwf     ADCON1
     bcf       STATUS,RP0     ; back to Register Page 0

     bcf       STATUS,RP0     ; address Register Page 2
     bsf       STATUS,RP1     
     movlw     0xFF           ; we want all Port A pins Analog
     movwf     ANSEL
     bcf       STATUS,RP0     ; address Register Page 0
     bcf       STATUS,RP1
     
     movlw     0x01
     movwf     ADCON0         ; configure A2D for Channel 0 
MainLoop:
     call	adcdelay		  ;delay to charge cap
     bsf       ADCON0,GO      ; start conversion
     btfss     ADCON0,GO      ; this bit will change to zero when the conversion is complete
     goto      $-1

     movf     ADRESH,w       ; Copy the display to the LEDs
    movlw 	_1VOLT
    subwf	 ADRESH, w
    BNC 	LessThan1V                ; Branch if less than 1V
    movlw 	_2VOLT
    subwf	 ADRESH, w
    BNC 	LessThan2V                ; Branch if Between 1V and 2V
    movlw 	_2_5VOLT
    subwf 	ADRESH, w
    BNC 	LessThan2_5V             ; Branch if Between 2V and 2.5V
    movlw 	_3VOLT
    subwf	 ADRESH, w
    BNC 	LessThan3V                ; Branch if Between 2.5V and  3V
    movlw 	_4VOLT
    subwf 	ADRESH, w
    BNC 	LessThan4V                ; Branch if Between 3V and 4V
    								;Hmmm..  must be 4V or more here.
    goto      MainLoop
LessThan1V:
	bsf		PORTC,0
	return
LessThan2V
	bsf		PORTC,1					; lights led thats in volt range 
	return
LessThan2_5V 
	bsf		PORTC,2 
	return
LessThan3V
    bsf		PORTC,3	  
	return	
LessThan4V
	bsf		PORTC,4
	return
 

   
adcdelay:
	 nop					  ;1 cycle

	 return					  ;4 cycles (including call)
	
     end
be80be is offline  
Old 28th June 2009, 07:18 PM   #18
Default take a look at this dealing w/ ADC

has code etc.
may not be what your looking for but then again it might be??
Phototransistor multitouch with a twist - Hack a Day
MrDEB is offline  
Old 28th June 2009, 07:47 PM   #19
Default

I have read more then I need to lol my head is killing me but not one apnote
I have read tells you which way the conversion gos That's what was getting me and I found out the 16f684 has only a 10 bit conversion
be80be is offline  
Old 28th June 2009, 08:08 PM   #20
Default

Quote:
Originally Posted by be80be View Post
I have read more then I need to lol my head is killing me but not one apnote
I have read tells you which way the conversion gos That's what was getting me and I found out the 16f684 has only a 10 bit conversion
Read my PIC ADC tutorial, you can't set PIC's to only be 8 bit, BUT you can (usually) set then right or left justified. By setting this correctly you can read just the top 8 bits, effectively giving you an 8 bit conversion.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 28th June 2009, 08:42 PM   #21
Default

Nigel
In your PIC ADC tutorial your bit is set ADFM: A/D Result Formed Select bit 1 = Right justified . That is right ? My code is reading for the left justified
I need to make sure this is set right
Code:
     movlw     0x01
     movwf     ADCON0         ; configure A2D for Channel 0
I should use this
Code:
    movlw     B’10000001’     ;Right, Vdd Vref, AN0
    movwf    ADCON0
and change ADRESH,w to ADRESL,W

Last edited by be80be; 28th June 2009 at 08:48 PM.
be80be is offline  
Old 28th June 2009, 11:03 PM   #22
Default

No, you need to clear it, and read just ADRESH - this then gives the top 8 bits (8 bit resolution), and also doesn't need the bank changing.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 29th June 2009, 03:41 AM   #23
Default

Almost have it I think what it is doing is as reads the volts it lights the led
starting at 1 and going to 5 volts But when I get at 5 volts and go back down
the last led stays on
Code:
list		p=16f684		; list directive to define processor
	#include	<P16F684.inc>		; processor specific variable definitions
	errorlevel -302 ; Turn off banking message
                            ; known tested (good) code

	__CONFIG    _CP_OFF & _CPD_OFF & _BOD_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _FCMEN_OFF & _IESO_OFF
	


	CBLOCK 		0x020
	endc
	#define _1VOLT 0x33
	#define _2VOLT 0x66
	#define _2_5VOLT 0x7F
	#define _3VOLT 0x99
	#define _4VOLT 0xCC
	#define _5VOLT 0xff




	ORG			0x000		; processor reset vector
  	goto		init		; go to beginning of program


	ORG			0x004	    ; interrupt vector location

init:
     bsf       STATUS,RP0     ; select Register Page 1
     movlw     0xFF
     movwf     TRISA          ; Make PortA all input
     clrf      TRISC          ; Make PortC all output
     movlw     0x10           ; A2D Clock Fosc/8
     movwf     ADCON1
     bcf       STATUS,RP0     ; back to Register Page 0

     bcf       STATUS,RP0     ; address Register Page 2
     bsf       STATUS,RP1     
     movlw     0xFF           ; we want all Port A pins Analog
     movwf     ANSEL
     bcf       STATUS,RP0     ; address Register Page 0
     bcf       STATUS,RP1
     clrf	   ADCON0
     movlw     0x01
     movwf     ADCON0         ; configure A2D for Channel 0 
MainLoop:
     call	adcdelay		  ;delay to charge cap
     bsf       ADCON0,GO      ; start conversion
     btfss     ADCON0,GO      ; this bit will change to zero when the conversion is complete
     goto      $-1
	
    movf     ADRESH,w       ; Copy the display to the LEDs
    movlw 	_1VOLT
    subwf	 ADRESH, w
	BNC 	LessThan1V                ; Branch if less than 1V

	movf     ADRESH,w       ; Copy the display to the LEDs
    movlw 	_2VOLT
    subwf	 ADRESH, w
	BNC 	LessThan2V                ; Branch if Between 1V and 2V
	
	movf     ADRESH,w       ; Copy the display to the LEDs
    movlw 	_2_5VOLT
    subwf 	ADRESH, w
	BNC 	LessThan2_5V             ; Branch if Between 2V and 2.5V

	movf     ADRESH,w       ; Copy the display to the LEDs
    movlw 	_3VOLT
    subwf	 ADRESH, w
	BNC 	LessThan3V                ; Branch if Between 2.5V and  3V

	movf     ADRESH,w       ; Copy the display to the LEDs
    movlw 	_4VOLT
    subwf 	ADRESH, w
	BNC 	LessThan4V                ; Branch if Between 3V and 4V
	movf     ADRESH,w       ; Copy the display to the LEDs
    movlw 	_5VOLT
    subwf 	ADRESH, w
	BNC 	LessThan5V                ; Branch if Between 3V and 4V
    goto      MainLoop
LessThan1V:
	bsf		PORTC,0
	return
LessThan2V
	bsf		PORTC,1					; lights led thats in volt range 
	return
LessThan2_5V 
	bsf		PORTC,2 
	return
LessThan3V
    bsf		PORTC,3	  
	return	
LessThan4V
	bsf		PORTC,4
	return
LessThan5V
	clrf	PORTC
	return 

   
adcdelay:
	 nop					  ;1 cycle

	 return					  ;4 cycles (including call)
	
     end

Last edited by be80be; 29th June 2009 at 03:41 AM.
be80be is offline  
Old 29th June 2009, 06:05 AM   #24
Default

If you want them to go off you need to clear the other bits. Also you have returns without calls.

Try changing it to,
Code:
LessThan1V
	movlw	b"00000001"
	movwf	PORTC
	goto	MainLoop
LessThan2V
	movlw	b"00000011"
	movwf	PORTC
	goto	MainLoop
The red one should be zero if you only want one LED on at any one time.

Mike.
Pommie is online now  
Old 29th June 2009, 07:02 AM   #25
Default

Did a little changing plus add what you said Mike and this works flawless.
Code:
    list		p=16f684		; list directive to define processor
	#include	<P16F684.inc>		; processor specific variable definitions
	errorlevel -302 ; Turn off banking message
                            ; known tested (good) code

	__CONFIG    _CP_OFF & _CPD_OFF & _BOD_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _FCMEN_OFF & _IESO_OFF
	


	CBLOCK 		0x020
	endc
	#define _1VOLT 0x33
	#define _2VOLT 0x66
	#define _2_5VOLT 0x7F
	#define _3VOLT 0x99
	#define _4VOLT 0xCC
	#define _5VOLT 0xff




	ORG			0x000		; processor reset vector
  	goto		init		; go to beginning of program


	ORG			0x004	    ; interrupt vector location

init:
     bsf       STATUS,RP0     ; select Register Page 1
     movlw     0xFF
     movwf     TRISA          ; Make PortA all input
     clrf      TRISC          ; Make PortC all output
     movlw     0x10           ; A2D Clock Fosc/8
     movwf     ADCON1
     bcf       STATUS,RP0     ; back to Register Page 0

     bcf       STATUS,RP0     ; address Register Page 2
     bsf       STATUS,RP1     
     movlw     0xFF           ; we want all Port A pins Analog
     movwf     ANSEL
     bcf       STATUS,RP0     ; address Register Page 0
     bcf       STATUS,RP1
     clrf	   ADCON0
     movlw     0x01
     movwf     ADCON0         ; configure A2D for Channel 0 
MainLoop:
     call	adcdelay		  ;delay to charge cap
     bsf       ADCON0,GO      ; start conversion
     btfss     ADCON0,GO      ; this bit will change to zero when the conversion is complete
     goto      $-1
	
    movf     ADRESH,w       ; Copy the display to the LEDs
    movlw 	_1VOLT
    subwf	 ADRESH, w
	BNC 	LessThan1V                ; Branch if less than 1V


    movlw 	_2VOLT
    subwf	 ADRESH, w
	BNC 	LessThan2V                ; Branch if Between 1V and 2V
	

    movlw 	_2_5VOLT
    subwf 	ADRESH, w
	BNC 	LessThan2_5V             ; Branch if Between 2V and 2.5V


    movlw 	_3VOLT
    subwf	 ADRESH, w
	BNC 	LessThan3V                ; Branch if Between 2.5V and  3V


    movlw 	_4VOLT
    subwf 	ADRESH, w
	BNC 	LessThan4V                ; Branch if Between 3V and 4V


    movlw 	_5VOLT
    subwf 	ADRESH, w
	BNC 	LessThan5V                ; Branch if Between 3V and 4V
    goto      MainLoop
LessThan1V:
	movlw	b'00000001'
	movwf	PORTC
	goto	MainLoop

LessThan2V
	movlw	b'00000010'
	movwf	PORTC
	goto	MainLoop

LessThan2_5V 
	movlw	b'00000100'
	movwf	PORTC
	goto	MainLoop

LessThan3V
    movlw	b'00001000'
	movwf	PORTC
	goto	MainLoop

LessThan4V
	movlw	b'00010000'
	movwf	PORTC
	goto	MainLoop

LessThan5V
	movlw	b'00100000'
	movwf	PORTC
	goto	MainLoop

adcdelay:
	 nop					  ;1 cycle

	 return					  ;4 cycles (including call)
	
     end
I was sending it back to the same place it came from lol thanks Mike and Kchriste I have learned a lot here. Wait till you see what I'm making. now it's solder time.

Last edited by be80be; 29th June 2009 at 07:12 AM.
be80be is offline  
Old 29th June 2009, 12:05 PM   #26
Default QUICK grab your wives n childeren!!!!

And run like hell!!!!
Ol be80be is going to solder something
It's Alive, Its alive can be herd from the basement of the be80be's compound
the lights are flickering, the weather has turned bad, lightening everywhere!!
If you care for your loved ones,
RUN
the be80be laboratory is up and running. just as soon as that soldering iron gets hot!!
and this time he has been playing with ADC!! PIC code
MrDEB is offline  
Old 29th June 2009, 04:01 PM   #27
Default

LOL NOT TO WORRY my pic still run when i hook them up lol
be80be is offline  
Old 30th June 2009, 05:13 AM   #28
Default I can't say the same

I cut the one battery off my set up just to prevent popping another PIC
In fact the SFHTOP paid me a visit.
I have been put on probation that if I destroy another PIC then off to the big house



Society For Humain Treatment Of Pics
MrDEB is offline  
Old 1st July 2009, 03:53 PM   #29
Default

Here what I was making the GPIO Play ground I like play with 12f683
so i made this board to go with the one that has the pic and 74hc164 on it. It gives
me 10 switches and 8 leds and two adc toys a pot and a LDR to mess with.
Attached Thumbnails
Some ideals on adc-gedc0474.jpg   Some ideals on adc-gpio-play-ground.png  

Last edited by be80be; 1st July 2009 at 03:54 PM.
be80be is offline  
Old 1st July 2009, 04:29 PM   #30
Default

I kind of added it up the data sheet tell you it takes 5 cycles for the cap to settle that's the same as a nop and the return. Oh and the call takes 2 so you have a 5 cycle delay more then good enough.

Last edited by be80be; 1st July 2009 at 04:42 PM.
be80be is offline  
Reply

Tags
adc, ideals

Thread Tools
Display Modes




All times are GMT. The time now is 04:40 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker