[SOLVED]AT90PWM3B amplified input to the ADC, AVR124 appnote

Go To Last Post
3 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have vacation now, and had time to try making amplified conversions on the AT90PVM3B, so far without obtaining what I want.

The app note on the subject, AVR124 has been examined. The PCB I have made has no support for the serial channel used for ADC result output, so I removed the serial channel stuff and replaced it with my display driver.

It was easy to get compiled, but then trouble started. The following refers to the following:

file AVR124.c, packed with the document
"Atmel AVR124: Using the A-D Amplifier on AT90PWM Rev. 8288B-AVR-01/12" and data sheet
"AT90PWM2/3/2B/3B Rev. 4317K"“AVR"“03/2013"

line 180 in function main():

	DDRB = 0xFF;	// Port B as output

AMP0 inputs are on PB3 and PB4, but they are configured as outputs.

So I changed the line to:

	DDRB = 0xE7;	// Port B as output, but not AMP0 inputs configured as output, please

With this correction the example worked and measured input from AMP0.

But there are other confusing things:

line 108 in function ADC_Init(void) states:

	ADCSRA = (1 << ADEN)  | (1<<ADATE) ;

The accompanying document says on page 8:

"When working with the amplifier, the auto-triggering mode of the ADC is not used
since the trigger has been configured in AMPxCSR register (Table 5-1).

So the ADC Auto Trigger Enable bit (ADATE in ADCSRA), ADC Trigger Select bits
and ADTS in ADCSRB used for free running mode cannot be used while using
amplified A/D conversion."

What to trust ? Obviously it does not prevent the example from measuring but is that an exception ?

line 132 in function ADC_SyncMeasure()

	ADCSRA &= ~(1<<ADIF);

From ADC Control and Status Register A "“ ADCSRA

""¢ Bit 4"“ ADIF: ADC Interrupt Flag
Set by hardware as soon as a conversion is complete and the Data register are updated with the
conversion result.
Cleared by hardware when executing the corresponding interrupt handling vector.
Alternatively, ADIF can be cleared by writing it to logical one."

But here it the appnote program tries to clear by writing a zero.

Also the description claims to return measured value, but it returns 0.

Page 253 in the data sheet:

"Only PSC sources can auto trigger the amplified conversion. In this case, the core must have a
clock synchronous with the PSC. If the PSC uses the PLL clock, the core must use the PLL/4
clock source."

Page 3 in app note AVR124:

"PSC events are related to the clock source for the PSC module; hence if PLL is used
to clock PSC then the synchronization clock (PSC Event) has no relation to clkI/O (see
Figure 3-2. A/D timing.)"

The data sheet statement should be highlighted on the first page of the app note, instead there is this vague statement on page 3. This is a potential showstopper because if the fuses are not set correctly, it does not work correctly if the data sheet is to be believed.

on line 8 in AVR124.c:

# Fuse settings = F9/DF/4E

CLKsel3..0 = 0xE, which is just using an external crystal/resonator, not a setting using PLL/4.

But the example uses the PLL clock in line 159

PCNF0 = (1<<PALOCK0) | (1<<POP0) | (1<<PCLKSEL0) ; 	/* PSC0 Config : Autolock/PSC0 output active high/fast clock input*/

By the way the data sheet is not fully clear on clock selection.

In figure 16-3 on page 134 and in figure 16-39 on page 161 the two possible clocks to choose from are CLKpll and CLKi/o while the register description uses the names CLKPF and CLKPS:

""¢ Bit 1 "“ PCLKSELn: PSC n Input Clock Select
This bit is used to select between CLKPF or CLKPS clocks.
Set this bit to select the fast clock input (CLKPF).
Clear this bit to select the slow clock input (CLKPS)."

Why not use the same names consistently ?


As I mentioned, I have the modified AVR124 program running, but as the above indicates, the published program has errors, and can not have been tested demonstrating the desired function (not possible with inputs configured as outputs which shorts input signals to GND in this case).

All in all this documentation and program has room for improvement.

I can still not make it run in my application, because I don't want to use interrupt driven conversion.

I do all the regulation of optimizing input power from the solar cells and regulating the max output voltage to 630V in SW, and don't want to waste CPU time on a fast interrupt, the converter runs at 150kHz to minimize the transformer size for transferring 600W. The AVR is fine for doing this SW regulation, I have made other switch mode supplies with the tiny45.

Annoying problem as I have all other HW working OK now, just waiting for the measurement input to the regulator SW.

I will be thankful if one of you can supply a code snippet doing synchronized amplified input to the ADC without using interrupts.


1st edit: Removed not so nice comment (true though)
2nd edit: Changed status to [SOLVED].

Last Edited: Sat. Aug 3, 2013 - 12:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have just turned the problem upside down.

I tried to make my own program from the documentation, but there are too many unknowns (at least for me).

Another way to solve it is to take the modified and working AVR124.c and step by step converting it to the program I have written, compile each step and program the uC.

This way the faulty step identifies itself by the measurement stopping working.

I just got it to work without interrupts on PSC0, next is to get it to work with PSC2 and so on.

So please don't waste time on helping me right now, maybe I get stuck later and ask again.


  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now I boiled down AVR124.c so it is more easy to get the essentials.

I have corrected (most) of the minor errors I found, including the faulty ADC offset measurement, you can compare my file to the original to see the differences.

The amplified conversion works fine for me now, the attached file is just delivering results in variables, no interrupt and no serial output.