Announcement

Collapse
No announcement yet.

Arduino code learning

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #46
    Originally posted by ivconic View Post
    You can nick a "tic or few" more if you control the whole port instead picking it's pins separately.
    Even that it's not the method which will provide you accurate timings... unfortunately.
    What you are planning with this? Are you planning further improving... let's say adding a LCD and digital audio output?
    Maybe soft buttons and more "jingle&bells"?
    Each functionality you add later; will affect your present timings.
    Without use of interrupts there is not much that can be done on this subject.
    Problem is if you pick a timer for such task; you'll have to trim it and any customizing will affect some of the functions which are dependable on that timer.
    I was carefully followed Joop's attempt on "PI ported to Arduino" and he did very basic but neat and precise job there.
    Joop realized that you can't do much more of the things you probably wanted; if you stay within Arduino IDE limits.
    Unfortunately it is true.
    Using his approach i made small step forward by implementing I2C LCD and displaying (by now) only one variable on it.
    I can share it here just as an example.
    I took Barracuda and just pulled out CD40106 from it. Than attached Arduino on it's place...
    [ATTACH]38775[/ATTACH]

    Code:
    #include <Wire.h> 
    #include <LiquidCrystal_I2C.h>
    #include <LCDBitmap.h>
    LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
    LCDBitmap bitmap(&lcd, 12, 0);
    #define DIGITAL_OUT PORTB
    #define TX_PIN_A 5       // 13     
    #define SAMPLE_PIN_B 4   // 12 
    #define SAMPLE_PIN_C 3   // 11
    unsigned int Sample1Delay = 65295;
    static int value;
    static int Mikrosekunde;
    void setup ()
    {
    Generator (); 
    InitTimer2 ();
    InitTimer1 ();
    TCNT2 = 200; 
    Serial.begin(1200);
     lcd.begin(16,2);
     welcome();
    }
    void VoidDelay (unsigned int n)
    {
    n += 12; 
    TCNT1 = n; 
    bitSet (TIFR1, TOV1);
    while (!(TIFR1 & (1<<TOV1))) {;} 
    }
    void loop ()
    {
    serial_radno1(); 
    lcd_delay_ispis();      
    }
    void InitTimer1 (void)
    {
    TCCR1A = 0;
    TCCR1B = 0;
    bitClear (TIMSK1, TOIE1); 
    TCNT1 = 0; 
    TCCR1B = 0x01; 
    }
    void InitTimer2 (void)
    {
    TCCR2A = 0;
    TCCR2B = 0;
    bitSet (TIMSK2, TOIE2); 
    TCCR2B = 0x05; 
    }
    void Generator (void)
    {
    DDRB = B00111111; 
    }
    void ReadDelayPot (void)
    {
    value = analogRead(A3);
    Sample1Delay = 65535 - 16 - value; 
    Mikrosekunde = (65535 -Sample1Delay)/16;
    }
    ISR (TIMER2_OVF_vect)
    {
    TCNT2 = 47; 
    //******************************** MAIN PULSE - TX ******************************
    DIGITAL_OUT |= (1<<TX_PIN_A);                  
    VoidDelay (63935);  
    DIGITAL_OUT &= ~(1<<TX_PIN_A);                  
    //******************************** MAIN DELAY ***********************************
    VoidDelay (Sample1Delay);
    //****************************** MAIN DELAY PULSE *******************************
    DIGITAL_OUT |= (1<<SAMPLE_PIN_B);            
    VoidDelay (64850); 
    DIGITAL_OUT &= ~(1<<SAMPLE_PIN_B);            
    //******************************** EF DELAY *************************************
    VoidDelay (65135); 
    //****************************** EF DELAY PULSE *********************************
    DIGITAL_OUT |= (1<<SAMPLE_PIN_C);                
    VoidDelay( 64850); 
    DIGITAL_OUT &= ~(1<<SAMPLE_PIN_C); 
    //******************************** EF+TX DELAY **********************************
    VoidDelay( 64850); 
                 
    ReadDelayPot();
    }
    void welcome()
    {
     lcd.clear ();
     lcd.setCursor(2, 0);
     lcd.print("BARRACUDA");
     bitmap.begin();  
     bitmap.home();
     for (byte x=0; x<=4; x++) 
      {
        bitmap.line(x, BITMAP_H-1, x+BITMAP_H-1, 0, ON, NO_UPDATE);  
        bitmap.line(x, 0, x+BITMAP_H-1, BITMAP_H-1, ON, NO_UPDATE);  
      }
      bitmap.update();   
    }
    void lcd_delay_ispis()
    {
          lcd.setCursor(0, 1);
          lcd.print("D=");
          lcd.print(Mikrosekunde);
          lcd.print("uS ");
          delay(50);
    } 
    void serial_radno1()
    {
      Serial.print("Analogue Value= ");  
      Serial.print(value);
      Serial.println();
      Serial.print("Sample1Delay= "); 
      Serial.print(Sample1Delay);
      Serial.println(); 
      Serial.print("Mikrosekunde= ");
      Serial.print(Mikrosekunde);
      Serial.print("uS");
      Serial.println();
    }

    Ivconic
    Why did you add R35 100k ? thanks

    Comment


    • #47
      Originally posted by 6666 View Post
      Ivconic
      Why did you add R35 100k ? thanks
      Good question!
      Because... i don't know?
      It is taken from old schematic from the past.
      That resistor does not exist on pcb which i used here:


      Click image for larger version

Name:	BarraApBerg.JPG
Views:	1
Size:	662.9 KB
ID:	348074

      Comment


      • #48
        Originally posted by ivconic View Post
        Good question!
        Because... i don't know?
        It is taken from old schematic from the past.
        That resistor does not exist on pcb which i used here:


        [ATTACH]39191[/ATTACH]

        Thanks so I guess its not required ?

        Comment


        • #49
          for those who can read a bit german
          https://www.arduinoforum.de/referenz.php

          Comment


          • #50
            Originally posted by 6666 View Post
            Thanks so I guess its not required ?

            No, it is not required.
            It is missing on my pcb.
            Barracuda is working just fine.

            Comment


            • #51
              Originally posted by bernte_one View Post
              for those who can read a bit german
              https://www.arduinoforum.de/referenz.php
              I have this, but due forum limitations i couldn't upload it in original form, i had to shrink it and degrade quality of document:
              Attached Files

              Comment


              • #52
                Code:
                [COLOR=#ff0000]#include <Wire.h>[/COLOR]
                #include <LiquidCrystal_I2C.h>
                #include <LCDBitmap.h>
                The library LiquidCrystal_I2C already includes Wire.h, so this line is not required.

                Comment


                • #53
                  Originally posted by Teleno View Post
                  Code:
                  [COLOR=#ff0000]#include <Wire.h>[/COLOR]
                  #include <LiquidCrystal_I2C.h>
                  #include <LCDBitmap.h>
                  The library LiquidCrystal_I2C already includes Wire.h, so this line is not required.
                  Good point!
                  Although i will have to check, because i am using customized I2C library, not standard one.
                  Maybe it is including Wire.h and maybe not, i will check.
                  Thanks anyway!

                  Comment

                  Working...
                  X