|
|
View previous topic :: View next topic |
Author |
Message |
frederic
Joined: 04 Nov 2011 Posts: 4
|
Help! MCP3553 read-out error |
Posted: Fri Nov 04, 2011 2:18 pm |
|
|
Hello...
Here, I am confused about that, with this code i get the data from mcp3553. But values are changing rapidly, thus code doesn't work stable. What may be the problem? Where is my mistake ? And the code as below:
Code: |
#include <18f452.h>
#fuses HS,NOWDT,NOLVP,NOPROTECT,NOBROWNOUT,NOPUT,STVREN,NODEBUG,NOWRT,NOWRTD,NOWRTB,NOWRTC,NOCPD,NOCPB,NOEBTR,NOEBTRB
#use delay(clock=8000000)
#include <lcd.c>
#define MCP_CS PIN_B3
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
int8 byte0,byte1,byte2;
int32 value;
void main()
{
lcd_init();
setup_spi(SPI_MASTER | SPI_MODE_3 | SPI_CLK_DIV_4);
while (true)
{
output_low(MCP_CS);
delay_us(20);
byte0 = spi_read(0x00);
delay_us(20);
byte1 = spi_read(0x00);
delay_us(20);
byte2 = spi_read(0x00);
delay_us(20);
output_high(MCP_CS);
value = make32 (byte0,byte1,byte2);
value = (value>>3);
lcd_gotoxy(1,1);
printf(lcd_putc,"%ld "value);
}
} |
I hope somebody can help me and give a point of view about my problem. Thank you.
Last edited by frederic on Fri Nov 04, 2011 4:48 pm; edited 2 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 04, 2011 4:42 pm |
|
|
There are various problems with your code, but the main one is that
you don't have a delay in your while() loop to allow time for the A/D
conversion. The MCP3553 data sheet says the conversion type can
be 17 ms maximum (16.67 +2%). So you should add a 20 ms
delay statement to the end of your while() loop.
I think there are other minor tweaks that should be made with respect
to power-up time delay, and exit from shutdown mode delay. But if you
add the while() loop delay I think you should see some improvement. |
|
|
frederic
Joined: 04 Nov 2011 Posts: 4
|
|
Posted: Sat Nov 05, 2011 1:51 am |
|
|
Thank you again.
When I turned A/D conversion to 20 ms, it worked. Values become stable. But this time, the last bit of the data changing rapidly and last digit isn't stable now. What causes this reason? And one more thing, it will be more useful if answers are given on the code.
note: Tries are done by using "Proteus". |
|
|
frederic
Joined: 04 Nov 2011 Posts: 4
|
|
Posted: Tue Nov 08, 2011 3:38 pm |
|
|
must be a solution |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 08, 2011 3:39 pm |
|
|
How do you know that Proteus has a correct simulation of the MCP3553 ?
It's possible that you are chasing a Proteus bug.
Post your latest test program. |
|
|
|
|
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
|