![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #16 |
|
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. | |
| |
| | #17 |
|
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
| |
| |
| | #18 |
|
has code etc. may not be what your looking for but then again it might be?? Phototransistor multitouch with a twist - Hack a Day | |
| |
| | #19 |
|
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 | |
| |
| | #20 |
| 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.
| |
| |
| | #21 |
|
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
Code: movlw B’10000001’ ;Right, Vdd Vref, AN0
movwf ADCON0
Last edited by be80be; 28th June 2009 at 08:48 PM. | |
| |
| | #22 |
|
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.
| |
| |
| | #23 |
|
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. | |
| |
| | #24 |
|
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 Mike. | |
| |
| | #25 |
|
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
Last edited by be80be; 29th June 2009 at 07:12 AM. | |
| |
| | #26 |
|
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 | |
| |
| | #27 |
| LOL NOT TO WORRY my pic still run when i hook them up lol
| |
| |
| | #28 |
|
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 | |
| |
| | #29 |
|
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. Last edited by be80be; 1st July 2009 at 03:54 PM. | |
| |
| | #30 |
|
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. | |
| |
|
| Tags |
| adc, ideals |
| Thread Tools | |
| Display Modes | |
| |