• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
problem w programie Arduino
#1
Witam, robię sobie projekt, jest to moduł mechanicznej modulacji światła na arduino, steruję wentylatorem 4 pinowym za pomocą pwm zmienionego na 30kHz, do tego mam czujnik szczelinowy który zlicza prędkość, potencjometry do regulacji wypełnienia PWM oraz lcd który pokazuje aktualna prędkość. Problem polega na tym, że wszystko ładnie działa, ale tylko wtedy kiedy pwm jest 100%. Pokazuje wtedy prędkosc 2200 rpm a jak zahamuje wentylator palcem to stopniowo maleje. Gdy zmniejsze wypełnienie pozniej 100% to nagle skacze z 2200 na 3800 a nastepnie stopniowo spada wraz ze mniejszaniem wypełnienia, jednak te wartosci skacza w zakresie 100rpm wiec to i tak jakies bzdury. Juz nie wiem co to moze byc, Timer 1 zlicza predkosc a timer 2 przestawia PWM na 30kHz. Prosze o pomoc


Kod:
#include <LiquidCrystal_I2C.h>
#include "TimerOne.h"
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
const byte SpeedSensor = 2;
volatile unsigned int counter = 0;
volatile unsigned int counterStan = 0;
float diskslots = 6;
float Speed = 0;

int timeToWait = 1000; //Czas, który ma czekać
int setTime=0;              
int aktualTime=0;
int done;

int odczytanaWartosc = 0;
void ISR_count()
{
  counter++;
}

void ISR_timerone()
{
  Timer1.detachInterrupt();
  counterStan = counter;
  Speed = (counter / diskslots) * 60.00;
  counter = 0;
  Timer1.attachInterrupt( ISR_timerone );
}
void setup() {

   TCCR2B = TCCR2B & B11111000 | B00000001; // Set PWM for D3 & D11
    pinMode(3, OUTPUT); // Sets the pin as output
 
  Timer1.initialize(1000000);
  attachInterrupt(digitalPinToInterrupt (2), ISR_count, RISING);
  Timer1.attachInterrupt( ISR_timerone);
 
  lcd.init();
  lcd.backlight();
 
}

void loop() {

lcd.clear();
 
  setTime = millis();
  done=1;
  while(done){  //Wykonuje się tak długo aż upłynie 1s i wykona się reszta kodu
    aktualTime = millis();
    if (aktualTime < setTime+timeToWait){
  lcd.setCursor(0,0);
  lcd.print("Frequence: ");
  lcd.print(counterStan);
  lcd.setCursor(0,1);
  lcd.print("RPM: ");
  lcd.print(Speed);
}
else
  {  
    odczytanaWartosc = analogRead(A3);
    analogWrite( 3,(odczytanaWartosc/4));
    done=0;
    }
}
}
[Obrazek: 4189131600_1573848755.png]
 
Odpowiedź
  


Wiadomości w tym wątku
problem w programie Arduino - przez sewek10 - 15-11-2019, 22:48
RE: problem w programie Arduino - przez semi - 16-11-2019, 01:14
RE: problem w programie Arduino - przez sewek10 - 16-11-2019, 11:58
RE: problem w programie Arduino - przez semi - 16-11-2019, 12:58
RE: problem w programie Arduino - przez sewek10 - 16-11-2019, 13:09
RE: problem w programie Arduino - przez elvis - 16-11-2019, 12:40
RE: problem w programie Arduino - przez sewek10 - 16-11-2019, 12:57
RE: problem w programie Arduino - przez Agregacik - 16-11-2019, 14:03
RE: problem w programie Arduino - przez sewek10 - 16-11-2019, 14:33
RE: problem w programie Arduino - przez Agregacik - 16-11-2019, 15:07
RE: problem w programie Arduino - przez sewek10 - 16-11-2019, 23:33
RE: problem w programie Arduino - przez semi - 17-11-2019, 00:46
RE: problem w programie Arduino - przez sewek10 - 17-11-2019, 12:31
RE: problem w programie Arduino - przez Agregacik - 17-11-2019, 08:40
RE: problem w programie Arduino - przez sewek10 - 17-11-2019, 12:32
RE: problem w programie Arduino - przez semi - 17-11-2019, 16:39
RE: problem w programie Arduino - przez Jarewa0606 - 17-11-2019, 13:02
RE: problem w programie Arduino - przez Agregacik - 17-11-2019, 13:38
RE: problem w programie Arduino - przez elvis - 17-11-2019, 16:48
RE: problem w programie Arduino - przez sewek10 - 17-11-2019, 17:19

Skocz do:


Przeglądający: 1 gości