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

16F1823 ADC and Delay problems

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



Joined: 14 Jul 2010
Posts: 9
Location: Switzerland

View user's profile Send private message

16F1823 ADC and Delay problems
PostPosted: Thu Aug 19, 2010 6:08 am     Reply with quote

I have some problems with the CCS compiler 4.110 for the 16f1823 device.

SETUP_ADC_PORTS(sAN1|sAN3|sAN4|sAN5|VSS_VDD);
-> ANSEL A/C arent right if i watch dem with
the MPLAB/debugger/MPLAB SIM

DELAY_US(900);
-> won't work, delays bigger than 700us won't work

Anybody else has this problem?

Regards, Nicolas
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 2:18 pm     Reply with quote

The setup_adc_ports() function is buggy for vs. 4.110 and 4.111. I can
see this by looking at the .LST file. The values and the register addresses
are wrong in some cases. I suggest that you write directly to the ANSEL
registers to setup the ports.

I can confirm that delay_us(900) does not work correctly. It fails with
both vs. 4.110 and 4.111. My suggestion is to use the sum of two smaller
delays that adds up to your desired value. Example:
Code:

delay_us(500);
delay_us(400);

And then email CCS with a full report of these bugs. Tell them that it fails
in both vs. 4.110 and 4.111. If your maintenance period has ended, I
think they will upgrade you to the latest version when they fix it.
duchonic



Joined: 14 Jul 2010
Posts: 9
Location: Switzerland

View user's profile Send private message

thank you.
PostPosted: Sun Aug 22, 2010 11:37 pm     Reply with quote

I tried to write to ANSELA, ANSELC directly but this won't work.

I worked with the PIC16F1827 and the CCS 4.109 compiler before. Delays and setup_adc_ports worked fine.

Is it possible that with the CCS4.109 compiler my 16F1823 device could work?

PCM programmer wrote:
The setup_adc_ports() function is buggy for vs. 4.110 and 4.111. I can
see this by looking at the .LST file. The values and the register addresses
are wrong in some cases. I suggest that you write directly to the ANSEL
registers to setup the ports.

I can confirm that delay_us(900) does not work correctly. It fails with
both vs. 4.110 and 4.111. My suggestion is to use the sum of two smaller
delays that adds up to your desired value. Example:
Code:

delay_us(500);
delay_us(400);

And then email CCS with a full report of these bugs. Tell them that it fails
in both vs. 4.110 and 4.111. If your maintenance period has ended, I
think they will upgrade you to the latest version when they fix it.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 24, 2010 12:45 pm     Reply with quote

Quote:
Is it possible that with the CCS4.109 compiler my 16F1823 device could work?

It could be. These newer chips (16F1xxx) were recently added to the
compiler and CCS always takes several versions to get all the built-in
functions working correctly. I ordered a 16F1827 (I wanted one anyway)
because I couldn't get a 16F1823 in DIP. It has an ADC register map
which is similar to the 16F1823 (just 2-3 bits are different, I think). I'll
try to get the A/D working later in the week when it comes in.
duchonic



Joined: 14 Jul 2010
Posts: 9
Location: Switzerland

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 1:05 am     Reply with quote

This would work:
Code:

  #byte ADCON0 = 0x09D
  ADCON0 = 0b00000001;
  #byte ADCON1 = 0x09E
  ADCON1 = 0b10110000; 
  #byte ANSELA = 0x18C
  ANSELA = 0b00010010;
  #byte ANSELC = 0x18E
  ANSELC = 0b00000011;

unsigned int16 read_a2d(unsigned char channel){

  unsigned int16 ADC_result;

  channel&=0x07;   // truncate channel to 3 bits
   
  #byte ADCON0 = 0x09D
  #byte ADRESH = 0x09C
  #byte ADRESL = 0x09B

  ADCON0=0x01;           // clear current channel select
   ADCON0|=(channel<<2);   // apply the new channel select
   delay_us(10);
  ADCON0|=0x02;   // initiate conversion on the selected channel
  while(BIT_TEST(ADCON0,1))continue;

  ADC_result = 0x0000;
  ADC_result += ADRESH;
  ADC_result <<= 8;
  ADC_result += ADRESL;
 
   return(ADC_result);   // return 16 MSB of the result
}
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