CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ADC conversion problem on 16F747

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
oneberto



Joined: 25 Aug 2004
Posts: 3
Location: Italy

View user's profile Send private message Send e-mail

ADC conversion problem on 16F747
PostPosted: Wed Aug 25, 2004 8:30 am     Reply with quote

Evil or Very Mad I don't know why the function read_adc(), that works well in other
PIC like 16F877, ecc doesnt' work in 16F747. Listed above is a simply C program used for testing ADC conversion and PWM; the program seems to halt when the function is called. If i comment this line the program works well so if i push the button i can read the value initialized in the variable "valore".... can someone help me ??? the version of CCS compiler is 3.181 and the MPLab is 6.40

#include "C:\Documents and Settings\Administrator\Documenti\ampli\pwm.h"
#include <LCD_D.C>
#include <2402.C>
#include <stdlib.h>

#define tastopiu PIN_B0 //definisco tasti
#define tastomeno PIN_B1
#define tastomenu PIN_B2
#define tastoin PIN_B3

#define ingressoa PIN_E0 //definisco uscite comando rele ingressi
#define ingressob PIN_E1
#define ingressoc PIN_E2

#define ventola PIN_A6 // uscita comando ventola

unsigned long int valore=123;

void main()
{

setup_adc_ports(ANALOG_AN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(00);
setup_vref(VREF_HIGH|6); //imposta limite ADC 1,25 Volt
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,251,1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_ccp3(CCP_PWM);
setup_comparator(NC_NC_NC_NC);
set_tris_B(0b00010000); // imposta porta B5 PWM3 come uscita
port_b_pullups(TRUE); //abilita resistenze pull up su porte B

lcd_init();
//init_ext_eeprom();

do{
printf(lcd_putc,"\fAttendo Lettura");
delay_ms(150);

if(input(tastopiu)==FALSE){
valore=read_adc();
delay_ms(100);
printf(lcd_putc,"\fLeggo ADC : %lu",valore);
delay_ms(150);}

set_pwm1_duty(64);
set_pwm2_duty(128);
set_pwm3_duty(192);
}
while(true);

}


Many thanks in advance Umberto[/i][/b]
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Aug 25, 2004 9:47 am     Reply with quote

A very strange problem, it looks like the internal RC clock of the ADC isn't working.
Please try if the problem also occurs when you change
Code:
 setup_adc(ADC_CLOCK_INTERNAL);
to
Code:
 setup_adc(ADC_CLOCK_DIV_32);
oneberto



Joined: 25 Aug 2004
Posts: 3
Location: Italy

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 25, 2004 10:28 am     Reply with quote

I've tryed this,but is the same... don't work....
Thanks Umberto Sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 25, 2004 11:54 am     Reply with quote

To find out what the compiler is doing, you should compile a short
test program and look at the .LST file. So I installed PCM vs. 3.181
and compiled the A/D portion of your code. From the .LST file, I
can that the compiler doesn't produce any code for the setup_adc()
function. This is a bug in that version.

When CCS adds support for new PICs to the compiler, it is very often
the case that the A/D functions do not work properly. It takes them
several versions to get bug reports and then fix it.

In the following code, I see several problems:
1. The initial A/D setup code at the beginning of main() is initializing
ADCON0 and ADCON1 incorrectly.
2. The setup_adc() function generates no code.
3. The set_adc_channel() function clears bits 6 and 7 in ADCON0,
and it should not do that.

To fix these problems for the 16F747 and PCM vs. 3.181, you need
to write your own functions to replace the bad ones listed above.

Code:

.................... main() 
.................... { 
0004:  CLRF   04
0005:  MOVLW  1F
0006:  ANDWF  03,F
0007:  MOVLW  0F
0008:  BSF    03.5
0009:  MOVWF  1F
000A:  MOVLW  07
000B:  BCF    03.5
000C:  MOVWF  1F
.................... int16 valore; 
....................   
.................... setup_adc_ports(ANALOG_AN0);   
000D:  MOVLW  0E
000E:  BSF    03.5
000F:  MOVWF  1F
.................... setup_adc(ADC_CLOCK_INTERNAL);   
.................... set_adc_channel(00);   
0010:  MOVLW  00
0011:  MOVWF  78
0012:  BCF    03.5
0013:  MOVF   1F,W
0014:  ANDLW  03
0015:  IORWF  78,W
0016:  MOVWF  1F
.................... setup_vref(VREF_HIGH | 6);   
0017:  MOVLW  86
0018:  BSF    03.5
0019:  MOVWF  1F
....................   
oneberto



Joined: 25 Aug 2004
Posts: 3
Location: Italy

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 26, 2004 6:50 am     Reply with quote

Thank you, i apprecciate your replay.
In fact the assembler code generated is incomplete like you said.
But now i have another problem... Sad i don't know how to correct the bug in assembly 'cos don't know it...
Can you help me another bit ???

many thanks in advance Umberto
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 26, 2004 8:28 am     Reply with quote

This post has an example of how to write functions for features that
CCS didn't implement yet.
http://www.ccsinfo.com/forum/viewtopic.php?t=20189
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group