View previous topic :: View next topic |
Author |
Message |
wave_man Guest
|
ADC troubles |
Posted: Thu Jan 06, 2005 6:37 pm |
|
|
Hi All,
I am working with a 16C877A, the CCS demo-board actually. I am trying to work on an analog input routine as a prelude to developing a position controller for a rotary actuator. With the demo board powered down, I can apply a voltage to the header for AN3 and read it all the way to the appropriate pin on the '877A. Call it 3.0 VDC. As soon as I run the following code, it gets pulled down to about 10 mV. Huh??
#include <16f877A.h>
#device ADC=8
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000)
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <stdlib.h>
main()
{
long reading;
setup_adc_ports (AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(3);
while(TRUE)
{
delay_ms(1);
reading=read_adc();
printf("\r\nThe reading is %Lu ",reading);
}
}
I don't quite know what to do. Is this a hardware problem? The 3V is being generated by a Measurement Computing PMD-1208FS D/A channel.
Thanks for any clues...
JF |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Thu Jan 06, 2005 7:06 pm |
|
|
What compiler version?
Have you looked at your LST file to confirm that the ADC pins are correctly configured by the "setup_adc_ports" and "setup_adc" functions. I believe early versions of the compiler had a tendency to goof up on those functions. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Guest
|
|
Posted: Thu Jan 06, 2005 7:26 pm |
|
|
rwyoung wrote: | What compiler version?
Have you looked at your LST file to confirm that the ADC pins are correctly configured by the "setup_adc_ports" and "setup_adc" functions. I believe early versions of the compiler had a tendency to goof up on those functions. |
Compiler PCM 3.213.
I run it from Textpad, install with the ICD40.
As for the second question, I no speaka da assembler.
Here is that portion of the list.
.................... long reading;
.................... setup_adc_ports (AN0_AN1_AN3);
*
00AB: BSF 03.5
00AC: BCF 1F.0
00AD: BCF 1F.1
00AE: BSF 1F.2
00AF: BCF 1F.3
.................... setup_adc(ADC_CLOCK_INTERNAL);
00B0: BCF 1F.6
00B1: BCF 03.5
00B2: BSF 1F.6
00B3: BSF 1F.7
00B4: BSF 03.5
00B5: BCF 1F.7
00B6: BCF 03.5
00B7: BSF 1F.0
.................... set_adc_channel(3);
00B8: MOVLW 18
00B9: MOVWF 78
00BA: MOVF 1F,W
00BB: ANDLW C7
00BC: IORWF 78,W
00BD: MOVWF 1F
....................
.................... while(TRUE)
.................... {
.................... delay_ms(1);
00BE: MOVLW 01
00BF: MOVWF 27
00C0: GOTO 01E
.................... reading=read_adc();
00C1: BSF 1F.2
00C2: BTFSC 1F.2
00C3: GOTO 0C2
00C4: MOVF 1E,W
00C5: CLRF 26
00C6: MOVWF 25
and on it goes...
Thank you for your insight, please take a look at this and see if it looks kosher!
JF |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Thu Jan 06, 2005 10:25 pm |
|
|
[quote="Anonymous"] rwyoung wrote: | As for the second question, I no speaka da assembler.
JF |
Now is a VERY GOOD time to learn.
In the long run, it will help you find odd problems.
I'll take a quick look too. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Guest
|
|
Posted: Fri Jan 07, 2005 11:53 am |
|
|
[quote="rwyoung"] Anonymous wrote: | rwyoung wrote: | As for the second question, I no speaka da assembler.
JF |
Now is a VERY GOOD time to learn.
In the long run, it will help you find odd problems.
I'll take a quick look too. |
How do you recommend I proceed (references, websites, books)?
JF |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 07, 2005 12:28 pm |
|
|
What pin number are you looking at with your voltmeter or scope ? |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Fri Jan 07, 2005 1:00 pm |
|
|
Quote: | How do you recommend I proceed (references, websites, books)?
|
Data sheet for the part. Also go to Microchip's web site and start reading application notes. Google for "PIC assembly lanugag tutorial" and variations on that theme.
I didn't use a book to learn PIC assembly, just the datasheet. However I had already been working in assembly for years with Motorola (now Freescale) 6809, 6805 and 6811 parts so it was mostly learning the PIC syntax and learning to "love" register banks.
Sorry I haven't had time to go over your listing yet. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Guest
|
|
Posted: Fri Jan 07, 2005 8:22 pm |
|
|
rwyoung wrote: | Quote: | How do you recommend I proceed (references, websites, books)?
|
Data sheet for the part. Also go to Microchip's web site and start reading application notes. Google for "PIC assembly lanugag tutorial" and variations on that theme.
I didn't use a book to learn PIC assembly, just the datasheet. However I had already been working in assembly for years with Motorola (now Freescale) 6809, 6805 and 6811 parts so it was mostly learning the PIC syntax and learning to "love" register banks.
Sorry I haven't had time to go over your listing yet. |
Please don't!!
I found the problem. The tri-state register was not being set by the c-commands I was sending, so I had to chunk in one more line of code to do that...
Thanks for your help and advice,
JF |
|
|
|