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

Ttelmah's MAX3100 Driver[LOCATED...not crying wolf...really]
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Mon Oct 15, 2007 6:25 pm     Reply with quote

I think I've finally found the problem. It appears that the IRQ line may not be returning High fast enough for the code as written. When I add the 50uS delay just prior to the while statement everything works as advertised. By tracking the trips through the interrupt and loop, I figured out without the delay, extra trips were being made. I tried reducing the pull-up on the IRQ to 4.7K (originally 47K, then 10K) and it didn't appear to have any effect. (IRQ trace is 8mils and approximately 5 inches long.)

So, I guess the question is.... Is that a plausible explanation? (Did you experience any similar issues?)

Is a 50uS delay in an ISR an acceptable solution?

Code:
#INT_EXT3 NOCLEAR //Interrupt from local radio Maxim chip
void maxim_lcl(void)
{
   unsigned int16 Rxdata;

   do
   {
      Rxdata = iSSPtransfer16(0L, LCL);   // force a read
      if (Rxdata & 0x8000L)               // if a character is returned from the read
      {                                    // put it in the MAXIPbuff for later use            
         tobuff(MAXIPbuff_lcl,MAXIPin_lcl,MAXIPout_lcl,SIBUFF,make8(Rxdata,0));         
      }
      if (Rxdata & 0x4000L)               // if no character is returned from the read
      {                                    // and there is a character to be sent
         if (hasdata(MAXOPbuff_lcl,MAXOPin_lcl,MAXOPout_lcl,SOBUFF))
         {                                 // send it
            Rxdata = iSSPtransfer16(0x8000L | make16(0,ifrombuff(MAXOPbuff_lcl,MAXOPin_lcl,MAXOPout_lcl,SOBUFF)), LCL);
            if (Rxdata & 0x8000L)         // if there was a character returned from the tx
            {                              // put it in the MAXIPbuff for later use
               tobuff(MAXIPbuff_lcl,MAXIPin_lcl,MAXIPout_lcl,SIBUFF,make8(Rxdata,0));
            }
         }
         else
         {
            Mconfig_lcl &= (~0x0800L);      // disable transmitter interrupt
            iSSPtransfer16(Mconfig_lcl, LCL);   // update the configuration to put the change in effect
         }
      }
isr_lp++;
delay_us(50);
   } while (EXT3INT == 0);                  // loop for as long as the chip holds the interrupt line low
                                          // this is necessary, since the Maxim device requires _level_ sensitive
                                          // interrupt detection, but the PIC, is an edge sensitive device...
isr_tot++;
   EXT3IF = 0;                              // clear the interrupt flag (releases the processor from ISR)
}


Thanks again for all the help,

John
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Oct 16, 2007 2:28 am     Reply with quote

The EXTx interrupts are edge triggered, not level triggered, so the EXT3 line staying high too long can not be your problem. The improved behavior you see by adding the delay could suggest the interrupt is triggered by a second pulse edge. Adding the delay would cause the second pulse / edge to be missed.

I haven't seen your schematic and am no hardware expert, but is it possible you are receiving such a second trigger? Reflections?
Ttelmah
Guest







PostPosted: Tue Oct 16, 2007 2:51 am     Reply with quote

Saw no such issues, but my 'pull up' is 4K7, and the trace is under 30mm long.
However if the line is held low too long, it shouldn't really cause a problem. It'd just make the code loop again, and poll the status bits again.
I agree with Ckielstra. It sounds as if, exiting quickly, is allowing the line to trigger the interrupt a second time. I'd be very suspicious of ringing behaviour, but at the slow rise time, seen wih your large resistors, this is unlikely on this edge. Is is possible that another signal is being capacitively coupled into the IRQ line, and when it is just transitioning, induces enough noise to make it trigger multiple times?.

Best Wishes
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Tue Oct 16, 2007 8:49 am     Reply with quote

I have a feeling this is going to get interesting and I'm going to learn a lot. (Translation: ahhh crap.) I'm afraid maybe my luck has run out.

I understand the issues that were raised and have tried to test and see if 'extra interrupts' were happening. I don't think it is extra interrupts, but may be something similar.

Method:

Disabled appropriate int_ext. Copied the original ISR function and renamed it. I removed the while loop and any other INT related code:

