|
|
View previous topic :: View next topic |
Author |
Message |
bertronicom Guest
|
urgent please (Microchip SPI A/D MCP3202) |
Posted: Thu Aug 21, 2003 1:03 pm |
|
|
I have got in the screen of the digital analizer the signals CLK and CS as above in the datasheet, but output always is null.
I'm using 18F452 40Mhz with CCS PCW 3147.
Can you help me please? thanks in advance
void Conv_AD_SPI () {
Output_high ( ADC_RUN );
delay_us ( 5 );
Output_Low ( ADC_CLK );
Output_Low ( ADC_RUN );
for ( Ciclos=0x00 ; Ciclos<17 ; Ciclos++ ) {
Output_high ( ADC_CLK );
delay_us ( 150 );
Output_low ( ADC_CLK );
delay_us ( 150 );
shift_left(&AD_Data, 2, input(PORT_ADC));
}
AD_Data &= 0x0fff;
Output_high ( ADC_RUN );
Output_low ( ADC_CLK );
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517134 |
|
|
Sherpa Doug Guest
|
Re: urgent please (Microchip SPI A/D MCP3202) |
Posted: Thu Aug 21, 2003 2:10 pm |
|
|
:=I have got in the screen of the digital analizer the signals CLK and CS as above in the datasheet, but output always is null.
:=I'm using 18F452 40Mhz with CCS PCW 3147.
:=Can you help me please? thanks in advance
:=
:=void Conv_AD_SPI () {
:= Output_high ( ADC_RUN );
:= delay_us ( 5 );
:= Output_Low ( ADC_CLK );
:= Output_Low ( ADC_RUN );
:= for ( Ciclos=0x00 ; Ciclos<17 ; Ciclos++ ) {
:= Output_high ( ADC_CLK );
:= delay_us ( 150 );
:= Output_low ( ADC_CLK );
:= delay_us ( 150 );
:= shift_left(&AD_Data, 2, input(PORT_ADC));
:= }
:= AD_Data &= 0x0fff;
:= Output_high ( ADC_RUN );
:= Output_low ( ADC_CLK );
First try using the PIC to set those lines high and low to make sure there is no hardware problem. Then make sure they are properly declared. Without posting your initialization code (fuses, includes, defines, etc.) it is hard for us to help you.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517137 |
|
|
bertronicom Guest
|
Re: urgent please (Microchip SPI A/D MCP3202) |
Posted: Thu Aug 21, 2003 2:15 pm |
|
|
:=:=I have got in the screen of the digital analizer the signals CLK and CS as above in the datasheet, but output always is null.
:=:=I'm using 18F452 40Mhz with CCS PCW 3147.
:=:=Can you help me please? thanks in advance
:=:=
:=:=void Conv_AD_SPI () {
:=:= Output_high ( ADC_RUN );
:=:= delay_us ( 5 );
:=:= Output_Low ( ADC_CLK );
:=:= Output_Low ( ADC_RUN );
:=:= for ( Ciclos=0x00 ; Ciclos<17 ; Ciclos++ ) {
:=:= Output_high ( ADC_CLK );
:=:= delay_us ( 150 );
:=:= Output_low ( ADC_CLK );
:=:= delay_us ( 150 );
:=:= shift_left(&AD_Data, 2, input(PORT_ADC));
:=:= }
:=:= AD_Data &= 0x0fff;
:=:= Output_high ( ADC_RUN );
:=:= Output_low ( ADC_CLK );
:=
:=First try using the PIC to set those lines high and low to make sure there is no hardware problem. Then make sure they are properly declared. Without posting your initialization code (fuses, includes, defines, etc.) it is hard for us to help you.
:=
:=
I mean that the signals are properly from the hardware inputs in the a/d converter i have got verification by mean logic analizer.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517138 |
|
|
ryoung Guest
|
Re: urgent please (Microchip SPI A/D MCP3202) |
Posted: Thu Aug 21, 2003 2:56 pm |
|
|
I have modified some of the routines from the CCS examples for another project and they work OK with PIC16F877A and PIC16F73s
I've used this at 4MHz and 20MHz with xtals and ceramic resinators (all for combinatinos).
I have fast_io enabled for all my I/O lines.
Rob Young
rwyoung@ieee.org
/**********************************************************
* int16 read_mcp3202(int8 channel)
*
* Purpose : Sample data from 2 channel ADC. ADC is 12-bits, unipolar.
* Parameters : channel - 1 or 2
* Calls : write_spi_byte()
* read_spi()
* Returns : Value read from ADC. Return data is LSB justified in 16 bits
* Notes :
* Tested : 02/03 RWY
**********************************************************/
int16 read_mcp3202(int8 channel)
{
int8 ctrl_bits;
int8 high;
int8 low;
output_low(SPI_CLK);
output_high(SPI_DIN);
output_low(ADC_CS);
if (channel==1)
ctrl_bits = 0b00001011; // channel 1 single ended
else
ctrl_bits = 0b00001111; // channel 2 single ended
write_spi_byte(ctrl_bits, 5); // send control bits (4 bits plus dummy clock)
high = read_spi(4);
low = read_spi(8);
output_high(ADC_CS);
return ( make16(high,low));
}
/**********************************************************
* void write_spi_byte(int8 data, int8 num_bits)
*
* Purpose : Write upto 8 bits of data to SPI device. SPI device chip select
* must be activated prior to calling this subroutine.
* Parameters : data - data to write
* num_bits - up to 8 bits
* Calls :
* Returns : none
* Notes :
* Tested : 02/03 RWY
*********************************************************/
void write_spi_byte(int8 data, int8 num_bits)
{
int8 i;
delay_us(1);
for(i=0;i<num_bits;i++)
{
output_low(SPI_CLK);
if ((data & 1) == 0)
output_low(SPI_DIN);
else
output_high(SPI_DIN);
data = data >> 1;
delay_us(1);
output_high(SPI_CLK);
delay_us(1);
}
}
/**********************************************************
* int8 read_spi(int8 num_bits)
*
* Purpose : Read upto 8 bits of data from SPI device. SPI device chip
* select must be activated prior to calling this subroutine.
* Parameters : num_bits - up to 8 bits
* Calls :
* Returns : data read from SPI device.
* Notes :
* Tested : 02/03 RWY
*********************************************************/
int8 read_spi(int8 num_bits)
{
int8 i;
int8 data;
data=0;
for(i=0; i<num_bits; i++)
{
output_low(SPI_CLK);
delay_us(1);
shift_left(&data,1,input(SPI_DOUT));
output_high(SPI_CLK);
delay_us(1);
}
return (data);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517139 |
|
|
|
|
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
|