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 support@ccsinfo.com

ADC does not work with external reference
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19231

View user's profile Send private message

PostPosted: Sat Jul 29, 2017 8:33 am     Reply with quote

This gets interesting.

I am using an old data sheet, and quite an early chip (may even be an engineering sample - it's what I had on the shelf...). On my data sheet the table is given as:
Code:

Logic State VREF+ VREF-
00 AVDD AVSS
01 AVDD VREF-
10 VREF+ AVSS
11 VREF+ VREF


The chip is dated 2004 B0, and it works with the change....

However on the current errata listings I can't see any change being mentioned to the sheet/registers for this.

Try one other thing I did alter which might also be having an effect:

setup_adc_ports(sAN0|sAN3 ,VSS_VREF);

They mention that ANSEL must be set for the Vref pin, so I had added it to the pins setup in the multiplexer to ensure this.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jul 29, 2017 10:32 am     Reply with quote

MPLAB reports this silicon revision for my 16F917:
Quote:
Device ID Revision = 00000004



Quote:
Try one other thing I did alter which might also be having an effect:
setup_adc_ports(sAN0|sAN3 ,VSS_VREF);

I tried that just now and also earlier. It makes no difference.
The PIC acts like it's always using VDD_VSS.
POPE19



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

PostPosted: Sat Jul 29, 2017 10:47 am     Reply with quote

I am really confused. Ttelmah & PCM Programmer could you please explain.
Ttelmah



Joined: 11 Mar 2010
Posts: 19231

View user's profile Send private message

PostPosted: Sat Jul 29, 2017 12:53 pm     Reply with quote

I have an extremely early (pre release) engineering sample chip (B0), and a paper data sheet that came with this.
PCM_Programmer has a B3 revision chip (the current chip).

His is behaving like yours. Mine is not. On mine the code has to change but it then works. On his (like yours), the chip behaves as if it is using the supply as the reference all the time.

The listed errata, do not mention the ADC anywhere.

Other people have used the ADC with an external Vref, but also with oddities (though the other way round):
<http://www.microchip.com/forums/m220537.aspx>

Another user has it working OK:
<http://www.electro-tech-online.com/threads/cricket-thermostat-kit-concept-16f917-lcd.31994/>

Now these are both using setups that match what CCS is currently doing.

So it should work. The question is what is different?.

One thing is possibly the LCD setup?. Given that the Vref+ pin is segment 15, it is possible that this is interfering somehow.

You are selecting MUX_14, and 0x1E000F for the segments. So segments 0 to 3, then 17 to 20, which looks right.
On two of the other chips, there is the following comment:

Quote:

COM3 and SEG15 share the same physical pin on the PIC16F913/916, therefore SEG15 is not available
when using 1/4 multiplex displays.


Now this shouldn't apply with the 914, but it has me 'wondering' if there is some horrible undocumented internal connection that is causing a problem.

Have you tried actually testing without an LCD?.
Are you testing with an LCD or serial port PCM?.

If you look at the pin diagram for RA3, you can see that the Vref connection is direct, and that the only thing that might cause problems is LCDMODE_EN. If this was enabling the output driver, there would be problems. However you are turning off Seg15...
POPE19



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

PostPosted: Sat Jul 29, 2017 1:25 pm     Reply with quote

Ttelmah, I am checking using LCD. As I said I am newbie I really don't know any other way to check the output of PIC in any other way. But I will really appreciate if you please guide something so that I can use serial port PCM. As it will be beneficial all newbie like me in future. I will try that too and let you know the results without using LCD.

I really appreciate you guys explaining such deeply making a newbie like me easy to understand and learn at same time. Keep it up.

Waiting for your reply.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jul 29, 2017 5:29 pm     Reply with quote

It's this one:
https://www.ccsinfo.com/forum/viewtopic.php?p=75407
Look at the 2nd post from the bottom. It's a bug in set_adc_channel().
Not fixed in 10 years. Probably never reported.

Quote:
........ set_adc_channel(0);
009B: MOVLW 00
009C: MOVWF @78
009D: MOVF ADCON0,W
009E: ANDLW C3
009F: IORWF @78,W
00A0: MOVWF ADCON0

It's clearing VCFG0 in bit 5, turning off Vref+.

To fix it, add this line above main():
Code:
#bit VCFG0 = getenv("BIT:VCFG0")


Then set VCFG0 in code, just after setting the channel:
Code:
set_adc_channel(0);
VCFG0 = 1;  // Enable Vref+. Fix for compiler bug in set_adc_channel(). 

It now works:
Quote:

500
501
500
500
499
500
499
501
499
Ttelmah



Joined: 11 Mar 2010
Posts: 19231

View user's profile Send private message

PostPosted: Sun Jul 30, 2017 12:31 am     Reply with quote

That is interesting. On my chip, that makes it stop working!. It permanently gives 0. It is resulting in the Vref- floating. If I ground the Vref- pin it starts working, but is using Vdd, unless I set VCFG1.
MPLAB reports my revision as 00000001, which according to the current data sheets doesn't exist (the earliest they list is 00000002). Would have to trace my correspondence (physical letters in those days), but I suspect it was an engineering sample.

So a silly error in CCS, that may date from them writing the code for a really early chip, and never revising it to the working chips....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 30, 2017 1:12 am     Reply with quote

I sent off a bug report to CCS support.
POPE19



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

PostPosted: Sun Jul 30, 2017 1:25 pm     Reply with quote

Thanks a lot PCM Programmer & Ttelmah. Can you please suggest something so that i can watch the output of a pic on computer ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 30, 2017 3:31 pm     Reply with quote

POPE19 wrote:

Can you please suggest something so that i can watch the output of a pic
on computer ?

Do you have a DB-9 Com Port connector on your computer ?
Or only USB connectors ?

What PIC development board are you using ? Did you make it yourself
or did you buy it ? If you bought it, post the manufacturer and part number.
POPE19



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

PostPosted: Sun Jul 30, 2017 5:25 pm     Reply with quote

I don't have db9 connector in my computer but I only have USB ports. I am making my circuit on breadboard. Please suggest. I read I have to get rs232 ic for serial connection so I got the hardware circuit but I don't know which software would I use and how to proceed or whether I am going in right direction or not.
temtronic



Joined: 01 Jul 2010
Posts: 9117
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jul 30, 2017 6:08 pm     Reply with quote

What you need is a 'TTL to USB ' adapter module.

I get them for about $2 CDN with free shipping from China. Usually I buy x5 to get a bit of a price break and, well, you always need a spare !!
I've never had a bad one over the years and it's cheaper than buying a PIC with USB and adding parts !

Connections are easy

PIC USB module
Ground Ground
Txd Rxd
Rxd Txd

That's it....

It's best to use the PIC's HW UART, if it has one, otherwise any I/O pin can be used to send data to the PC, CCS makes that EASY !

I cannot buy the PL2303 'USB chip', connector, resistor, PCB for $2 ! NOBODY can, so buy the module. One source is Banggood and they offer free shipping. Any local electronics supplier may have them so check around.

You can use a free 'terminal' program like RealTerm to send/recieve data. There are others but I started using it years ago and,well, it works, so why should I change?

edit: forgot to mention most(all ?) of these TTL<>USB adapter modules have LEDs for both power and data. I unsolder/remove the power LED more so because it's TOO BRIGHT...and it saves power.

edit2: I also now buy RTC/EEPROM modules instead of discrete parts. Again CHEAPER than making it AND the last ones came with RECHARGABLE coin cell batteries !

Hope this helps
Jay


Last edited by temtronic on Mon Jul 31, 2017 5:18 pm; edited 1 time in total
POPE19



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

PostPosted: Mon Jul 31, 2017 5:09 am     Reply with quote

thanks a lot to all of you . PCM Programmer I am getting output with 3.3 V reference as per your suggestion. I am still kind of confused how to display output of a pic on my computer .

Temtronic is there a link where some detailed instructions of what you said is available especially software part . Please suggest .
temtronic



Joined: 01 Jul 2010
Posts: 9117
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 31, 2017 5:19 am     Reply with quote

First, check the FAQ section of the CCS manual! They show code(easy...) as well as how to connect a MAX232 for an 'old' PC with RS232 ports.
While in the manual, lookup 'putc', 'getc',printf, and then other 'blue links' they say are 'related'.
Also look in the 'examples' folder. Most programs will use the PC as a 'display device', and check out code in the 'code library' forum here as well.

Jay
POPE19



Joined: 27 Jun 2017
Posts: 71

View user's profile Send private message

PostPosted: Mon Jul 31, 2017 1:46 pm     Reply with quote

thanks a lot Temtronic. will give a shot once i receive the cable.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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