Code:
void maxim_lcl_non_isr(void)
{
   unsigned int16 Rxdata;

      Rxdata = iSSPtransfer16(0L, LCL);   // force a read
      if (Rxdata & 0x8000L)               // if a character is returned from the read
      {                                    // put it in the MAXIPbuff for later use   
isr_rx++;         
         tobuff(MAXIPbuff_lcl,MAXIPin_lcl,MAXIPout_lcl,SIBUFF,make8(Rxdata,0));         
      }
      if (Rxdata & 0x4000L)               // if no character is returned from the read
      {                                    // and there is a character to be sent
isr_tx++;
         if (hasdata(MAXOPbuff_lcl,MAXOPin_lcl,MAXOPout_lcl,SOBUFF))
         {                                 // send it
isr_tx2++;
            Rxdata = iSSPtransfer16(0x8000L | make16(0,ifrombuff(MAXOPbuff_lcl,MAXOPin_lcl,MAXOPout_lcl,SOBUFF)), LCL);
            if (Rxdata & 0x8000L)         // if there was a character returned from the tx
            {                              // put it in the MAXIPbuff for later use
               tobuff(MAXIPbuff_lcl,MAXIPin_lcl,MAXIPout_lcl,SIBUFF,make8(Rxdata,0));
            }
         }
         else
         {
            Mconfig_lcl &= (~0x0800L);      // disable transmitter interrupt
            iSSPtransfer16(Mconfig_lcl, LCL);   // update the configuration to put the change in effect
         }
      }
isr_lp++;
                                          // this is necessary, since the Maxim device requires _level_ sensitive
                                          // interrupt detection, but the PIC, is an edge sensitive device...
isr_tot++;
}


I then call this from the maxputc function to transmit. And I get similar results. By all appearances it looks as though some trips through the function don't result in a character being transmitted. The function gets called the correct number of times, but the trips through the 'transmit' related sections of the function are less than should be.

For instance - Every three seconds I send 16 characters. I get the following back:

