Paul, it has been several months since I have written any code for the 12 bit ADC in the 148/149. However, I have vague recollections of having similar problems to what you describe. However, (at least for me) it was due to the way I initialised the consecutive channel capture. (Once again, this was several months ago. So I cannot remember exactly what I was doing wrong!) It took several rereads of the TI documentation to finally fully absorb what was being said! I vaguely remember there was a bug in the header file for the ADC as well! (Long since been fixed though. Unless it has crept back in.)
Anyway, the following fragments are from my initialisation of the ADC.(Partially hacked to get rid of stuff you wouldn't be interested in. (RequiredChannels actually came from a structure.) The whole thing easily ran at 40khz with no problems. void SetupADC(void) { unsigned char *ADC_MCTL_X = (unsigned char *) 0x0080; // position of first ADCMCTLx channel memory int ChannelCnt; ADC12CTL0 = ADC12ON | SHT1_1 | SHT0_1 | REF2_5V | REFON; // ADC on, int. ref. on (2.5 V), sample timer = 2*4*250ns = 2uS (well within spec), Encoding is OFF ADC12CTL1 = ADC12SSEL_2 | ADC12DIV_1 | CSTARTADD_0 | CONSEQ_3 | SHP | SHS_2; // MCLK / 2 = 4 MHz, sequence of channels run once!, // Start a adcmem12 = 0, conversion initiated by Timer Bout.0 for (ChannelCnt = 0; ChannelCnt < (RequiredChannels - 1); ChannelCnt++) //set up the group of ADC mems for the current conversion) { *(ADC_MCTL_X++) = SREF_1 | INCH_0; // int. ref., channel 0 } *(ADC_MCTL_X) = EOS | SREF_1 | INCH_0; // int. ref., channel 0 ADC12IE = 0x0001 << ChannelCnt; // Interrupt when conversion placed in last used ADC12MEMx } Incidentally, the above shows a single channel being sampled multiple times. To change this to an ad-hoc channel sequence would be trivial I used the hardware multiplier in the ADC interrupt routine to MAC the values, and also to shift the values, as I really only want the most significant byte of data The reading of the ADC from within an interrupt was trivial, no special action required. Hope this is helpful. Cheers Harry -----Original Message----- From: mspgcc-users-ad...@lists.sourceforge.net [mailto:mspgcc-users-ad...@lists.sourceforge.net]on Behalf Of Paul Burke Sent: Friday, April 11, 2003 1:49 AM To: mspgcc-users Subject: [Mspgcc-users] A Really Weird ADC12 Problem Friends, Russians and Countrymen! I have a problem which is seriously weird. (no, not that one, I've seen the doctor about that). This doesn't seem to be a GCC bug, so relax.. I have an F148 program in which a fair amount is going on: interrupts for Timer_A0 and Port 2 edge (for a TimerA uart), Timer_A1 CCR1 and CCR2, and receive interrupts for both hardware uarts. All interrupt routines are enablenested, and the right code seems to be generated. So far so good. Now the problem: I am using the ADC in sequence mode, for a sequence of six channels. I've tested this in a standalone program, it's fine. The problem is, when I integrate it with my real program, the TimerA uart hangs. The ADC conversion is called from the CCR1/2 interrupt. CCR2 is the 1ms timebase. The odd part is, that if I jimmy the check for ADC ready test to always return 1, everything works OK (except of course for the ADC). With the ADC test in place, the CCR2 interrupt completes (so the ADC isn't hanging), but the uart runs (sometimes for one or two characters, sometimes for a couple of dozen) then hangs. The ADC ready test (ADC12CTL0 & ADC12SC) seems to produce the right code, and there's nothing else in that routine apart from the pushes and pops. There are no extra pushes compared to when I make the routine return TRUE, so I'm not running out of stack. I'm baffled. Can I put it to your combined almost infinite brain power to come up with an explanation? Regards Paul Burke ------------------------------------------------------- This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger for complex code. Debugging C/C++ programs can leave you feeling lost and disoriented. TotalView can help you find your way. Available on major UNIX and Linux platforms. Try it free. www.etnus.com _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users