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

Analog Multiplexing
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
StingzLD



Joined: 18 Jul 2010
Posts: 42
Location: Richmond, VA

View user's profile Send private message

Analog Multiplexing
PostPosted: Sun Aug 15, 2010 9:25 am     Reply with quote

Hey Guys,

I have never used an analog multiplexer before, and I am slightly confused with how you read the individual channels. The chip I am using is the MAXIM DG406 (Click for datasheet). I understand that you have to send an address to select which channel you want to read. What I am confused about is how does my MCU read that? The datasheet is pretty vague about everything. Take a look at this Functional Diagram:



According to this, one end of the switch is connected to Sx, and the other end is connected to D. According to the Pin Configuration below, there is not another pin left behind to be connected to the MCU.



Am I suppose to connect these switches from Sx to D and have the MCU read from D? Or am I suppose to connect them from Sx to ground and still have the MCU read from D? I am assuming D is the correct pin to read from since it is the only Output on the entire chip.

Thanks in advance!
Jerson



Joined: 31 Jul 2009
Posts: 126
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Sun Aug 15, 2010 9:43 am     Reply with quote

The Sx line which is selected will connect to D. How do you select this? That is done by jamming an address on the Ax lines. When the EN signal is set to logic '1' (Vcc) level, the addressed switch connects to D. Since you have jammed the address from your micro, you know which line is selected and there is no need to read that back in.

The truth table in the datasheet should clarify which switch connects on which address code.

I hope I've been able to help you here.
_________________
Regards
Jerson Fernandes
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 9:57 am     Reply with quote

1) All your analog signals should be wired to S1..S16
2) The MCU AD input wired to the MPX output D
3) A0.. A3 and EN wired to MCU pins configured as outputs

To capture an analog input through the MPX:
1) Init A0.. A3=0 and EN=1
2) Select the desired input to convert with A0.. A3
3) Set EN=0 (add a delay of 1 uS to settle, -see datasheet P4 )
4) Get the analog value with the MCU, until the flag set telling that the AD convertion was done.
5) Set EN=1

and you get it !!!

Humberto
StingzLD



Joined: 18 Jul 2010
Posts: 42
Location: Richmond, VA

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 10:25 am     Reply with quote

I know all of the signals are wired to S1 -> S16, but what I am unsure about is where the other end is suppose to be connected; Ground?

And that is definitely a big help with how to actually read the analog input. But I am still new to C and have not done this before, so could you help me by explaining how you actually get the analog value? I am assuming you would do this by using the read_adc() command? And if so, how could I use this (for future reference) if I wanted to remove a sensor and put in a switch instead? Just say if there is any voltage at all then the switch is closed? As for the flag being set, I don't exactly know much about flags yet. Only going on a month now with teaching myself C.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 1:14 pm     Reply with quote

The multiplexer is NOT an A/D converter. Analog signal sources connect to the Sx lines and the D line connects to an A/D built into the uC or that you provide.
_________________
The search for better is endless. Instead simply find very good and get the job done.
StingzLD



Joined: 18 Jul 2010
Posts: 42
Location: Richmond, VA

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 2:03 pm     Reply with quote

Quote:
SherpaDoug
The multiplexer is NOT an A/D converter. Analog signal sources connect to the Sx lines and the D line connects to an A/D built into the uC or that you provide.


I know that much. I was simply asking if I need to use read_adc() to read the output from the MUX that's going into the ADC on the MCU or not. Like I said, I have never done this before and am new to C; but I do know the difference between a MUX and an ADC. I am just asking nicely for some help and if this is the correct way to do it or not. If it's not (which judging from your reaction I would assume it is not), could you provide me with the correct way to read the output from the MUX with the MCU? I really am lost in the Amazon here considering the datasheet doesn't specify how to attain what you need from the MUX. Humberto sure gave me a good head start, but not knowing how to do Step 4 in his post leaves me slamming into a tree like George on his vine.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 2:59 pm     Reply with quote

Well, I assume that you would understand the meaning of
Quote:

4) Get the analog value with the MCU, until the flag set telling that the AD convertion was done.

It was my fault because you got this phrase literally, hence it is confused.

You did not mention what MCU are you using, but for reference purposes let see the PIC16F877 datasheet:
http://ww1.microchip.com/downloads/en/devicedoc/30292c.pdf
Chapter 11.0 Analog-to-Digital converter Module

At the end of an AD convertion, bit2 in the ADCON0 Register is cleared in order to inform that the convertion
task has finished and that the result (digital equivalent value) is available in the AD Result AD Registers.

