MC9S08QE128 Array Size.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC9S08QE128 Array Size.

1,958 Views
FWFan
Contributor III
Hi All,
 
I'm trying to store about 1024 bytes of ADC readings.
I am only successful at storing 256 at the most.
I've tried changing the stack size but still no luck.
Do you have any advice?
 
I've included my main.c and prm files.
 
Thank you,
FWFan
Labels (1)
0 Kudos
8 Replies

434 Views
stevep
Contributor I
A number of issues.

volatile byte adcLow[ArraySize] @0x00000080;

Why put start of array in Page0?

void interrupt VectorNumber_Vadc ADC_ISR(void) {
  byte i;
  byte ADCResult[ArraySize];
This array should be static or declared outside of the interrupt function.

BUT your problem is almost certainly that the array index you use is defined as a byte which has a range of 0..255, ie 256 !
     ADCResult[i] = ADCRL;



0 Kudos

434 Views
bigmac
Specialist III
Hello,
 
In addition to the problems already outlined, I would suspect that the operation of the ISR code will not be as you intend.
 
Since you have decided to use interrupts for the ADC operation, I might normally expect that only a single ADC reading would be processed during each pass through the ISR.  If more than one reading is processed, this will slow the operation because of the wait, within the ISR, until the next reading is ready.  So there would be no benefit to use interrupts over polling.  I notice that the present code does not wait for completion of each reading beyond the first.
 
I wonder at the purpose of the array ADCResult[].  It does not seem to achieve anything since it does not appear to be read read by any of the code.  If the variable were declared static, it would not be visible outside of the ISR, so perhaps it should be global.  In either case, it would no longer occupy the stack, so the stack size might be reduced from its current 4K size.  This would provide more RAM capacity for the large global/static arrays.
 
Regards,
Mac
 
0 Kudos

434 Views
FWFan
Contributor III
Hi Guys,
 
Thank you for the quick replies.
 
Steve:
 
I originally declared adcLow[ArraySize] as a global so I can see the values in RAM.
But I think I can take that out now.  I also do not know about Page memory.
How does that work?  I tried a long time to understand that concept but still in the dark.
Thanks for noticing byte i, you're right, that blew by me.  I originally tested for only 128 bytes.
I do not understand about static declaration though.  I can also try putting the array in the main
section later.
Thanks a lot for your help.
 
BigMac:
 
I'm trying to get a snapshot of my bandpass filter output.
I can see from the data that I'm getting three images of the sine wave.
I don't know if this is correct because according to my calculation, I should
be receiving over 600 data points for a complete period.  I'm assuming a 8 MHz divide down to 4 MHz.
As for the ADCResult array, I will try to do some simple DSP later.  Even feed it
to my FPGA board later.  Right now, I'm just trying to see if I can get the samples correctly.
I'm still trying to understand how globals and locals work with this micro.
 
Thank you very much.
0 Kudos

434 Views
FWFan
Contributor III
Hi Bigmac,
 
Can you deduce from the ADC initial code that the bus clock is 4 MHz?  That is my assumption from the data sheet along with my settings.  However, I am getting repeated sine waves instead of one sine wave with 606 samples.  My sine wave should have a period of 3.03 ms.  From the datasheet, I should
get 606 samples to represent one period.  I have tried single conversion before, but I was getting 128 bytes of the same value.
 
Are you saying I should do one sample and wait, and then trigger again every 5 us?
 
Thank you.
0 Kudos

434 Views
bigmac
Specialist III
Hello,
 
Using the POR default settings for the ICS module, the untrimmed bus frequency should lie somewhere within the range 4-5 MHz.  Your current settings for the ADC will give an ADC clock 2-2.5 MHz.  For continuous conversion mode, the first conversion will take 85 bus cycles (17.0- 21.3 us), and subsequent conversions 74 bus cycles (14.8-17.5 us).
 
You are a long way from your intended sampling rate of 5 us.  Using the short sampling interval would reduce the number of bus cycles to 45 or 34 cycles.  However, it is possible that this may not be sufficient cycles to process each reading, even using polling.  If you were to double the bus frequency, whilst keeping the same ADC clock frequency, the minimum bus cycles available for processing each reading would increase to 68 cycles.
 
For polling operation within main(), you will need to wait until each conversion is completed before reading the conversion value.
 
word i;
...
 
for (i = 0; i < ArraySize; i++) {
   while (!ADCSC1_COCO);  // Wait until conversion complete
   ADCResult[i] = ADCRL;
}
 
Regards,
Mac
 


Message Edited by bigmac on 2008-10-09 04:27 AM
0 Kudos

434 Views
FWFan
Contributor III
Hi Bigmac,
 
Thanks for your help.  I wasn't sure how my clock was working.  My signal is only 336 Hz, so I don't really need something too quick.  2 Mhz should do it, assuming that is the sampling rate.  I did tried out your code but didn't get it to work.  I did not see any sample at all.  Do you think I need to add the code in the for loop to start the conversion every time?  Since this is a single conversion?
 
I do have a puzzle though about the clock.  I tried out the SCI at 9600 bps and it worked.  But this was done at the assumption that the clock is at 8 MHz.  What do you think?
 
Thank you for your help.
FWFan
0 Kudos

434 Views
bigmac
Specialist III
Hello FWFan,
 
I had previously assumed that you were using continuous conversion mode, since this is what your posted code seemed to indicate.  Using single conversion mode, you would need to initiate the conversion on each circuit of the for loop.
 
The bus frequency will depend on how you have actually set up the ICS module.  The frequency range that I previously stated assumed that the power-up default settings was used.  For reliable SCI operation using the internal reference, the reference would need to be trimmed to a specific frequency.
 
Regards,
Mac
 
0 Kudos

434 Views
FWFan
Contributor III
Hi Bigmac,
 
Thanks for your help.  I did try the continuous mode but I was not getting what I think I should.  So I tried the single conversion method.  I changed the while loop into an if statement and it seemed to work for me.  With the conversion starting after each read.  Perhaps I'll try the continous mode and use the while loop as you suggeted.
 
I looked at the true time window and the clock indicates that it is at about 4MHz.  So I assume that is what I'm working with.  This does seem to confirm with the SCI module that I am using and the number of cycle I am getting from the ADC readout. 
 
Thank you again for your help.  I hope to get further help from you in the future.
 
FWFan
0 Kudos