Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
et:examples:sensor:encoder [2015/02/25 14:01] raivo.sellet:examples:sensor:encoder [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-~~PB~~+<pagebreak>
 ====== Kooder ====== ====== Kooder ======
  
-//Vajalikud teadmised: [HW] [[et:hardware:homelab:digi]], [HW] [[et:hardware:homelab:combo]], [LIB] [[et:software:homelab:library:module:encoder]], [LIB] [[et:software:homelab:library:module:lcd_graphic]], [AVR] [[et:avr:timers]]//+//Vajalikud teadmised:  
 +[HW] [[et:hardware:homelab:digi]], [HW] [[et:hardware:homelab:combo]], 
 +[LIB] [[et:software:homelab:library:module:encoder]], \\ 
 +[LIB] [[et:software:homelab:library:module:lcd_graphic]],  
 +[AVR] [[et:avr:timers]], [AVR] [[et:avr:interrupts]]//
  
 ===== Teooria ===== ===== Teooria =====
Line 41: Line 45:
 #define NUM_ENCODERS 2 #define NUM_ENCODERS 2
  
-// Koodri pulside arvu määramine sekundis+// Koodri pulsside arvu määramine sekundis
 #define ENCODER_TICKS (F_CPU / 8 / 256) #define ENCODER_TICKS (F_CPU / 8 / 256)
  
Line 66: Line 70:
  
 // Katkestused // Katkestused
-ISR(INT6_vect) +ISR(INT6_vect) {
-{+
  encoder_pulse(0);  encoder_pulse(0);
 } }
  
  
-ISR(INT7_vect) +ISR(INT7_vect) {
-{+
  encoder_pulse(1);  encoder_pulse(1);
 } }
Line 80: Line 82:
 void encoder_init(unsigned char index) void encoder_init(unsigned char index)
 { {
- // Viigud sisendistamine väljundiks+ // Viigu sisendiks seadistamine koos pull-up takistite lubamisega
  pin_setup_input_with_pullup(encoder_pins[index]);  pin_setup_input_with_pullup(encoder_pins[index]);
   
Line 103: Line 105:
 } }
  
-// Valitud kooderi nullimine+// Valitud koodri nullimine
 void encoder_reset_pulses(unsigned char index) void encoder_reset_pulses(unsigned char index)
 {  {
Line 111: Line 113:
 } }
  
-// Koodri pulside arvu loendamine+// Koodri pulsside arvu loendamine
 unsigned short encoder_get_pulses(unsigned char index) unsigned short encoder_get_pulses(unsigned char index)
 {  {
Line 121: Line 123:
  
 <code c> <code c>
-// Kodulabori koodri kasutamise näide+// Kodulabori koodri kasutamise näidisprogramm
 // LCD-le kuvatakse koodri pulsside arv // LCD-le kuvatakse koodri pulsside arv
 #include <stdio.h> #include <stdio.h>
Line 135: Line 137:
  char text[16];  char text[16];
  
- // Nupu seadmistamine+ // Nupu seadistamine
  pin_setup_input_with_pullup(S2);  pin_setup_input_with_pullup(S2);
  
Line 146: Line 148:
  // LCD ekraani algseadistamine  // LCD ekraani algseadistamine
  lcd_gfx_init();  lcd_gfx_init();
-  lcd_gfx_clear(); + lcd_gfx_clear(); 
-  lcd_gfx_backlight(true);  + lcd_gfx_backlight(true);  
-  lcd_gfx_goto_char_xy(3, 1);+ lcd_gfx_goto_char_xy(3, 1);
  lcd_gfx_write_string("Kooder");  lcd_gfx_write_string("Kooder");
      
  // Lõputu tsükkel   // Lõputu tsükkel
- while (true)+ while (1)
  {  {
  pulses = encoder_get_pulses(1);  pulses = encoder_get_pulses(1);
   
  // Teksti moodustamine.  // Teksti moodustamine.
- sprintf(text, "Pulsse: %d",pulses);+ sprintf(text, "Pulsse: %5d",pulses);
     
  lcd_gfx_goto_char_xy(0, 3);  lcd_gfx_goto_char_xy(0, 3);
  lcd_gfx_write_string(text);  lcd_gfx_write_string(text);
  
- // Nupp S2 alla vajutatud ?+ // Nupp S2 alla vajutatud?
  if(button_read(S2))  if(button_read(S2))
  {  {
et/examples/sensor/encoder.1424872895.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0