2008-08-08 06:09 PM
Number of Injected Channels
2011-05-17 03:41 AM
I know how to write JL[1:0] in ADC_JSQR. In fact, I’ve done it in assembly and it works. How is this parameter setup with the STM32 macros?
I have some kind of other serious failure giving me grief. Because all the Q&A uses the STM32 macros I decided to recast my code in C. I wanted to show my setup so that someone could point out what I’m doing wrong. Perhaps someone can help knowing the problems I face: I have uncertainty as to how one specifies conversion time. I can calculate the time okay but do the various SMPx[2:0] values refer to ADC channel number or the position of the channel number in ADC_SQR{1, 2, 3}. If the latter, how does one control injected channel conversion time? Using a pair of injected channels I have yet to find any channel that responds any differently to ground or 3.3 volts. But when I change SMP0[2:0] from 1 (I set them all them way to be sure) to 3 the values I see in ADC_JDR1 & ADC_JDR2 change. Still no response to 0 or 3.3 volts.2011-05-17 03:41 AM
I found my problem. Some of the antics of the STM32 ADC library code provided a clue.
I’ve seen some strange things in 40+ years of software engineering. This is one of the strangest. For two injected channels in ADC_JSQR . . . JSQ1[4:0] puts its result into ADC_JDR4 JSQ2[4:0] puts its result into ADC_JDR3 And I suppose if I wanted more that I might see that JSQ3[4:0] puts its result into ADC_JDR2 JSQ4[4:0] puts its result into ADC_JDR1 BEGIN Snip from docs 10.12.12 ADC injected sequence register (ADC_JSQR) Bits 19:15 JSQ4[4:0]: 4th conversion in injected sequence These bits are written by software with the channel number (0..17) assigned as the 4th in the sequence to be converted. Note: Unlike a regular conversion sequence, if JL[1:0] length is less than four, the channels are converted in a sequence starting from (4-JL). Example: ADC_JSQR[21:0] = 10 00011 00011 00111 00010 means that a scan conversion will convert the following channel sequence: 7, 3, 3. (not 2, 7, 3) Bits 14:10 JSQ3[4:0]: 3rd conversion in injected sequence Bits 9:5 JSQ2[4:0]: 2nd conversion in injected sequence Bits 4:0 JSQ1[4:0]: 1st conversion in injected sequence END Snip from docs This is just strange. I guess if I ever want 4 injected channels I had better check things out VERY carefully. In my application I care not at all which channel is sampled before another. As long as two samples are sampled at regular intervals and finish in something under 100 milliseconds it’s okay. The actual time to finish is more like 5 microseconds. The hardware design team made life difficult for this user. That much is clear. Yet they provided an addend to injected channels. Never tried it. But it had to cost more than a few gates. And that addend added to my effort. I need both signed and unsigned half words for analog values. Yes, all I need is “<(As half words I sometimes want 0x0000 to 0xFFF0 to be positive numbers. I.e. for output to the DAC. Other times I want 0x8000 to be the most negative reading and 0x7FF0 to be the most positive number. Conversion between forms is as simple as xor or add 0x8000.)