![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
hi..
im very new..n i need someone guides to help me solving this problem. i try 2 display digital values in a row of 10leds by injecting 1.5V as an analog value with 5V as Vref..but the values displayed is 0100010010 instead of 100110011...why is this happen? any suggestion to solve it?my codes are as below..is there possibly caused by my wrong codes? define ADIN_RES 10 DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 MEASURED_VALUE VAR word REMAINDER0 VAR word MEASURED0 VAR word REMAINDER1 VAR word MEASURED1 VAR word REMAINDER2 VAR word MEASURED2 VAR word REMAINDER3 VAR word MEASURED3 VAR word REMAINDER4 VAR word MEASURED4 VAR word REMAINDER5 VAR word MEASURED5 VAR word REMAINDER6 VAR word MEASURED6 VAR word REMAINDER7 VAR word MEASURED7 VAR word REMAINDER8 VAR word MEASURED8 VAR word REMAINDER9 VAR word MEASURED9 VAR word TRISA = %00000001 TRISB = %00000000 TRISD.0 = %0 TRISD.1 = %0 ADCON0 = %11000101 ADCON1 = %10000000 pause 500 START: ADCIN 0 , MEASURED_VALUE REMAINDER0 = MEASURED_VALUE // 2 PORTB.0 = ~REMAINDER0 MEASURED0 = ( MEASURED_VALUE / 2 ) REMAINDER1 = MEASURED0 // 2 PORTB.1 = ~REMAINDER1 MEASURED1 = ( MEASURED0 / 2 ) REMAINDER2 = MEASURED1 // 2 PORTB.2 = ~REMAINDER2 MEASURED2 = ( MEASURED1 / 2 ) REMAINDER3 = MEASURED2 // 2 PORTB.3 = ~REMAINDER3 MEASURED3 = ( MEASURED2 / 2 ) REMAINDER4 = MEASURED3 // 2 PORTB.4 = ~REMAINDER4 MEASURED4 = ( MEASURED3 / 2 ) REMAINDER5 = MEASURED4 // 2 PORTB.5 = ~REMAINDER5 MEASURED5 = ( MEASURED4 / 2 ) REMAINDER6 = MEASURED5 // 2 PORTB.6 = ~REMAINDER6 MEASURED6 = ( MEASURED5 / 2 ) REMAINDER7 = MEASURED6 // 2 PORTB.7 = ~REMAINDER7 MEASURED7 = ( MEASURED6 / 2 ) REMAINDER8 = MEASURED7 // 2 PORTD.0 = ~REMAINDER8 MEASURED8 = ( MEASURED7 / 2 ) REMAINDER9 = MEASURED8 // 2 PORTD.1 = ~REMAINDER9 pause 100 GOTO START END hope somebody willing to lend me help thank you.. Last edited by sixty9sandals; 6th March 2007 at 07:18 AM. |
|
|
|
|
|
|
(permalink) |
|
1st: You seem to be witing a command to do a conversion, read a value and writing it to the LEDS. Don't you have to wait for the conversion to be complete BEFORE reading the result?
2nd: Don't you have to insert some delay in between one A/D conversion and the next? 3rd: You gave the value of the analog input voltage, but you didn't tell us what the reference voltage was. How can we know if the value you are getting is correct or the value you expect is correct? 4th: Ohhh..never mind |
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
Agustín Tomás In theory, there is no difference between theory and practice. In practice, however, there is. |
||
|
|
|
|
|
(permalink) | |
|
Quote:
mmm..ya..the Vref value is 5V..as im using adcon1=10000000 which is Vref=Vdd=Vss...pls do correct me if im wrong..im too new to all of this thing..n im using pic 16f877 thank you Last edited by sixty9sandals; 6th March 2007 at 12:07 AM. |
||
|
|
|
|
|
(permalink) |
|
You have to check when the GO!DONE bit (ADCON0.2) has been cleared by hardware (conversion completed), if this is not done by the ADCIN instruction (?). Is that a built-in function of your compiler?
Code:
Pseudo-code:
START: ADCON0.2 = 1;
WAIT: IF (ADCON0.2 = 1)
GOTO WAIT
Get value
Last edited by eng1; 6th March 2007 at 08:29 AM. |
|
|
|
|
|
|
(permalink) |
|
You went back and edited your original post! Now we have no frame of reference for the discussion.
Says me if 5V is the reference and 1.5V is the input you should get Code:
(1.5/5.0)*1024 = 307 decimal = 0x133 = 01 0011 0011 Last edited by Papabravo; 6th March 2007 at 11:59 AM. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| When did this happen? | Marks256 | Feedback/Comments | 1 | 26th February 2007 05:50 PM |
| Accident waiting to happen... | Marks256 | Chit-Chat | 8 | 15th February 2007 12:26 PM |
| wt happen if 3 led in series with 12 vdc | mamun2a | General Electronics Chat | 7 | 7th December 2006 06:34 PM |
| If we fire a bullet to TV screen..what will happen ?? | TuTu | General Electronics Chat | 22 | 30th July 2006 04:02 AM |
| What will happen.... | kevinloh | General Electronics Chat | 2 | 8th December 2003 09:28 AM |