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

mcp 3204 driver

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



Joined: 04 Nov 2012
Posts: 15

View user's profile Send private message

mcp 3204 driver
PostPosted: Sun Mar 17, 2013 9:02 am     Reply with quote

Hi,

I am using driver file of mcp3204 and having some trouble in understanding "read_analog_mcp " function used in it.

Control bits calculated in code is not matching with datasheet for selected channel.

It would be great if you explain me how that control bits are calculated?

Thanks,
paddy
temtronic



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

View user's profile Send private message

PostPosted: Sun Mar 17, 2013 9:24 am     Reply with quote

Whenever I get the 'puzzled look on my face' I end up grabbing a piece of graph paper, pencil and the datasheets.
Starting with say 'select channel 0, single mode' and write down the bit combination required.
Then 'play computer' and go through each step that the driver does.
For every line, put down the results of the action (add,move,shift,etc.).
It help to have the CCS help (F11) open, so you can consult the book for what's happening.

yes, it might take 3 or 4 goes at it, but you'll get a better 'feel' for what the driver programmer did.

I know CCS is quite diligent at fixing up errors or bugs and while I've never used this driver am fairly confident it does work. However if it really doesn't please email them and they will fix it.

hth
jay
paddy



Joined: 04 Nov 2012
Posts: 15

View user's profile Send private message

PostPosted: Sun Mar 17, 2013 9:46 am     Reply with quote

Thanks temtronic for quick reply!!!

I did some similar kind of calculations but failed to get expected results.

Anyways I'll try it again as per your suggestions.

Thanks,
paddy
ckielstra



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

View user's profile Send private message

PostPosted: Sun Mar 17, 2013 10:48 am     Reply with quote

The driver has a file date of 2005 which gives me confidence the driver is OK, otherwise you would be the first to find an error since 8 years. Possible, but small chance.

What is strange about the driver code is that they are preparing the data in reverse order, that is, the first bit to be sent is in the LSB. This requires the channel numbers specified in the function parameter to be reversed. After that they are doing two shift operations to insert space for the mode bit and the start bit.
Would CCS have implemented the transmit function by sending the MSB first, then the whole reverse action wouldn't have been necessary and code would have been shorter too. I don't understand why CCS did choose to do as they did as the transmit function is only called from one place. None-the-less, the code as present looks fine to me and should work.
paddy



Joined: 04 Nov 2012
Posts: 15

View user's profile Send private message

PostPosted: Sun Mar 17, 2013 11:35 pm     Reply with quote

Yeah... You are right ckielstra!!!

I was confused in MSB and LSB part. Now I understood that function.

Thanks a lot.
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