(note: even though var's are named isr_... they are actually in the non isr function.)
Code:

isr_rx   = 0
isr_tx   = 5
isr_tx2  = 5
isr_lp  = 16
isr_tot = 16


So, for some reason the tx sections of the function are getting skipped. But, even if they are, that shouldn't cause the problem that I'm seeing.

My next suspicion is that the indexes in the ring buffer are getting corrupted some how. I'll work on dumping them and seeing if that is the problem. EDIT: I take that back. It seems more logical that it would be a garbled spi tx/rx?

Any other ideas?

Thanks,

John
Ttelmah
Guest







PostPosted: Tue Oct 16, 2007 9:41 am     Reply with quote

Are you running async or sync now with the clocks?.
At the 48Mz, you originally mentioned, you might be running into a number of timing issues. For instance, the clock setups required, and the pause between CS, and starting input/output, are 100nSec. At anything below 40MHz, these should be met, but over this frequency, single cycle delays might be necessary at a number of places. How fast are you actually running the SPI clock?. The maximum allowed, is just over 4Mhz. At 48MHz, you would need to use Fosc/16.

Best Wishes
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Tue Oct 16, 2007 9:58 am     Reply with quote

EDIT:

I was posting this as you were replying.

Still unsync'd. At 40MHz.

Reduction of SPI clock has never appeared to fix or reduce any problems.

I will try adding some cycles after CS.

***************************************************

EDIT #2:

If you read this post prior to me deleting the information here, disregard it. It was based on some bad logic.
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Tue Oct 16, 2007 12:53 pm     Reply with quote

I've reached the conclusion that the IRQ isn't returning HIGH fast enough (already noted, observed and commented on.)

I only see problems when there are more 'trips' through the ISR than are required. (i.e. when there isn't a delay.)

So that begs the questions...

Why do more than required trips through the loop in the ISR corrupt the data being sent? (I'm currently working on this.)

How do I make the ISR tolerant of unnecessary trips? (Can't work on this until I figure out the answer to the previous question.)

How do I 'fix' the problems with the IRQ signal? (I'll plan on scoping the signal and get an idea what it looks like and report back.)
Signal looks very clean. Sampled close to PIC. Rise time of 200nS from 0V to 3V. Which now tends to discount my previous conclusion?


Just thinking aloud. Any comments or suggestions are welcome.


John
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Tue Oct 16, 2007 5:12 pm     Reply with quote

EDIT #14

Latest conclusion is that without the delay the IRQ isn't being brought low with every trip into the ISR. See the scope plot below with no delay.


Code:

Code:
#INT_EXT3 NOCLEAR //Interrupt from local radio Maxim chip
void maxim_lcl(void)
{
   unsigned int16 Rxdata;

BH2_CS_BIT = 0;

   do
   {
BH2_CS_BIT = 1;
      Rxdata = iSSPtransfer16(0L, LCL);   // force a read
      if (Rxdata & 0x8000L)               // if a character is returned from the read
      {                                    // put it in the MAXIPbuff for later use         
         tobuff(MAXIPbuff_lcl,MAXIPin_lcl,MAXIPout_lcl,SIBUFF,make8(Rxdata,0));         
      }
      if (Rxdata & 0x4000L)               // if no character is returned from the read
      {                                    // and there is a character to be sent
         if (hasdata(MAXOPbuff_lcl,MAXOPin_lcl,MAXOPout_lcl,SOBUFF))
         {                                 // send it
            Rxdata = iSSPtransfer16(0x8000L | make16(0,ifrombuff(MAXOPbuff_lcl,MAXOPin_lcl,MAXOPout_lcl,SOBUFF)), LCL);
            if (Rxdata & 0x8000L)         // if there was a character returned from the tx
            {                              // put it in the MAXIPbuff for later use
               tobuff(MAXIPbuff_lcl,MAXIPin_lcl,MAXIPout_lcl,SIBUFF,make8(Rxdata,0));
            }
         }
         else
         {
            Mconfig_lcl &= (~0x0800L);      // disable transmitter interrupt
            iSSPtransfer16(Mconfig_lcl, LCL);   // update the configuration to put the change in effect
         }
      }
//delay_us(50);      //(100uS, 50uS works) (25uS, 12uS doesn't)
   } while (EXT3INT == 0);                  // loop for as long as the chip holds the interrupt line low
                                          // this is necessary, since the Maxim device requires _level_ sensitive
                                          // interrupt detection, but the PIC, is an edge sensitive device...
BH2_CS_BIT = 1;
   EXT3IF = 0;                              // clear the interrupt flag (releases the processor from ISR)
}


I toggle a pin to indicate on the scope when the IRQ is entered and finished.

Below, you can see with and without the delay.

Signal A = IRQ
Signal B = ISR start and finish


The big question is: When there is no delay, why isn't the interrupt being set by the MAX3100 every time? Is there a limit on how fast the MAX3100 can perform actions?


This is with no delay.
http://ultrasense.net/img/No_delay.bmp

This is with the delay.
http://ultrasense.net/img/50uS_delay.bmp

Sorry, for some reason I can't embed the images, only link....
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Wed Oct 17, 2007 7:51 am     Reply with quote

I want the last three days of my life back!

The problem is, is that the MX3100 does NOT have a TX FIFO buffer! (I thought it had both a TX AND an RX, 8 character FIFO buffer. It doesn't! BTW, the RX FIFO buffer has to be enabled and Ttelmah's driver does not utilize it... not that it matters in this case, just be aware of it.)

So here's the analysis:

Expected MAX3100 time to 'process' one byte at 57,600 = 174uS.

(1/57,600)*10 = 174uS.

If I look at the scope plots of the 'un-delayed', bad code, the time between the MAX3100 'accepting' a new byte is PRECISELY 174uS. (That is measured by the time between the leading edge of each IRQ.) So, the solution for that is simply to prevent overfilling the software input buffer. I assumed there was a problem because I was seeing 'over-runs' with 8 characters or less. (i.e. the non-existent TX FIFO wasn't working.)

The code with the delay would work as long as I didn't feed it a character any faster than every 174uS. The 50uS delay, that worked, fed the MAX3100 characters every 188uS. If I dropped to 25uS it would fail.
Ttelmah
Guest







PostPosted: Wed Oct 17, 2007 8:48 am     Reply with quote

The code does enable the receive buffer. The logic on this is reversed, so a '0' in the FEN bit, enables the buffer, which is done.
It does have a transmit buffer, but it is only two deep. Like the one on the PIC, a shift register, and one holding register (it actually uses the write data register). The code shouldn't load data to it, unless it sees the transmit empty status bit on the status command. What you post, doesn't really explain what is happening, since this status is checked...
I'd overflow the internal buffering every time at lower data rates (even with my slower processor clock).
It actually sounds as if the status bit doesn't properly update in time.

Best Wishes
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Wed Oct 17, 2007 10:02 am     Reply with quote

Arghhhhh.......

Yes. I missed the FEN setting. (I couldn't figure out why you wouldn't enable that, but I didn't bother to look it up.)

I agree. I just went back and tested again... 64 character buffer, with a timer sending 16 characters to the maxputc every 1 second, and still barfs! (that is without any code to prevent over-filling the software buffer.)

I know the ISR works as advertised. It can't be that.

The only other thing is a problem with the software buffer (or the status bit, as you've suggested... which I should probably heed).

Essentially it's the software buffer that gets over-run. Once I put the 'check' in place to prevent that, everything works great. When I scope that, I can see the first two characters being received by the MAX3100 as fast as the PIC will send them, then it settles down to reception at the byte-time rate. (i.e. the MAX3100 will accept a new character as fast as it sends one out... every ~170uS, in a continuous stream that is.)

Do you agree that the MAX3100 is only capable of receiving characters at the same rate that it is sending them? That's the real issue here and there must be handling in place for preventing both sending to quickly to the MAX3100 and sending to quickly to the software buffer that feeds the MAX3100. You have handled the hardware, but there must be some preventative measure for the software buffer. Either timing (doesn't appear to work) or something like this:

Code:
void maxputc_lcl(int8 chr)
{
   int16 tval;
   
   while(MAX_output_buff_full_lcl());      // wait for a spot in the buffer to open up
   disable_interrupts(GLOBAL);            // put the character in the tx buffer
   tobuff(MAXOPbuff_lcl,MAXOPin_lcl,MAXOPout_lcl,SOBUFF,chr);
   Mconfig_lcl = Mconfig_lcl | 0xC800;      // set tx buffer interrupt bit (turn on interrupt)
   tval=SSPtransfer16(Mconfig_lcl, LCL);   // enable tx buffer interrupt bit (turn on interrupt)
   EXT3IF = 1;                              // force an interrupt to start transmission
   enable_interrupts(GLOBAL);
}



I'm going to try to trace the buffer handling and after that I'll try to figure out some way to track the TX status bit on the MAX3100.

Thanks again for providing a voice of reason/experience.

John
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Wed Oct 17, 2007 10:36 am     Reply with quote

I've tested all the different possibilities on the software buffer and it is working as advertised (imagine that...)

Can you suggest some ideas on how to test the TX bit?


EDIT:

Just found an interesting bit. With the software buffer over-run code in place, the buffer fills up and runs constantly full. Even though I'm only sending 16 characters/second.
Ttelmah
Guest







PostPosted: Wed Oct 17, 2007 2:23 pm     Reply with quote

It is sounding to me as if the TX empty interrupt is not getting properly enabled when data is being sent.

The sequence I use, is:

Load character into buffer
Enable this interrupt source from the chip
Trigger a single interrupt handler call.

In the interrupt handler, after outputing a character, if no characters are waiting in the TX software buffer, I disable the TX interrupt source. Otherwise it is left enabled.

If this bit isn't enabling properly, then you won't receive TX empty interrupts, and will only be able to send as characters are received.

Have you checked if there are any erratas for the chips?. The ones I used were very early examples, and though I have not heard of any problems appearing with the boards recently (they are still made), they tend to be made in batches, and if there was a modification/errata, it might not have hit my unit yet...

Best Wishes
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Wed Oct 17, 2007 6:03 pm     Reply with quote

Some recent observations during my experimentation:

When I use this test code: (called once/second by timer)

Code:
for(i=0;i<10;i++)
{
   maxputc(i + 0x30);
}


All ten characters a placed correctly in the MAXOPbuff per Ttelmah's original code. But only 4 to 6 are actually output. Almost as if the SPI TX isn't completing on the missing characters. There is a not about incomplete SPI TX's canceling the active transmission.

Another thing that I find very interesting (but can't decide on the importance of) is that if I remove the GLOBAL int enable and disable from the maxputc and put them like this around my test code in the main:

Code:
disable_interrupts(GLOBAL);
for(i=0;i<10;i++)
{
   maxputc(i + 0x30);
}
enable_interrupts(GLOBAL);


Everything works great.

ERRATA:

Yes, there are some for the A1 silicon and they are SSP and interrupt related. Unfortunately I'm experienced enough to understand the ramifications.

INTERESTING OBSERVATION:

spi_clk_div_64 Works fine. But it appears that it slows things to less than the 174uS byte timing. BUT, MOSI idles low prior to start. All other spi clock settings idle high prior to starting. WHY? Is this important?

Yes. I use your code/flow for handling all the basics.

I'm trying to write a bit-bang routine now, to see if I can slow things down and see if that helps.
newguy



Joined: 24 Jun 2004
Posts: 1946

View user's profile Send private message

PostPosted: Wed Oct 17, 2007 7:48 pm     Reply with quote

Can an interrupt during an SPI transmission throw off the MAX3100? It kind of seems like it based on what you describe and your observations. Perhaps if the SPI transactions experience a "delay" while the processor services an interrupt, even though the SPI waveforms are technically okay/to spec, maybe that's enough to screw with the '3100?

....It kind of seems as though the 3100 has an internal SPI timeout - if a transaction isn't completed within x clocks from the time that that communication is initiated, it drops/resets the transaction?
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, 3  Next
Page 2 of 3

 
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