Author Topic: ATtiny13 project problems  (Read 9835 times)

0 Members and 1 Guest are viewing this topic.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: ATtiny13 project problems
« Reply #25 on: May 18, 2014, 06:24:58 pm »
Ah, I need :

Code: [Select]
void adc_go (void)
{
bit_s(ADCSRA, BIT(ADSC));
}
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1977
  • Country: dk
Re: ATtiny13 project problems
« Reply #26 on: May 18, 2014, 06:27:55 pm »
It makes no difference with ADC, the tutorial you link to just uses ADCL in 8 bit mode, I am not doing this because i am not passing the ADC result straight to the ADC but working with it to come up with a PWM value so i need that resolution.


It spooks me a bit that using ADCW didn't return a compiler error  (undefined).

Well now it don't (from iotn13.h)

Code: [Select]
/* ADC Data Register */
#ifndef __ASSEMBLER__
#define ADC                  _SFR_IO16 (0x04)
#endif
#define ADCW                 _SFR_IO16 (0x04)
#define ADCL                 _SFR_IO8(0x04)
#define ADCH                 _SFR_IO8(0x05)

So ADC & ADCW has same def.

/Bingo
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: ATtiny13 project problems
« Reply #27 on: May 18, 2014, 06:36:54 pm »
Still no joy
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1977
  • Country: dk
Re: ATtiny13 project problems
« Reply #28 on: May 18, 2014, 06:42:55 pm »
What adc channel are you using , and what voltage reference  (vcc or 1.1v ) ?

/Bingo
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: ATtiny13 project problems
« Reply #29 on: May 18, 2014, 06:45:54 pm »
I'm using VCC on channel 0 - oh bugger, bet the AVRISP2 is interfering although probably not as there is a 2V input so something to convert either way
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: ATtiny13 project problems
« Reply #30 on: May 18, 2014, 06:47:36 pm »
IDIOT! I should be on ADC2 there is probably a change from the tiny25 to the tiny13
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1977
  • Country: dk
Re: ATtiny13 project problems
« Reply #31 on: May 18, 2014, 06:53:45 pm »

I siggest you start the conversion & read the result in the same routine

Code: [Select]
uint16_t read_adc(void)
{

//ADCSRA |= ADC_CONVERT; // ADC Start conversion (this bit is restored to zero when finished)
        bit_s(ADCSRA, BIT(ADSC));                          // // ADC Start conversion (this bit is restored to zero when finished)
//while (ADCSRA & ADC_CONVERT);               // Check the complete flag and wait until done
        while (ADCSRA & BIT(ADSC));               // Check the complete flag and wait until done
return ADCW;

}

/Bingo
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: ATtiny13 project problems
« Reply #32 on: May 18, 2014, 07:16:19 pm »
yes i have now done:

Code: [Select]
uint16_t adc_result (void) //return the current ADC value, the function will wait until the a conversion has ended.
{
uint16_t result;

bit_s(ADCSRA, BIT(ADSC)); //start a conversion
while( ADCSRA & (1<<ADSC));   // Wait until ADC conversion is complete..
result = ADC;
return result;
}

I think i meant to do it and then forgot.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf