Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
kramer3d
PostPosted: Apr 20, 2012 - 01:48 AM
Newbie


Joined: Apr 06, 2012
Posts: 5


Can the ADC interrupt when in TX BUSY state when using the wireless peripheral on board??
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Apr 20, 2012 - 05:38 AM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4865
Location: San Jose, CA

TX_BUSY is a state of the transmitter, it does not affect other MCU functions.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
kramer3d
PostPosted: Apr 20, 2012 - 06:55 AM
Newbie


Joined: Apr 06, 2012
Posts: 5


Thanks for your reply. I'm currently trying to sample a signal using the ADC on one ATMEGA128RFA1 and sending the data via the transceiver to another ATMEGA128RFA1. The problem I'm having is that when I load the framebuffer, the ADC does not sample during that time. So the signal I am receiving looks like a chopped up sine wave rather than a smooth one. I am not sure how to work around this issue. (I'm using the fastest ADC and RF transmit rate)
 
 View user's profile Send private message  
Reply with quote Back to top
dak664
PostPosted: Apr 20, 2012 - 12:22 PM
Posting Freak


Joined: Jun 15, 2008
Posts: 1762
Location: North Carolina USA

Probably the code is disabling interrupts when loading the frame buffer. If you start transmission and then load the frame buffer a long interrupt could be a problem. Load frame buffer first and no need to disable interrupts.
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Apr 20, 2012 - 04:21 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4865
Location: San Jose, CA

Show your code, writing a frame buffer is just like writing a register, it can't block interrupts.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
kramer3d
PostPosted: Apr 20, 2012 - 06:49 PM
Newbie


Joined: Apr 06, 2012
Posts: 5




Here is the output graphed in MATLAB.
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Apr 20, 2012 - 07:00 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4865
Location: San Jose, CA

What makes you think this code would give the result you need? sendFrame() takes a long time to execute (busy wait for a state change, etc), you'll definitely miss some samples.

What you need to do is organize FIFO buffer and run two processes at the same time: ADC writes samples to FIFO as they appear (minimizing the amount of time spent in the ISR) and another process takes them out of FIFO, packs them into a frame and sends this frame.

While frame is filling FIFO will be empty most of the time, when transmission starts FIFO will be filling with the new data and once frame is sent FIFO will be emptied into TX buffer and so on.

Now if you could get your FIFO not to overflow, it will tell you that radio throughput is suitable for the application, otherwise - there is not much you can do.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
alexru
PostPosted: Apr 20, 2012 - 07:00 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4865
Location: San Jose, CA

PS: Separate your sending and receiving device code into two different files.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
kramer3d
PostPosted: Apr 20, 2012 - 07:55 PM
Newbie


Joined: Apr 06, 2012
Posts: 5


I used a swing buffer in the code I posted earlier by switching between 2 buffers. I thought it would be sufficient for transmitting all the ADC values. I have attempted to move the sendFrame from the ADC ISR to the main and setting a flag in ADC ISR to send the frame but I am not able to get transmission from the Atmega128

ADC ISR
Code:

ISR(ADC_vect)
{
   PORTF ^= (1 << PORTF5);
   low  = ADCL;
   high = ADCH;

       if(togglebuffer) {
         
            adcbuffer1[adcbuffercounter++] = high;//tempadccounter++;// high;
            if(adcbuffercounter >= ADCVALUESTRANS) {
               
                togglebuffer = 0;
                adcbuffercounter = 0;
            sendBuffer1 = 1;
            sendBuffer2 = 0;
            //PORTF |= (1 << PORTF6);
                //sendFrame(adcbuffer1);
            //PORTF &= ~(1 << PORTF6);
                //TRX_STATE = CMD_TX_START;
                  
            //}
            //else {
                //ADCSRA |= (1 << ADSC);
            }
       }
       else {
         
            adcbuffer2[adcbuffercounter++] = high;//tempadccounter++;// high;
            if(adcbuffercounter >= ADCVALUESTRANS){
               
                togglebuffer = 1;
                adcbuffercounter = 0;
            sendBuffer2 = 1;
            sendBuffer1 = 0;
                // SEND BUFFER
                  
                  
            //PORTF |= (1 << PORTF6);
                //sendFrame(adcbuffer2);
                //
            //PORTF &= ~(1 << PORTF6);
            //TRX_STATE = CMD_TX_START;
                  
            //}
            //else{
                //ADCSRA |= (1 << ADSC);
            }
       }
      ADCSRA |= (1 << ADSC);




TRANSMITTER MAIN

Code:

#if DEVICE == TRANSMITTER
 ADC_Init();

 uint8_t counter = 0;
 uint8_t j;
 while (1)
 {
    if(sendBuffer1){
       sendFrame(adcbuffer1);
       TRX_STATE = CMD_TX_START;
       while(txWaitInt);
       sendBuffer1 = 0;
    }
    else if(sendBuffer2){
       sendFrame(adcbuffer2);
       TRX_STATE = CMD_TX_START;
       while(txWaitInt);
       sendBuffer2 = 0;
    }

 }
 
 View user's profile Send private message  
Reply with quote Back to top
alexru
PostPosted: Apr 20, 2012 - 08:03 PM
Raving lunatic


Joined: Apr 15, 2009
Posts: 4865
Location: San Jose, CA

You need to perform simple test: check if previous buffer is sent by the time you are switching to a new one. I bet it is not.

100 samples at the sample rate of 100000 samples/sec will be filled in 1 ms. This is might not be enough to send a frame.

_________________
The opinions and views expressed by me on this forum are my own and do not represent my employer or anyone else that I’m affiliated with.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits