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 support@ccsinfo.com

Some problems to create a virtual table

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



Joined: 03 Feb 2012
Posts: 4

View user's profile Send private message

Some problems to create a virtual table
PostPosted: Sat Feb 18, 2012 12:47 pm     Reply with quote

Hey everybody !

I have a small problem I need your help. I need to create a virtual table in a PIC18F4580, globally receive information with my MUX (8 inputs coded into 8bits analogical information). And with my PIC18F4580 I choose each IN (from IN1 to IN8) from my MUX (MCP508), then each information need to be converted into Digital and put in a virtual table. But I don't know to create it, or how it works. I've never done that.

Here is my main program until yet :
Code:

#include<18F4580.h>
#use delay (clock=4000000)

#define A0 PIN_A0
#define A1 PIN_A1
#define A2 PIN_A2
#define SS PIN_A6  // this introduce my TLC3545 to start the conversion

int a;

Void main(void)
// décodage 8 entrée analogique
{     

while(a<8)
{
output_low(A0);  // the different output value allowed to choose different IN on the MULTIPLEX  for example the adress is A0=A1=A2= 0 so it select IN1
output_low(A1);
output_low(A2);
delay_ms(2);     
output_low(SS);
delay-ms(2);
}

{
output_high(A0); // and  if the adress is  A0=1 ; A1=A2=0 so  @=1  it  select  IN2 and it continu until IN8
output_low(A1);
output_low(A2);
delay_ms(2); 
output_low(SS);
delay-ms(2); 
}

{
output_low(A0);
output_high(A1);
output_low(A2);
delay_ms(2);   
output_low(SS);
delay-ms(2);
}

{
output_high(A0);
output_high(A1);
output_low(A2);
delay_ms(2);
output_low(SS);
delay-ms(2);   
}

{
output_low(A0);
output_low(A1);
output_high(A2);
delay_ms(2);
output_low(SS);
delay-ms(2);   
}

{
output_high(A0);
output_low(A1);
output_high(A2);
delay_ms(2);
output_low(SS);
delay-ms(2);   
}

{
output_low(A0);
output_high(A1);
output_high(A2);
delay_ms(2);   
output_low(SS);
delay-ms(2);
}

{
output_high(A0);
output_high(A1);
output_high(A2);
delay_ms(2);   
output_low(SS);
delay-ms(2);
}
}


Please help me !
_________________
Impossible is nothing
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

Virtual table
PostPosted: Sun Feb 19, 2012 2:36 am     Reply with quote

Hi.

You've had lots of views and no response.

It could be that nobody understands your question.

It seems silly to me that you generated code without much idea of where you were going.

I, for one, do not know what you mean by a virtual table.

Perhaps you could enlighten me?

Mike
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Feb 19, 2012 3:54 am     Reply with quote

It seems like the OP wanted to say that he has no clue how to operate the TLC3545 SPI interface, because there's only an output_low(SS) statement, but no 16 Bit SPI read and output_high(SS) afterwards.
Stiffyisworking



Joined: 03 Feb 2012
Posts: 4

View user's profile Send private message

PostPosted: Sun Feb 19, 2012 8:45 am     Reply with quote

FvM wrote:
It seems like the OP wanted to say that he has no clue how to operate the TLC3545 SPI interface, because there's only an output_low(SS) statement, but no 16 Bit SPI read and output_high(SS) afterwards.

That's it ! I really have no clue how to operate the SPI interface of my TLC3545.
My PIC18f4580 as 3 different pins that I want to to use, but I'm not sure that it's done.

I have the : -SDO that is connected to the SOD of my TLC3545
-SCL that is connectec to the SCLK of my TLC3545
-But where does the SDI of my PIC go ? because I think that normally the SOD of my TLC3545 must be connected to that no ?

And then read the SDI pin ?

So if for one instruction for example I should do that is it ok ?
Code:

#include<18F4580.h>
#use delay (clock=4000000)

#define A0 PIN_A0
#define A1 PIN_A1
#define A2 PIN_A2
#define SS PIN_A6

int a ;

Void main(void)
{     

while(a<8)
{
output_low(A0);
output_low(A1);
output_low(A2);
delay_ms(2);     
output_low(SS);
delay-ms(2);
             
                             // HERE is the problem I don't know how to make the PIC read the data that comes from my TLC3545

output_high(SS);   // AD Chip select high to stop AD sending
 
return result;
}

Have you some idea ? Please can you give me an example because I'm a little confused.
_________________
Impossible is nothing
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Feb 19, 2012 10:27 am     Reply with quote

SDO of the ADC has to be connected to SDI of the PIC, the PIC SPI clock output pin is named SCK. When using the hardware SPI interface, SDO has to be reserved as well, although not used with TLC3545. For the chip select function (SS at the ADC) any PIC pin can be used, not necessarily SS.

Alternatively CCS software SPI mode can be used with any combination of pins, but it's slower than hardware SPI.

Examples for SPI operation can be found with the CCS compiler, e.g. in the various SPI device drivers.
Stiffyisworking



Joined: 03 Feb 2012
Posts: 4

View user's profile Send private message

PostPosted: Sun Feb 19, 2012 12:36 pm     Reply with quote

Code:

#include<18F4580.h>
#use delay (clock=4000000)

#define A0  PIN_B0   
#define A1  PIN_B1 
#define A2  PIN_B4 

#define SDO PIN_C5   //SPI_OUT     RC5_bit     /* Define SPI SDO signal to be PIC port RC5 */
#define SDI PIN_C4   //SPI_IN      RC4_bit     /* Define SPI SDI signal to be PIC port RC4 */
#define SCL PIN_C3   //SPI_CLK     RC3_bit     /* Define SPI CLK signal to be PIC port RC3 */
#define SS  PIN_A5   //SPI_CS      RA5_bit     /* Define SPI CS signal to be PIC port RA5 */

int a;

Void main(void)
{     

while(a<8)
{
output_low(A0); 
output_low(A1); 
output_low(A2);
delay_ms(2);       

output_low(SS);  // Falling Edge enable the CS input initiates the cycle.
delay_ms(2);

setup_spi(spi_master |spi_l_to_h | spi_clk_div_16 );

( !spi_data_is_in() && input(PIN_C4) );

if( spi_data_is_in() )
   SPI_READ (SDI);

output_high(SS); // AD Chip select high to stop AD sending.

}
}


If I do that is that RIGHT ?
_________________
Impossible is nothing
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Feb 19, 2012 4:50 pm     Reply with quote

Two comments:
- setup_spi() needs to be performed only once at the begin of the application.
- A SPI master don't need to use spi_data_is_in(). It only should do two calls of spi_read(). All necessary timing is done inside the function. Then the bytes can be assembled by make16().
Code:
int8 bh,bl;
int16 result;
output_low(SS);
// no delay required
bh=spi_read();
bl=spi_read();
// shift right to get a 14-bit value
result = make16(bh,bl)>>2;
output_high(SS);
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