View previous topic :: View next topic |
Author |
Message |
paddy
Joined: 04 Nov 2012 Posts: 15
|
mcp 3204 driver |
Posted: Sun Mar 17, 2013 9:02 am |
|
|
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
|
|
Posted: Sun Mar 17, 2013 9:24 am |
|
|
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
|
|
Posted: Sun Mar 17, 2013 9:46 am |
|
|
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
|
|
Posted: Sun Mar 17, 2013 10:48 am |
|
|
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
|
|
Posted: Sun Mar 17, 2013 11:35 pm |
|
|
Yeah... You are right ckielstra!!!
I was confused in MSB and LSB part. Now I understood that function.
Thanks a lot. |
|
|
|