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 CCS Technical Support

Multiplexing PCM data from 2 channels A/D CHANNEL (SOLVED)
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
juanodiy



Joined: 07 Sep 2012
Posts: 17

View user's profile Send private message

PostPosted: Tue Sep 11, 2012 12:44 am     Reply with quote

Quote:

Using SPI, you could use a single other line as a 'A/B' identifier, and change this according to which channel you are sending, allowing the slave device to always 'know' which channel it is receiving.


This is very interesting, I'm doing this but with a counter in the slave, every arrives byte is counted, but is not very efficient I think, if you can help with this part, I will be very happy , thanks very much for the observation
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Tue Sep 11, 2012 2:55 am     Reply with quote

The problem is not 'efficiency', but if the slave wakes out of sync with the master, or a transaction is missed, the channels will be swapped....
Only an 'overview', but hopefully will give you some ideas:
Code:

//in both master and slave
#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)

//master
#define ABselect PIN_xx //set to suit your hardware
#define CSoutput PIN_yy //again set to suit your hardware connects to SS
//input on slave
    int1 channel=0;
    int8 val;
    setup_spi(SPI_MASTER,|SPI_CLK_DIV_4|SPI_MODE_0);
    //obviously need your ADC configuration etc. here
    set_adc_channel(channel)
    output_high(CSoutput);
    delay_us(13);

    do {
        read_adc(ADC_START_ONLY); //start the ADC reading
        set_adc_channel(channel^1); //swap ADC channels
        output_bit(ABselect,channel); //output bit to say which channel
        //Now wait for the ADC to complete
        while (!adc_done()) ;
        //ADC starts acquiring the new channel _immediately_ here
        val=read_adc(ADC_READ_ONLY); //read the value
        output_low(CSoutput);
        spi_write(val);
        output_high(CSoutput);
        channel^=1; //toggle channel
        delay_us(5); //ensure acquisition has completed
    } while(TRUE);

//slave
#define ABinput pin_zz //again set to suit your input, connected to ABselect
    int1 channel=0;
    int8 val[2];
    setup_spi(SPI_SLAVE,|SPI_MODE_0);
    do {
        //wait for byte from master
        while (!SPI_DATA_IS_IN) ;
        channel=input(ABinput);
        val[channel]=spi_read();
        //then process the data
    } while(TRUE);


Not complete, and probably with some errors, but hopefully will give you some ideas. Note the 'overlapping' of jobs. While the ADC is acquiring, I get on doing some other things, including selecting the next channel, which means the ADC will begin Tacq, as soon as the reading is complete.

Best Wishes
juanodiy



Joined: 07 Sep 2012
Posts: 17

View user's profile Send private message

Greats
PostPosted: Wed Sep 19, 2012 10:08 pm     Reply with quote

Thanks to all, in special to Ttelmah, I can do it finally , I learn so much with this, and Ttelmah you are a genius man, really you are a master, thank you very much for your help, and thanks to the forum.
Quote:

Not complete, and probably with some errors, but hopefully will give you some ideas.


many ideas, your awesome man, thank you.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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