Hi Jeff,
I am not familiar with the MakroC complier (by your code smippet it seems that one can set things at a bit level rather than having to write the entire register - interesting...)
A few things to note -
1. What happens to the bits that you are not explicitly setting? We assume they are zero - but are they _really_??
2. Are you select the correct ADC channel you are reading from? (ADMUX bits)
3. Did you setup the ADC clock? (ADPS bits)
Can you look at the generated asm to check that the registers are written as you'd expect?
Below is code I use to init the adc on an ATMega128. HTH
Please let us know how you get on.
Regards,
Ivan Vernot
void ADC_Init(BOOL use_internal_ref )
{
ADMUX = 0; // Sel Ch0
if(use_internal_ref)
{ // use VCC as reference
ADMUX = BIT(REFS0); // 01xx xxxx; AVCC as ref
// NB: ;'use internal' does not mean use
// ACTUAL internal 2.56 V ref
// it means use AVCC are the reference (5V)
}
else
{ // use external reference
ADMUX &= ~(BIT(REFS1)|BIT(REFS0));
// 00xx xxxx ; AREF as ref
}
// ADMUX |= BIT(ADLAR); // xx1x xxxx; Left Adjust results
ADCSRA = BIT(ADEN) | BIT(ADPS2)|BIT(ADPS1)|BIT(ADPS0);
// Enable ADC in single shot mode
// ADSP2:0 110 => clk/64 => 14MHz/64 = 230Khz ADC clk)
// ADSP2:0 111 => clk/128 => 14MHz/128 = 115.2Khz ADC clk)
// SFIOR = BIT(ADHSM); // ADC High Speed Mode
ADCSRA |= BIT(ADSC); // Start the first conversion
// initiate dummy conversion
while (ADCSRA & BIT(ADSC))
{
WATCHDOG(); // Wait until coversion completed
}
}
--- In AVR-Chat@yahoogroups.com, "Jeff Blaine AC0C" <keepwalking188@...> wrote:
>
> I am having a tough time getting this chip to respond to any other ADC voltage reference than the default AVcc.
>
> The code snip is really simple... Below, using the MakroC Pro compiler, however the results seem to be the same if I do the same using ASM instructions instead of their bit-level defines.
>
> I must be overlooking something. It seems so simple, driving me nuts that it's not working right. I have used the same compiler and basic code to get a mega328 to work.
>
> Appreciate any suggestions the group may have.
>
> Thanks/jeff
>
>
> REFS0_bit = 1; // 001 invokes external Vref as ADC reference
> ADEN_bit = 1; // enable adc
> ADSC_bit = 1; // start conversion
> while(adsc_bit);
> lb=ADCL; // get lower byte
> ub=ADCH; // get upper byte
> adc_rd0 = (256*ub) + lb; // build number
>
> [Non-text portions of this message have been removed]
>Message
Re: Vref on ATTiny861a
2010-01-21 by ivernot
Attachments
- No local attachments were found for this message.