BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Mon Oct 22, 2018 2:16 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: NANO WITH MCP3551
PostPosted: Fri Sep 12, 2014 11:07 pm 
Offline
Citizen

Joined: Thu Feb 06, 2014 7:37 pm
Posts: 19
HELLO:I am using the MCP3551 22 bit ADC with a nano 28 for a project.My code is not yet right,i tried to read the flag status and consider the over flow bits,still not right.Should i see 0 to 2097153 DEC. number as i increase voltage at input???...Here is my simple code,as a test...
Any help with a code example will be great,I need to display DEC number from 0 to 1000000,my ref.voltage is 5.00..thank you much...

VALUE VAR LONG'---DATA FROM ADC---

PAUSE 1000
HIGH P3'---CLOCK PIN---

MAIN:
LOW P11'---CHIP SELECT PIN---
PAUSE 100'---MIN. TIME FOR SAMPLE---
SHIFTIN P12,P13,2,[VALUE.BYTE2,VALUE.BYTE1,VALUE.BYTE0]'---READ IN THREE BYTES---
HIGH P11
HIGH P13
PAUSE 100
SEROUT S_OUT,I9600,[DEC VALUE,13,13]'---DISPLAY THE ADC-DEC VALUE---
PAUSE 1000
GOTO MAIN


Top
 Profile  
 
 Post subject: Re: NANO WITH MCP3551
PostPosted: Sat Sep 13, 2014 3:40 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
To check the status you need to lower CS and then do a GETPIN(SDO). if SDO = 0 means that the AD it is ready. They used the SDO for transfer data to the micro and as a ready status.


Top
 Profile  
 
 Post subject: Re: NANO WITH MCP3551
PostPosted: Tue Sep 16, 2014 5:45 pm 
Offline
Citizen

Joined: Thu Feb 06, 2014 7:37 pm
Posts: 19
hello: i try an if-then command to check for the ready flag...no mater if i pause 100ms or check ready flag my numbers don't add up...for example,my ref voltage is 5.00 volts,my input volts is 1.3 volts,my DEC ADC value should be around 545259,,,right???...i seem to have extra numbers,for example 80374564 or 5678090...that is not right???...it can only go to 2097153 at max volts(5.0) right???...i might not be reading in the 24 bits properly,any suggestions???...thanks...
''''here is my code'''''

VALUE VAR LONG'---DATA FROM ADC---

PAUSE 1000
HIGH P3'---CLOCK PIN---

MAIN:
LOW P11'---CHIP SELECT PIN---
IF IN12 = 0 THEN'---CHECK FOR READY FLAG---
GOTO GET_DATA
ELSE
PAUSE 5
HIGH P11'---MCP3551 MANUAL SAY TO TOGGLE AND RECHECK SDO---
PAUSE 5
GOTO MAIN
ENDIF


GET_DATA:
SHIFTIN P12,P13,2,[VALUE\24]'---READ IN THREE BYTES---
HIGH P11
HIGH P13
PAUSE 100
SEROUT S_OUT,I9600,[DEC VALUE,13,13]'---DISPLAY THE ADC-DEC VALUE---
PAUSE 1000
GOTO MAIN


at 1.2 volts input my output number is---14595---not right???...


Top
 Profile  
 
 Post subject: Re: NANO WITH MCP3551
PostPosted: Tue Sep 16, 2014 7:20 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
I think I tried the shiftin command reading 16 bits and it always come out with bit 9 set. So I decided to write my own input routine.
This will read any bits from any serial device. Just add it to your program and see if it worked for you. Just rename your routine.

What it does it clock the data in by pulsing the clock and then read the data latched at the SDO. Every time that you clocked the data will be latch at the falling edge of the clock. Also you need to add the variable loop at the beginning of the program.

'*******************************************************************************
GET_DATA

'input data from the mc3551
High P13 'clock pin
For loop = 0 to 21 'fetch the 22 bit, msb bit first
pulsout P13,20 'Clock the bit at the output
value =(value * 2) + IN12
Next
High P11 'disable chip
return
'**********************************************************************************


Top
 Profile  
 
 Post subject: Re: NANO WITH MCP3551
PostPosted: Tue Sep 16, 2014 9:09 pm 
Offline
Citizen

Joined: Thu Feb 06, 2014 7:37 pm
Posts: 19
hi: yes i can see what you are doing,that might work. when i try it i get huge numbers like 900 million???...maybe the "value = (value * 2) + in12" ,line???...i played with that statement,i get smaller numbers,but to small,around 1 thousand...i even tried to mask the binary number,still wrong...i have used this chip before,i just test the high value,then minus out to get my max value,it is a bad way to do this,this time i hope with some help from others we can solve this issue???...thanks.


Top
 Profile  
 
 Post subject: Re: NANO WITH MCP3551
PostPosted: Tue Sep 16, 2014 9:52 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
I checked the bits and I overlooked that you need to set the bits count to 23. 23= overflow high , 22= overflow low and 21 sign bit.
Just try increment the counts to 23 and see how the output reading. When you do the *2 your are shifting the values to left one bit. Try first with zero volt input and then a know voltage at the input and see the output reading.
I used this routine for all my inputs. I used the 12 bits A/D that it is a really 12 bits inputs.


Top
 Profile  
 
 Post subject: Re: NANO WITH MCP3551
PostPosted: Tue Sep 16, 2014 9:59 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
I checked the routine and missed the command value = 0 at the beginning of the loop.

Add the command and see how it works.


'input data from the mc3551
value = 0 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this command
High P13 'clock pin
For loop = 0 to 21 'fetch the 22 bit, msb bit first
pulsout P13,20 'Clock the bit at the output
value =(value * 2) + IN12
Next
High P11 'disable chip


Top
 Profile  
 
 Post subject: Re: NANO WITH MCP3551
PostPosted: Wed Sep 24, 2014 4:13 pm 
Offline
Citizen

Joined: Thu Feb 06, 2014 7:37 pm
Posts: 19
HELLO: sorry for the long wait here,I was gone for a week...Well your idea did work,in fact it seems to work very well. I was also able to read in the three bytes like i was doing before. You say to check the ready_bit,that works much better. before i would just wait 100ms then get reading,(may not always be ready),so to check the ready_bit is an improvement.Also i did not clear the stack variable before the next reading,(value = 0),that made a big difference.one programmer suggested value = value&0xffffff i use this sometimes...(value = 0 works best here).. I tried to read all 24 bits at one time,sometime works sometimes don't..well any way i like the way you clock out bit by bit,and you pick the speed,works great thank you for all your help on this..... :D


Top
 Profile  
 
 Post subject: Re: NANO WITH MCP3551
PostPosted: Wed Sep 24, 2014 8:38 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
Glad it worked for you. I used the routine and worked every time. It is a simple routine and you can use it to inputs any size bits.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


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 post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO