Hi all,
I have a problem with a project I am currently doing. I am building an anemometer and have been debugging it via proteus. The schematic is attached to the post. The basic setup is this: there is a rotary encoder which is clocking a counter. The counter bits are being fed to the arduino together with the MR (Master Reset) of the counter. Now the arduino code should do the following:
Set the MR low so that the counter resets.
Every 0.5ms it should read the value of the 4 bits and use the equation found here(Support) to calculate the velocity.
This velocity is displayed on the LCD.
The MR pin is then pulsed so that the counter resets.
The problem is that according to the simulation, the lcd is simply displaying a velocity of -1 and it never changes. I see the counter incrementing and the MR pin being pulsed but the LCD isn't displaying the velocity value. Could someone suggest any possible solutions to the problem?
The code is as follows:
#include <LiquidCrystal.h>
// Connections:
// rs (LCD pin 4) to Arduino pin 19
// rw (LCD pin 5) to Arduino pin 3
// enable (LCD pin 6) to Arduino pin 4
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 6, 25, 12, 14
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int bitstate [4] = {0,0,0,0};
int bitaddress[4] = {6, 7, 8, 9};
int RSTaddress = 0;
int backLight = 13; // pin 13 will control the backlight
int pulses = 100; // indicates the number of pulses per revolution
int fixedtime = 0.5; //fixed time interval in ms
long encoderval = 0;
//int encoderval1,encoderval2 =0;
long velocity=0;
long time = 0;
void setup()
{
pinMode (bitaddress[0], INPUT);
pinMode (bitaddress[1], INPUT);
pinMode (bitaddress[2], INPUT);
pinMode (bitaddress[3], INPUT);
pinMode (RSTaddress, OUTPUT);
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("Wind Speed: "); // change this text to whatever you like. keep it clean.
digitalWrite (RSTaddress, HIGH);
}
void loop()
{
encoderval = 0;
velocity = 0;
digitalWrite (RSTaddress, LOW);
delayMicroseconds (fixedtime*1000); //waits for 0.5ms
bitstate[0]= digitalRead(bitaddress[0]);
bitstate[1]= digitalRead(bitaddress[1]);
bitstate[2]= digitalRead(bitaddress[2]);
bitstate[3]= digitalRead(bitaddress[3]);
encoderval = bitstate[0] + (bitstate[1]*2) + (bitstate[2]*4) + (bitstate[3]*8);
//encoderval1 = PORTD & B11000000;
//encoderval2 = PORTB & B00000011;
//encoderval = (encoderval1 >> 6) & (encoderval2 << 2);
time = fixedtime/1000;
velocity = (encoderval*60)/(pulses*time);
lcd.setCursor (0,1);
lcd.print (velocity);
digitalWrite (RSTaddress, HIGH);
delay (1);
return;
}
Thanks in advance for any help!