How to use 2.56 internal reference with attiny861

Moderator: Benj

Post Reply
gliga69
Posts: 8
Joined: Sat Oct 19, 2013 2:10 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

How to use 2.56 internal reference with attiny861

Post 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

gliga69
Posts: 8
Joined: Sat Oct 19, 2013 2:10 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Re: How to use 2.56 internal reference with attiny861

Post 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

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: How to use 2.56 internal reference with attiny861

Post 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.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

gliga69
Posts: 8
Joined: Sat Oct 19, 2013 2:10 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Re: How to use 2.56 internal reference with attiny861

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: How to use 2.56 internal reference with attiny861

Post 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.

gliga69
Posts: 8
Joined: Sat Oct 19, 2013 2:10 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Re: How to use 2.56 internal reference with attiny861

Post 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
Last edited by gliga69 on Mon Oct 21, 2013 10:23 pm, edited 2 times in total.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: How to use 2.56 internal reference with attiny861

Post 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.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

gliga69
Posts: 8
Joined: Sat Oct 19, 2013 2:10 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Re: How to use 2.56 internal reference with attiny861

Post 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.

gliga69
Posts: 8
Joined: Sat Oct 19, 2013 2:10 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Re: How to use 2.56 internal reference with attiny861

Post by gliga69 »

And of course a BIG thanks for Benj for the solution :)

gliga69
Posts: 8
Joined: Sat Oct 19, 2013 2:10 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Re: How to use 2.56 internal reference with attiny861

Post 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

gliga69
Posts: 8
Joined: Sat Oct 19, 2013 2:10 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Re: How to use 2.56 internal reference with attiny861

Post by gliga69 »

Can somebody help, please? What did i do wrong?
Peter

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: How to use 2.56 internal reference with attiny861

Post by kersing »

Could you attach your Flowcode program (fcf file) and the generated C code for us to have a look at?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Post Reply