View previous topic :: View next topic |
Author |
Message |
memoally
Joined: 25 Jan 2010 Posts: 35
|
adc help please |
Posted: Mon Jan 25, 2010 2:40 pm |
|
|
I am new on pics, and I have got a duty to make an analog to digital converter with a pic 18f4620 (or 18f4431) but I am really too new for this job, and I can't do it right now. Could anyone help me with codes and explanations sentences. Thank you... _________________ compiler version: 4.105
pic: 16f876
clock frequency: 4MHz |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
memoally
Joined: 25 Jan 2010 Posts: 35
|
|
Posted: Tue Jan 26, 2010 2:43 pm |
|
|
Yes you are right but I can't make it in 18f4620, today I test the code;
Code: |
#include "C:\Documents and Settings\Administrator\My Documents\ccspic uygulamalar\1.h"
#include <16f877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#Define ADC=8
void main()
{
long deger;
set_tris_d(0x00);
while(1)
{
setup_adc(ADC_CLOCK_INTERNAL);
setup_port_a(ALL_ANALOG);
set_adc_channel(0);
delay_ms(10);
deger=read_adc();
output_d(deger);
}
}
|
On 16f877, it is working, but I cannot implement it on 18f4620. I cannot resolve the problem. Maybe I use the wrong ports, of course I change the code for 18f4620 but I cannot take good result. _________________ compiler version: 4.105
pic: 16f876
clock frequency: 4MHz |
|
|
Guest
|
|
Posted: Tue Jan 26, 2010 3:38 pm |
|
|
memoally wrote: | Yes you are right but I can't make it in 18f4620, today I test the code;
Code: |
#include "C:\Documents and Settings\Administrator\My Documents\ccspic uygulamalar\1.h"
#include <16f877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#Define ADC=8
void main()
{
long deger;
set_tris_d(0x00);
while(1)
{
setup_adc(ADC_CLOCK_INTERNAL);
setup_port_a(ALL_ANALOG);
set_adc_channel(0);
delay_ms(10);
deger=read_adc();
output_d(deger);
}
}
|
On 16f877, it is working, but I cannot implement it on 18f4620. I cannot resolve the problem. Maybe I use the wrong ports, of course I change the code for 18f4620 but I cannot take good result. |
Show your code for the 4620. On the 18F series I think to make the ADC eight bits the preprocessor directive is #DEVICE ADC = 8. You have #DEFINE ADC = 8 which doesn't look correct. |
|
|
memoally
Joined: 25 Jan 2010 Posts: 35
|
|
Posted: Wed Jan 27, 2010 11:05 am |
|
|
Actually, it is also 'device' for 16f877 but when changing 'define'
to 'device', CCS gives me some errors, but I can't understand them.
If I am wrong, correct me... _________________ compiler version: 4.105
pic: 16f876
clock frequency: 4MHz |
|
|
Guest
|
|
Posted: Wed Jan 27, 2010 2:12 pm |
|
|
The line
should be placed immediately after your include <16F877> statement. If you put it later you will get an error something like "can't change device this far into the code". |
|
|
|