Page 1 of 1
How to use 2.56 internal reference with attiny861
Posted: Sat Oct 19, 2013 3:24 pm
by gliga69
Please help me to use the 2.56 internal reference with attiny861
There is no option in extension propertise (can only set vref+ and vdd)
i have try to use a c code : "ADMUX=0x80; ADCSRB=0x10;"
Peter
Re: How to use 2.56 internal reference with attiny861
Posted: Sun Oct 20, 2013 5:27 pm
by gliga69
No one?
Please help me, i need the info for project to my university. We have registred flowcode5 avr in the lab if it matters.
Peter
Re: How to use 2.56 internal reference with attiny861
Posted: Sun Oct 20, 2013 6:30 pm
by kersing
Have you tried adding a C code block with those statements? I'm not sure, but I think you need flowcode professional to add C code.
Re: How to use 2.56 internal reference with attiny861
Posted: Mon Oct 21, 2013 12:03 pm
by gliga69
yes, i'd already try to add "ADMUX=0x80; ADCSRB=0x10;" as c code, but it was not work.
When i write the program to the uc it only uses the suppy voltage or the extref pins as reference, as i set it in the extension properties, my c code is not matters at all.
Should i modify the "AVR_CAL_ADC.c" ? I think the attiny 861 have "ADC Type 10".
Peter
Re: How to use 2.56 internal reference with attiny861
Posted: Mon Oct 21, 2013 4:49 pm
by Benj
Hi Peter,
Yes you will likely have to edit the CAL ADC file if you want the changes to be made. A good way would be to add your edit to the CAL like this.
Code: Select all
#ifdef MY_CUSTOM_ADC
ADMUX=0x80;
ADCSRB=0x10;
#endif
The ADC type used by your chip can be seen by viewing the Flowcode generated C code. Should be near the top.
Then in the Project Options -> Supplementary code you can switch on your code mod by adding this line to the defines section.
#define MY_CUSTOM_ADC
Otherwise if this is omitted the code will default back to the standard CAL code.
Re: How to use 2.56 internal reference with attiny861
Posted: Mon Oct 21, 2013 8:47 pm
by gliga69
Hi!
I have do the changes and i got an error message whilecompiling
Code: Select all
In file included from C:\Program Files\Flowcode(AVR)\v5\CAL\includes.c:47,
from C:\BALANC~1\Drill.c:1462:
C:\Program Files\Flowcode(AVR)\v5\CAL\/AVR\AVR_CAL_ADC.c:199: error: expected identifier or '(' before 'volatile'
C:\Program Files\Flowcode(AVR)\v5\CAL\/AVR\AVR_CAL_ADC.c:199: error: expected ')' before '(' token
C:\Program Files\Flowcode(AVR)\v5\CAL\/AVR\AVR_CAL_ADC.c:200: warning: data definition has no type or storage class
i think i was pasted the next few lines to the wrong place
Code: Select all
#ifdef MY_CUSTOM_ADC
ADMUX=0x80;
ADCSRB=0x10;
#endif"
My avr_cal_adc.c looks like this: (i have adc type 4, it turned out from my c code)
Code: Select all
/* ADC Type 4 Supported Devices ************************************************************
// Unknown
*******************************************************************************************/
#ifdef MY_CUSTOM_ADC
ADMUX=0x80;
ADCSRB=0x10;
#endif
#ifdef MX_ADC_TYPE_4
void FC_CAL_Enable_ADC (MX_UINT8 Channel, MX_UINT8 Conv_Speed, MX_UINT8 Vref, MX_UINT8 T_Charge)
{
tris_mask = Channel;
if (Channel > 2)
tris_mask++;
if (Channel < 7)
{
tris_reg = (MX_UINT8*) &DDRA;
}
else
{
tris_mask -= 4;
tris_reg = (MX_UINT8*) &DDRB;
}
old_tris = *tris_reg;
*tris_reg &= ~(1 << tris_mask); //turn selected ADC on
ADCSRA = (1 << ADEN) | Conv_Speed;
ADMUX = (Vref << REFS0) | (1 << ADLAR) | Channel;
delay_us(T_Charge); //wait the acquisition time
ADCSRA |= (1 << ADSC); //begin next conversion
}
MX_UINT16 FC_CAL_Sample_ADC (MX_UINT8 Sample_Mode)
{
MX_UINT16 iRetVal;
while(ADCSRA & (1 << ADSC));
if (Sample_Mode)
{
iRetVal = (ADCL >> 6); //10-bit ADC
iRetVal |= (ADCH << 2);
}
else
iRetVal = ADCH; //8-bit ADC
ADCSRA |= (1 << ADSC); //begin next conversion
return (iRetVal);
}
void FC_CAL_Disable_ADC ()
{
*tris_reg = old_tris; //restore old tris value, and reset adc registers
ADCSRA &= ~(1 << ADEN);
}
#endif
"
Peter
Re: How to use 2.56 internal reference with attiny861
Posted: Mon Oct 21, 2013 9:11 pm
by kersing
Please remove your code and change the FC_CAL_Enable_ADC function (look for ADDED and Original):
Code: Select all
void FC_CAL_Enable_ADC (MX_UINT8 Channel, MX_UINT8 Conv_Speed, MX_UINT8 Vref, MX_UINT8 T_Charge)
{
tris_mask = Channel;
if (Channel > 2)
tris_mask++;
if (Channel < 7)
{
tris_reg = (MX_UINT8*) &DDRA;
}
else
{
tris_mask -= 4;
tris_reg = (MX_UINT8*) &DDRB;
}
old_tris = *tris_reg;
*tris_reg &= ~(1 << tris_mask); //turn selected ADC on
// ADDED 4 lines
#ifdef MY_CUSTOM_ADC
ADMUX=0x80;
ADCSRB=0x10;
#else
// Original 2 lines follow:
ADCSRA = (1 << ADEN) | Conv_Speed;
ADMUX = (Vref << REFS0) | (1 << ADLAR) | Channel;
// ADDED next line
#endif
delay_us(T_Charge); //wait the acquisition time
ADCSRA |= (1 << ADSC); //begin next conversion
}
Feel free to skip the comments with 'ADDED' and 'Original'.
This should work. I can not test it as I do not have FC5 for AVR installed.
Re: How to use 2.56 internal reference with attiny861
Posted: Mon Oct 21, 2013 10:27 pm
by gliga69
Thank you kersing for the syntax correction, it seems it works. The compiler can finish the work without errors.
Tomorrow i will try it with the uc and write the result.
Re: How to use 2.56 internal reference with attiny861
Posted: Mon Oct 21, 2013 10:31 pm
by gliga69
And of course a BIG thanks for Benj for the solution

Re: How to use 2.56 internal reference with attiny861
Posted: Tue Oct 22, 2013 9:27 am
by gliga69
well, it did not work in the uc. do i have to some additional thing?
should i set something at theadditional properties?
If i set the additional code, my program runs, but something is not good at the adc configuration.
I try to read a byte from adc an if that byte is less than 128 one led lights.
If i add a 2V to the adc-s pin the led still lights.
If i add 2,6V to that pin the led still lights.
If i disable the additional code and set the ref voltage to supply voltage and give 2,6V to the adc-s pin the light goes off.
What did i do wrong.
Peter
Re: How to use 2.56 internal reference with attiny861
Posted: Tue Nov 05, 2013 11:31 pm
by gliga69
Can somebody help, please? What did i do wrong?
Peter
Re: How to use 2.56 internal reference with attiny861
Posted: Fri Nov 08, 2013 12:39 am
by kersing
Could you attach your Flowcode program (fcf file) and the generated C code for us to have a look at?