View previous topic :: View next topic |
Author |
Message |
erwin4838
Joined: 24 Feb 2012 Posts: 39 Location: Indonesia
|
Posted: Fri Feb 24, 2012 9:14 pm Post subject: Please help me (Attiny 2313 & 7segment) |
|
|
dear all
master
i'm a new begining in this forum and i new begin to learn microntroller,in the first project i'm use attiny 2313,because very simple,please help me master brother and sister to bulid speedometer digital with two digit 7segment and using chip attiny 2313,please give me code and schematic ,standart parameter time in 1 minute and diameter plate write sensore is 60mm,tanks
best regrast
erwin |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Sat Feb 25, 2012 8:25 am Post subject: |
|
|
Hi,
Try use Forum Serach for "speedometer" _________________ / Kim |
|
Back to top |
|
|
erwin4838
Joined: 24 Feb 2012 Posts: 39 Location: Indonesia
|
Posted: Sat Feb 25, 2012 8:47 am Post subject: |
|
|
ok i'll try,but if i have'nt find no match in my mind,please help me tks |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Sun Feb 26, 2012 10:21 am Post subject: |
|
|
Hi,
What type is your 7seg displays common Anode or Cathode , BCD or normal ?
maybe a model number .
do you need it to update 7Seg via a timer ? _________________ / Kim |
|
Back to top |
|
|
erwin4838
Joined: 24 Feb 2012 Posts: 39 Location: Indonesia
|
Posted: Sun Feb 26, 2012 2:08 pm Post subject: |
|
|
Common Anode sir,yes i have 7seg via timer,by the way i have source code and schematic like this :
Code: | #define F_CPU 1000000UL // adjust clock CKSEL !!
#include <avr/io.h>
#include <util/delay.h>
#include <avr/eeprom.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <avr/iotn2313.h>
#include <avr/pgmspace.h>
uint8_t angka1=10 ;
uint8_t angka2=10 ;
uint8_t angka3=10 ;
uint8_t angka4=10 ;
uint8_t segstep=0;
uint8_t kalibrasi=3;
int number=0;
void conv_segmen(uint8_t digit)
{
switch (digit)
{
case 0 :
{
PORTB &= ~_BV(PB0) & ~_BV(PB1) & ~_BV(PB2) & ~_BV(PB3) & ~_BV(PB4) & ~_BV(PB5);
PORTB |= _BV(PB6) ;
break;
}
case 1 :
{
PORTB &= ~_BV(PB1) & ~_BV(PB2) ;
PORTB |= _BV(PB0) | _BV(PB3) | _BV(PB4) | _BV(PB5) | _BV(PB6) ;
break;
}
case 2 :
{
PORTB &= ~_BV(PB0) & ~_BV(PB1) & ~_BV(PB3) & ~_BV(PB4) & ~_BV(PB6) ;
PORTB |= _BV(PB2) | _BV(PB5) ;
break;
}
case 3 :
{
PORTB &= ~_BV(PB0) & ~_BV(PB1) & ~_BV(PB2) & ~_BV(PB3) & ~_BV(PB6) ;
PORTB |= _BV(PB4) | _BV(PB5) ;
break;
}
case 4 :
{
PORTB &= ~_BV(PB1) & ~_BV(PB2) & ~_BV(PB5) & ~_BV(PB6) ;
PORTB |= _BV(PB0) | _BV(PB3) | _BV(PB4) ;
break;
}
case 5 :
{
PORTB &= ~_BV(PB0) & ~_BV(PB2) & ~_BV(PB3) & ~_BV(PB5) & ~_BV(PB6) ;
PORTB |= _BV(PB1) | _BV(PB4) ;
break;
}
case 6 :
{
PORTB &= ~_BV(PB0) & ~_BV(PB2) & ~_BV(PB3) & ~_BV(PB4) & ~_BV(PB5) & ~_BV(PB6) ;
PORTB |= _BV(PB1) ;
break;
}
case 7 :
{
PORTB &= ~_BV(PB0) & ~_BV(PB1) & ~_BV(PB2) ;
PORTB |= _BV(PB3) | _BV(PB4) | _BV(PB5)| _BV(PB6) ;
break;
}
case 8 :
{
PORTB &= ~_BV(PB0) & ~_BV(PB1) & ~_BV(PB2) & ~_BV(PB3) & ~_BV(PB4) & ~_BV(PB5) & ~_BV(PB6);
break;
}
case 9 :
{
PORTB &= ~_BV(PB0) & ~_BV(PB1) & ~_BV(PB2) & ~_BV(PB3) & ~_BV(PB5) & ~_BV(PB6);
PORTB |= _BV(PB4) ;
break;
}
case 10 :
{
PORTB |= _BV(PB0) | _BV(PB1) | _BV(PB2) | _BV(PB3) | _BV(PB4) | _BV(PB5) | _BV(PB6) ;
break;
}
case 11 :
{
PORTB &= ~_BV(PB4);
PORTB |= _BV(PB0) | _BV(PB1) | _BV(PB2) | _BV(PB3) | _BV(PB5) | _BV(PB6);
break;
}
case 12 :
{
PORTB &= ~_BV(PB4) & ~_BV(PB2);
PORTB |= _BV(PB0) | _BV(PB1) | _BV(PB3) | _BV(PB5) | _BV(PB6);
break;
}
case 13 :
{
PORTB &= ~_BV(PB4) & ~_BV(PB2) & ~_BV(PB5);
PORTB |= _BV(PB0) | _BV(PB1) | _BV(PB3) | _BV(PB6) ;
break;
}
case 14 :
{
PORTB &= ~_BV(PB4) & ~_BV(PB1) & ~_BV(PB2) & ~_BV(PB5);
PORTB |= _BV(PB0) | _BV(PB3) | _BV(PB6) ;
break;
}
}
}
void animasi(uint8_t posisi)
{
switch(posisi) {
case 0 :{ angka4=10; angka3=10 ; angka2=10; angka1=10;
break; }
case 1 :{ angka4=11; angka3=10 ; angka2=10; angka1=10;
break; }
case 2 :{ angka4=12; angka3=10 ; angka2=10; angka1=10;
break; }
case 3 :{ angka4=12; angka3=11 ; angka2=10; angka1=10;
break; }
case 4 :{ angka4=12; angka3=12 ; angka2=10; angka1=10;
break; }
case 5 :{ angka4=12; angka3=12 ; angka2=11; angka1=10;
break; }
case 6 :{ angka4=12; angka3=12 ; angka2=12; angka1=10;
break; }
case 7 :{ angka4=12; angka3=12 ; angka2=12; angka1=11;
break; }
case 8 :{ angka4=12; angka3=12 ; angka2=12; angka1=12;
break; }
case 9 :{ angka4=13; angka3=12 ; angka2=12; angka1=12;
break; }
case 10 :{ angka4=14; angka3=12 ; angka2=12; angka1=12;
break; }
case 11 :{ angka4=14; angka3=13 ; angka2=12; angka1=12;
break; }
case 12 :{ angka4=14; angka3=14 ; angka2=12; angka1=12;
break; }
case 13 :{ angka4=14; angka3=14 ; angka2=13; angka1=12;
break; }
case 14 :{ angka4=14; angka3=14 ; angka2=14; angka1=12;
break; }
case 15 :{ angka4=14; angka3=14 ; angka2=14; angka1=13;
break; }
case 16 :{ angka4=14; angka3=14 ; angka2=14; angka1=14;
break; }
default :{ angka4=14; angka3=14 ; angka2=14; angka1=14;
}
}
}
void init_ctr(void)
{
TCCR0A |= (1 << WGM01); // Configure timer 0 for CTC mode
TIMSK |= (1 << OCIE0A); // Enable CTC interrupt
OCR0A = 50; // Set CTC compare value till blink disapear at 1MHz AVR clock, with a prescaler of 64
TCCR0B |= (1 << CS01)|(1 << CS00); // Start timer at Fcpu/64
}
void init_ctr1(void)
{
TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode
TIMSK |= (1 << OCIE1A); // Enable CTC interrupt
OCR1A = 586; //compare the CTC A = 600ms =586
TCCR1B |= ((1 << CS10) | (1 << CS12)); // Start timer at Fcpu/1024
}
ISR(TIMER1_COMPA_vect) //timer capture RPM count
{ uint16_t rpm,anime;
anime=0;
switch(kalibrasi) {
case 1 :{
rpm=number/100;
break; }
case 2 :{
rpm=number/10;
break; }
case 3 :{
rpm=number;
break; }
case 4 :{
rpm=number*10;
break; }
case 5 :{
rpm=number*100;
break; }
case 6 :{
anime=1;
break; }
case 7 :{
anime=2;
break; }
default: rpm=0;
}
switch(anime) {
case 0 : {
OCR1A = 586;
angka1 = rpm%10;
if(rpm>9) angka2 = ((rpm%100) - (rpm%10)) /10 ;
else angka2=10;
if(rpm>99) angka3 = ((rpm%1000) - (rpm%100)) /100 ;
else angka3=10;
if(rpm>999) angka4 = ((rpm%10000) - (rpm%1000)) /1000 ;
else angka4=10;
break ; }
case 1 : {
OCR1A = 100;
animasi(number/50);
break ; }
case 2 : {
OCR1A = 100;
animasi(number/2600);
break ; }
}
number=0;
}
ISR(TIMER0_COMPA_vect) // timer migration column
{
segstep++;
switch(segstep) {
case 1 :{ conv_segmen(10);
PORTD |= _BV(PD0);
PORTD &= ~_BV(PD1) & ~_BV(PD4) & ~_BV(PD5) ;
conv_segmen(angka1);
break;
}
case 2 :{ conv_segmen(10);
PORTD |= _BV(PD1);
PORTD &= ~_BV(PD0) & ~_BV(PD4) & ~_BV(PD5) ;
conv_segmen(angka2);
break;
}
case 3 :{ conv_segmen(10);
PORTD |= _BV(PD4);
PORTD &= ~_BV(PD1) & ~_BV(PD0) & ~_BV(PD5) ;
conv_segmen(angka3);
break;
}
case 4 :{ conv_segmen(10);
PORTD |= _BV(PD5);
PORTD &= ~_BV(PD1) & ~_BV(PD4) & ~_BV(PD0) ;
conv_segmen(angka4);
segstep=0;
break;
}
}
}
SIGNAL (SIG_INT0)
{
number++;
}
void tombol(void)
{
if(bit_is_clear(PIND, PIND3))
{
cli();
kalibrasi++;
if (kalibrasi == 8) kalibrasi=1;
eeprom_write_byte((uint8_t*)10, kalibrasi);
conv_segmen(10);
_delay_ms(200);
sei();
}
}
void baca_eeprom(void)
{
kalibrasi = eeprom_read_byte((uint8_t*)10);
if(kalibrasi == 0xFF) kalibrasi=3;
}
int main(void)
{
GIMSK |= (1<<INT0) ; // inetrupt for accunt pulse
MCUCR |= (1<<ISC01)| (1<<ISC11); //fall edge
DDRD |= _BV(PD0) | _BV(PD1) | _BV(PD4) | _BV(PD5) ; // segmen select
DDRB |= _BV(PB0) | _BV(PB1) | _BV(PB2) | _BV(PB3) | _BV(PB4) | _BV(PB5) | _BV(PB6) ; // seg a,b,c,d,e,f,g
DDRD &= ~_BV(PD3) ; // Input calibrasi
init_ctr();
init_ctr1();
baca_eeprom();
sei();
while(1)
{
tombol();
}
}
|
but when i'll try it doesn't work,S1 in shematic nothing respon in 7segment,next if this project came true i'll change S1 with sensore to read circle with one hole,exactly i'm not understand with "INTERUPT" in this schematic,please help me |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Sun Feb 26, 2012 3:10 pm Post subject: |
|
|
That is C code not for bascom use
sch show 4 7seg you ask for 2 7segment _________________ / Kim |
|
Back to top |
|
|
erwin4838
Joined: 24 Feb 2012 Posts: 39 Location: Indonesia
|
Posted: Sun Feb 26, 2012 10:04 pm Post subject: |
|
|
i'm very sory i'm wrong upload,i'm mean like this,but output build use LCD ,how to convert this output with 7segment,i'm very very sory
Code: | 'kristal
$crystal = 11059200
'konfigurasi tmr0
Config Timer0 = Timer , Prescale = 64 'timer 1 detik
Config Timer1 = Counter , Edge = Rising 'counter, external trigger
On Timer0 Gate_timer
On Timer1 Timer1_over
Dim Cnt_total As Long At &H60
Dim Cnt_lo As Word At &H60 Overlay
Dim Cnt_hi As Word At &H62 Overlay
Dim Gate_cnt As Word
Dim Freq As Single , F_str As String * 16 , F_str_cnt As Byte
Cls
Cursor Off
Lcd "Freq"
Ddrb.1 = 0 'input pin capture t1
Enable Interrupts
Enable Timer0
Start Timer0
Stop 'loop trus
'isr gate
Gate_timer:
If Gate_cnt = 0 Then
Enable Timer1
Start Timer1
Gate_cnt = 1
Elseif Gate_cnt < 675 Then
Incr Gate_cnt
Else
Stop Timer1
Disable Timer1
Cnt_lo = Counter1
Counter1 = 0
Gate_cnt = 0
F_str = Str(cnt_total)
If Cnt_total < 1000 Then
F_str = Format(f_str , " ")
Locate 2 , 1
Lcd Spc(1) ; F_str ; " Hz"
Elseif Cnt_total >= 1000 And Cnt_total < 1000000 Then
F_str = Format(f_str , " . ")
Mid(f_str , 9 , 1) = ","
Locate 2 , 1
Lcd F_str ; " KHz"
Else
F_str = Format(f_str , " . ")
Mid(f_str , 6 , 1) = ","
Locate 2 , 1
Lcd F_str ; " MHz"
End If
Cnt_total = 0
Tifr.tov0 = 1 'Erase Timer0-Overflow-Flag
Tifr.tov1 = 1 'Erase Timer1-Overflow-Flag
End If
Return
'isr cunter
Timer1_over:
Incr Cnt_hi
Return
| |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Mon Feb 27, 2012 2:32 am Post subject: |
|
|
Hmmm this have nothing to do with speedo and 7seg
its for lcd freqvence
Here is a TEST code for 2x7SEG count up 0-99
login to see addon file _________________ / Kim |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Mon Feb 27, 2012 8:56 am Post subject: |
|
|
So what you now need is to add a timer1 & Int0
for timing and sensor to make puls for speed _________________ / Kim |
|
Back to top |
|
|
erwin4838
Joined: 24 Feb 2012 Posts: 39 Location: Indonesia
|
Posted: Mon Feb 27, 2012 1:01 pm Post subject: |
|
|
Thank very much this code n schematic 100%work:D ,but its only count progress,where i place sensor/switch to get stabil digit when sensore/switch read in constant speed? |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Mon Feb 27, 2012 4:52 pm Post subject: |
|
|
Hi
The sensor output is HIGH(+5V) or LOW (0V) ???
is RADIUS 60mm or is i diameter ?
what is circumference ?
Circumference = diameter x Pi
do the sensor read at edge of the plate ?? _________________ / Kim |
|
Back to top |
|
|
erwin4838
Joined: 24 Feb 2012 Posts: 39 Location: Indonesia
|
Posted: Mon Feb 27, 2012 10:19 pm Post subject: |
|
|
the sensor range (5 to 12v),i'll try in 5v still work
60mm is all diameter,not half
yes the sensor read at edge of the plate, |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Mon Feb 27, 2012 10:40 pm Post subject: |
|
|
Hi
Now you add the puls from sensor to INT0 pin MAX +5v !!!
and I have change crystal to 8 Mhz intren !!!!! was 1 Mhz before
Ok here is a test (bin/Hex) _________________ / Kim |
|
Back to top |
|
|
erwin4838
Joined: 24 Feb 2012 Posts: 39 Location: Indonesia
|
Posted: Mon Feb 27, 2012 10:50 pm Post subject: |
|
|
thanks for you kindness,i'll try afternoon,cause this morning time to activity(havn't computer),i'll send you report afternoon/tonight,glad get acquainted with you
|
|
Back to top |
|
|
erwin4838
Joined: 24 Feb 2012 Posts: 39 Location: Indonesia
|
Posted: Tue Feb 28, 2012 3:41 pm Post subject: |
|
|
sory sir/mis 7 segment can't work,they only flicker,nothing respons with sensor/switch |
|
Back to top |
|
|
|