bit 2 GO/DONE: A/D Conversion Status bit
1 = A/D conversion in progress (setting this bit starts the A/D conversion)
0 = A/D conversion not in progress (this bit is automatically cleared by hardware when the A/D conversion is complete)


Regarding my previous post, replace the step 4 for this:
4) Get and store the ADC.

The compiler handle this for you automatically, (you don't need to fight with flags and registers)
and leave the AD result in a variable called -for example- value
Code:

value = read_adc();


Quote:

But I am still new to C and have not done this before,

This is not a fault, most of us were in the same level, but you will know that the learning curve must have
small steps begining from basic concepts, lets assume that this project it is not a basic concept hence it
is not the best way to start with.
I would suggest you to start learning how to get an AD value starting with a 5K linear potentiometer wired
to A0 until you get the basic skills working with 8/10-bit results, scaling the converted value, learning
how to filtering/averaging values, learning to use MPLAB or another tool that will help you debugging,
before to follows with a project like this.

Humberto
StingzLD



Joined: 18 Jul 2010
Posts: 42
Location: Richmond, VA

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 3:57 pm     Reply with quote

Well it wasn't a fault on your part. I can take the blame for this since I didn't express my novice experience from the beginning.

I didn't mention a specific MCU because I thought that all PIC MCUs reacted the same with ADC, so this was once again my fault. The MCU I am using is the PIC16F684.

And I didn't realize that I was making such a big jump into this. I figured that using ADC was the same all around no matter if the application is with a pot, temp sensor, or an analog MUX. But I will definitely start small like you say and take it from there. Hopefully I can figure this out relatively easily. Thanks for all of your help! You were very calm and patient in helping me with my inexperience in all of this. If I get lost along the way, I will tack on another post to this thread.

Thanks again! Very Happy
StingzLD



Joined: 18 Jul 2010
Posts: 42
Location: Richmond, VA

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 7:52 pm     Reply with quote

So I started writing some code to see if I could get this to work, and then headed on over to MPLAB to try my hand at watching the ADC values change in debug mode. I successfully got the project to build and program to my chip. But when I try to enter debug mode, I get this error message:

Quote:
PK2Error0024: PICkit 2 was unable to establish a valid Vdd on the target (Attempted 5.00V - Read 0.00V)


How is it that I can successfully load and run my program on the chip, yet I cannot successfully establish a valid Vdd? I find this very odd considering the fact you have to have a valid Vdd in order to program and run the chip and the fact that the last time I used MPLAB (which was probably 6 months ago) I was able to go into debug mode no problem. Anybody have any thoughts on this?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 8:15 pm     Reply with quote

The best thing to do is to use Google to search the Microchip forums.
Use this search string:
Quote:

site:microchip.com/forums PK2Error0024

If that doesn't help, read the PicKit2 FAQ and other posts on the PicKit2
forum:
http://www.microchip.com/forums/f15.aspx
StingzLD



Joined: 18 Jul 2010
Posts: 42
Location: Richmond, VA

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 9:16 pm     Reply with quote

So I read the relevant material, but I guess I should have mentioned one thing first. I do not actually have the PICkit 2. I have an equivalent programmer from http://www.piccircuit.com, the ICP01. The general consensus I am getting is that I need an ICD Header, and then it goes on about having the correct specification and so on. I find this odd that I have never had to use one in the past, that is until I downloaded the new version of MPLAB when I got CCS. I am wondering if there is a problem with CCS not finding the USB Programmer rather than MPLAB since MPLAB can program my chip successfully and MPLAB is using CCS to build and compile everything. I did notice that when I looked at the compiler again that I do not see anything relating to the PICkit 2. And if I click on Debug in the CCS compiler, it tells me:

Quote:
Could not open the USB port. Device not found.


When I go to step two of the Diagnostics for this, it tells me:

Quote:
Current ICD type does not support this operation.


The same goes for the rest of the steps in the Diagnostics. I find this quite odd considering MPLAB tells me everything that the CCS Diagnostics is trying to check but says isn't supported. After having this occur, I went to the main CCS site and downloaded every update there was to download, especially the USB Drivers. I am still having the same problem. Is there some step that I am missing in trying to get the CCS compiler to recognize my programmer like the MPLAB IDE does? And why is it that MPLAB recognizes it and can program with it, but it can't enter debug mode like it used to do before I started using CCS? I have tries searching online for help with this, but so far I have not seen anything that is actually relevant to my situation. I am hoping that somebody can speak from experience or at least have a really good guess. Maybe someone from CCS is reading the forum and can tell me why this is.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 15, 2010 10:12 pm     Reply with quote

But the CCS IDE and MPLAB are two different products. CCS has their
own line of debuggers that they want you to buy. They do have support
for some Microchip debuggers/programmers, but not all. I don't see
the Pickit2 in their list:
http://www.ccsinfo.com/faq.php?page=icd2_real_ice

According to this Pickit 2 page here, devices marked with an asterisk
require the ICD header to do debugging. The 16F688 has an asterisk.
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en027813

Debugging and programming are not the same thing. Debugging involves
stepping through code, looking at register values in a watch window,
setting breakpoints, letting the program run to the breakpoint, etc.
It's quite different than simple programming, and in MPLAB, these two
operations are done in different menus. I suspect that your earlier work
with the 16F688 consisted of programming only, or if you were debugging,
then it was done with a different series of PIC.
StingzLD



Joined: 18 Jul 2010
Posts: 42
Location: Richmond, VA

View user's profile Send private message

PostPosted: Mon Aug 16, 2010 7:51 pm     Reply with quote

See that's the thing, I have only been working with the exact same PIC. I got started with PIC through contacting an author from N&V, and he said I should start with PICs and told me to start with the PIC16F684. And since then, that is the only PIC that I have ever worked with/had in my inventory. So the possibility of a different PIC series is out of the question. And I know the difference between programming and debugging. And you are correct that my PIC (although it is different than what you stated) is said to require the ICD header in order to debug. But like I said before, I was able to debug with it no problem. I was able to look at my values in the Watch window and see how they changed with me stepping through the program from breakpoint to breakpoint. I just find it quite odd that all of the sudden after I installed the CCS compiler I can no longer do that in MPLAB as I have done before with the exact same chip and the exact same programmer. There has to be some kind of correlation to this happening is all I am saying. I am just curious as to what this is because debugging is a big part of exploring how things are really happening instead of what you think is happening. And without debugging, I am kind of stuck in rut for the moment.

***By all means, I am not trying to bash you in any way, shape, or form. You are incredibly more intelligent than I am. And I can see that from you helping me before and helping many other people in the forum, and I greatly appreciate your help to an extent that you may not know. I am just saying that there is something really weird going on that I don't think anybody has experienced before. And I know that CCS and MPLAB are two different products; I am just trying to figure out why MPLAB would let me debug before I got CCS, and why all of the sudden I cannot because I have CCS and the two are linked together.***
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Aug 16, 2010 11:17 pm     Reply with quote

StingzLD wrote:

***I am just trying to figure out why MPLAB would let me debug before I got CCS, and why all of the sudden I cannot because I have CCS and the two are linked together.***


Did you install the MPLAB "freebie" CCS Compiler? The overwrite may have narfed something up. Maybe a good idea to start from scratch.

Then, the order of operations are *ROUGHLY* that when installing CCS, there's a "plug in" that installs into the MPLAB directory that tells MPLAB about using CCSC.exe as a plug-in compiler. (just like Hi-Tech or C18/C30/C32 and so forth).

Something may have mucked up the install. but Debug SHOULD work.

Usually in MPLAB (which is *all* I use with CCS (PCB, PCM, PCH, PCD)) I hard set in my code the #fuse DEBUG or NODEBUG.

Then I compile
THEN I set MPLAB to debug mode.

And then program the IC and off I go.

MAKE SURE MPLAB loaded the debug exec on program.

Let us know if you're still narfed up.

Also try cleaning your project dir.. sometimes the project files in MPLAB get screwed up and cause a little chaos.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
StingzLD



Joined: 18 Jul 2010
Posts: 42
Location: Richmond, VA

View user's profile Send private message

PostPosted: Wed Aug 18, 2010 5:44 pm     Reply with quote

So I am still getting the same error message, and I do not know why. May I ask what you are using to program and debug your chips? Are you using a PICkit 2 with the ICD header? I ask because when I looked at the PICkit 2 Header Specification on page 7 and 10, it is saying that I need the AC162055 for my PIC16F684. And as I have said earlier, I have never had to use one before; and I have been using this same chip the whole time. Is this something new? I am not sure what is going on, but it is confusing the hell out of me.

Maybe I should just switch to a chip that doesn't need the header and has a lot more pin and gadgets than mine. Any objections to me ordering a couple PIC16F887s? Or is there a better suited chip out there? I just picked this one because it is loaded and seems to be a widely used chip, especially considering it is a direct replacement for the x877 (which I didn't realize until I went to look at it at Microchip and they are telling you to get the x887 instead). I am hoping that by switching to a chip that requires no header that I will be able to debug freely again.
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 1, 2  Next
Page 1 of 2

 
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