Sample Project For ATTINY10 - AVR Freaks
Sample Project For ATTINY10 - AVR Freaks
Signup
Login
Author Message
Fivestar widget
Total votes: 0
Just would like to know if there is anywhere i can download sample C example
projects for Atmel Studio that shows different functionality of the ATTINY10?
I use STK600.
Regards,
Tony Siu
Tony Siu
Tags:
AVR Microcontrollers, megaAVR and tinyAVR
Top
Log In / Register to post comments
https://www.avrfreaks.net/forum/sample-project-attiny10 1/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
Total votes: 0
Here's a short sample that read the ADC and uses the timer to generate two
Level: Posting Freak servo signals proportional to the ADC reading.
Joined: Thu. Jan 8, 2009
Posts: 1952 View posts
Location: Lund, Sweden
/*
Read ADC2 (PB2) and output servo signal on PB0 and PB1.
ATtiny5 or 10 at default 1MHz.
*/
#include <avr/io.h>
int main(void)
{
// ADC channel 2
ADMUX = 2;
// Disable digital input on PB2
DIDR0 = (1<<ADC2D);
// Enable ADC, presc 1:8 for 125kHz ADC-clock
ADCSRA = (1<<ADEN) | (1<<ADPS1) | (1<<ADPS0);
while(1)
{
uint8_t i;
uint16_t adc4;
Top
Log In or Register to post comments
Total votes: 0
Wasn't that useful? Anyway, here's a couple of more examples from my t10/test
Level: Posting Freak directory.
Joined: Thu. Jan 8, 2009
Posts: 1952 View posts
Location: Lund, Sweden
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
// PB2 output
DDRB = 1<<2;
while(1)
{
// Toggle PB2
PINB = 1<<2;
_delay_ms(500);
}
}
https://www.avrfreaks.net/forum/sample-project-attiny10 3/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
TCNT0 = 0;
OCR0A = 0;
// Start timer, free running with presc. 1:64
TCCR0B = 1<<CS01 | 1<<CS00;
DDRB = 1<<2;
while(1)
{
// Short flash
PORTB |= 1<<2;
_delay_ms(1);
PORTB &= ~(1<<2);
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
EMPTY_INTERRUPT(TIM0_COMPA_vect)
int main(void)
{
TCNT0 = 0;
OCR0A = 0;
// Enable compare match A interrupt
TIMSK0 = 1<<OCIE0A;
// Start timer, free running with presc. 1:64
TCCR0B = 1<<CS01 | 1<<CS00;
// PB2 output
https://www.avrfreaks.net/forum/sample-project-attiny10 4/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
DDRB = 1<<2;
set_sleep_mode(SLEEP_MODE_IDLE);
sei();
while(1)
{
// Short flash
PORTB |= 1<<2;
_delay_ms(1);
PORTB &= ~(1<<2);
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include <util/atomic.h>
#include <avr/wdt.h>
/*
Delay in powerdown mode. Wake up by watchdog interrupt.
*/
void delay_power_down_wdt(uint8_t wdto)
{
wdt_reset();
wdt_enable(wdto);
WDTCSR |= (1<<WDIE);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
// Make sure interrups are enabled and the I flag is r
NONATOMIC_BLOCK(NONATOMIC_RESTORESTATE)
{
sleep_cpu();
https://www.avrfreaks.net/forum/sample-project-attiny10 5/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
wdt_disable();
}
sleep_disable();
}
int main(void)
{
DDRB = 1<<2;
sei();
while(1)
{
// Short flash
PORTB |= 1<<2;
_delay_ms(1);
PORTB &= ~(1<<2);
delay_power_down_wdt(WDTO_1S);
}
}
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
int i;
while(1)
{
for (i = 0; i <= 1000; i++)
{
OCR0A = i;
OCR0B = 1000-i;
_delay_ms(1);
https://www.avrfreaks.net/forum/sample-project-attiny10 6/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
}
for (i = 1000; i >= 0; i--)
{
OCR0A = i;
OCR0B = 1000-i;
_delay_ms(1);
}
}
}
/*
Button on PB2 to GND, LED on PB0.
Toggle led when button is pressed.
Button is debounced using timer interrupt.
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
if (current_state != button_state) {
// Button is about to be pressed or released, inc
count++;
if (count >= 4) {
// The button have not bounced for four check
button_state = current_state;
// If the button was pressed (not released),
if (current_state != 0) {
button_down = 1;
count = 0;
}
}
https://www.avrfreaks.net/forum/sample-project-attiny10 7/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
} else {
// Reset counter
count = 0;
}
}
// Called at 100Hz
ISR(TIM0_OVF_vect)
{
debounce();
}
int main(void)
{
// PB0 output
DDRB = 1<<0;
// Enable internal pullup on PB2
PUEB = 1<<2;
while(1)
{
if (button_down) {
// Clear flag
button_down = 0;
// Toggle PB0
PORTB ^= (1<<0);
}
}
}
Top
Log In or Register to post comments
https://www.avrfreaks.net/forum/sample-project-attiny10 8/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
Total votes: 0
Here's one I played with a while ago. The anode of a yellow LED is hooked to
Level: Raving Lunatic a 100 ohm resistor to PB0, the cathode to ground. (This is the opposite of the
Joined: Tue. Nov 11, 2003
Posts: 9620 View posts traditional way to hook an LED.) Every minute or so, the program reads the
Location: Coweta Oklahoma voltage across the LED to decide if it's dark. If it is dark, it blinks like a firefly.
USA
I was curious how long one of these would last on 2 AA batteries: About a
month till a storm knocks it off the balcony railing, it smashes on the sidewalk
below and the landlady sweeps up the debris and throws it away.
/*
* Firefly02.c
*
* Created: 4/21/2013 4:30:21 PM
* Author: Tom
*/
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/sleep.h>
#define F_CPU 1000000UL // 1 MHz
#include<util/delay.h>
int IsDark(void)
{
DDRB = 1 ;
PORTB = PORTB & ~(1);
_delay_ms(20);
DDRB = 0 ; // go to high impedance.
ADMUX = 0; // Read v across LED
ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<
ADCSRA |= (1<<ADSC);
while ((ADCSRA & (1<<ADIF))==0)
{
}
ADCSRA = (1<<ADIF);
if (ADCL < 5) return 1;
return 0;
}
ISR(TIM0_OVF_vect)
{
https://www.avrfreaks.net/forum/sample-project-attiny10 9/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
}
else // Blinking
{
OCR0A = OCR0A-1 ;
}
}
ISR(WDT_vect)
{
int main(void)
{
DIDR0 = 0xf;
sei();
while(1)
{
if (IsDark()!=0)
{
DDRB = 1;
TCCR0B = 0;
TCCR0A = (1<<COM0A1) | (1<<WGM00);
TCCR0B = (1<<WGM02) | (1<<CS01);
OCR0A = 255 ;
TIMSK0 = (1<<TOIE0) ;
while (OCR0A>0)
{
}
TCNT0 = 0;
PORTB = 0 ;
DDRB = 0;
TCCR0B = 0;
}
for(uint8_t i = 0; i<8; i++)
{
// Set watch dog timer for about 8
WDTCSR = (1<<WDIE) | (1<<WDP3) | (1<
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu();
}
WDTCSR = 0 ; // Disable watch dog
}
}
https://www.avrfreaks.net/forum/sample-project-attiny10 10/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
2 82,589,933
-1 The largest known Mersenne Prime (Dec 7, 2018)
Top
Log In or Register to post comments
Total votes: 0
Just to note that there articles about timers and ADC in the tutorial forum here.
Level: Moderator Admittedly not for Tiny10 but on the whole a lot of these peripherals are very
Joined: Mon. Jul 18, 2005
Posts: 93783 View posts similar across the AVRs and the general techniques can be applied to all though
Location: (using avr-gcc in) you may need to determine the odd change in bit or register names between
Finchingfield, Essex, England
devices.
But the point is that the use of an ADC is fairly common in general: you init a
voltage reference, you init a prescale value to run the ADC at a "sensible"
speed, you actually enable the ADC then you set some "start" bit and either
keep watching it or wait for an interrupt indication to show completion then you
read the results register. That's true for pretty much all AVRs, Tiny10 included
so don't limit yourself to only trying to find details about Tiny10 alone. In fact
few people (except those using them in industrial quantities) choose to use Tiny
4,5,9,10,20,40 - the so called "brain dead" AVRs - because their only true
features are low cost and small package size. "hobbyists" pick more fully
featured AVRs to start with like Tiny2313 (previously), Tiny1634, Mega48/88/168,
Mega164/324/644/1284 and so on.
(http://www.nongnu.org/avr-libc/user-manual/FAQ.html)
Top
Log In or Register to post comments
https://www.avrfreaks.net/forum/sample-project-attiny10 11/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
Total votes: 0
Thanks.. I think I will use the full size chip for development first.
Level: New Member
Joined: Fri. Jan 2, 2015
Posts: 2 View posts
[The two extra copies of this post have been deleted. Ross]
Tony Siu
Top
Log In or Register to post comments
Total votes: 0
I like tiny 10s because they're tiny and cheap. Annoying that you can't program
Level: Raving Lunatic them with a 3v supply though.
Joined: Tue. Nov 11, 2003
Posts: 9620 View posts
Location: Coweta Oklahoma
USA
2 82,589,933
-1 The largest known Mersenne Prime (Dec 7, 2018)
Top
Log In or Register to post comments
Total votes: 0
Hello,
Level: New Member
Joined: Mon. Mar 5, 2018
Posts: 16 View posts
https://www.avrfreaks.net/forum/sample-project-attiny10 12/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
Flash an LED.
For some reason, My code does not wake up after the sleep_cpu(); command.
does anyone have any idea's. I am using an ATtiny 5 on the STK600 Dev
system.
* ModuleJunctionBoxV1.c
*
* Description:
* This Module will wake up every X Seconds, Flash the LED and Check the
Battery Voltage.
*/
#include <avr/io.h>
#include <util/delay.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include "MJBGlobals.h"
int main(void)
https://www.avrfreaks.net/forum/sample-project-attiny10 13/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
sysint();
adcint();
wdt_disable();
HORN_OFF;
LED_OFF;
while(1)
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu();
led_flash();
/*
* Function: sysint
*
* Description:
*/
void sysint(void)
{
https://www.avrfreaks.net/forum/sample-project-attiny10 14/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
// PB2 = INPUT
// PB1 = OUTPUT
// PB0 = OUTPUT
/*
* Function: adcint
*
* Description:
*/
void adcint(void)
/*
* Function: readadc
*
https://www.avrfreaks.net/forum/sample-project-attiny10 15/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
* Description:
* This function enables the ADC, Starts the ADC and then takes 4 readings.
*/
/*void readadc(void)
uint8_t i;
uint16_t adc4;
; // Nothing
adc4 += ADCL;
}*/
void led_flash(void)
https://www.avrfreaks.net/forum/sample-project-attiny10 16/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
Attachment(s):
MJBGlobals.h
main.c
Top
Log In or Register to post comments
Total votes: 0
Jim
share.robinhood.com/jamesc3274
Top
Log In or Register to post comments
Total votes: 0
https://www.avrfreaks.net/forum/sample-project-attiny10 17/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
Level: New Member
Joined: Mon. Mar 5, 2018
Posts: 16 View posts
What happens it the processor enters into sleep with the sleep_cpu(); instruction
and it never exits this instruction. If I put a LED_OFF; instruction right after the
sleep_cpu instruction, the LED never turns off.
Top
Log In or Register to post comments
Total votes: 1
As mentioned, others that have experience with this family may need to help.
Level: 10k+ Postman But with a quick glance ...
Joined: Mon. Feb 19, 2001
Posts: 39072 View posts
Location: Wisconsin USA
-- learn how to use the Code <> tags on the formatting toolbar. It makes
source code much easier to understand. Practice with editing your post, or
make another.
-- I cannot tell whether the WDIE is taking effect; I suspect that the sequence is
not correct. I don't think that the built-in GCC functions are very good at
watchdog interrupt.
-- "WDTCSR = 0 ; // Disable watch dog" won't turn off the watchdog, will it?
But a moot point as I don't think the watchdog is enabled anyway.
-- I don't see any WDE in your code? I guess that is OK in interrupt mode, so
you might be closer than we think.
https://www.avrfreaks.net/forum/sample-project-attiny10 18/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
I've never met a pig I didn't like, as long as you have some salt and pepper.
Top
Log In or Register to post comments
Total votes: 0
share.robinhood.com/jamesc3274
https://www.avrfreaks.net/forum/sample-project-attiny10 19/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
Top
Log In or Register to post comments
Total votes: 0
-- Clear of WDIF (though I don't really know what that might be for -- cascading
events?
I've never met a pig I didn't like, as long as you have some salt and pepper.
Top
Log In or Register to post comments
Total votes: 0
https://www.avrfreaks.net/forum/sample-project-attiny10 20/21
19/1/2019 Sample project for ATTINY10 | AVR Freaks
Torby, thank you for making the comment. I was pulling my hair out tonight
because I Had missed that detail while reading over the programming section on
the datasheet and AtmelStudio doesn't warn you (at least with the AtmelICE)...
As soon as I changed my rail to 5V, it just worked...
Level: New Member
Joined: Wed. Dec 4, 2013
Posts: 1 View posts
Top
Log In or Register to post comments
Jump To
--megaAVR and tinyAVR
Privacy
Contact
Site Use Terms
https://www.avrfreaks.net/forum/sample-project-attiny10 21/21