Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Project Guidance / Re: Problem about serial monitor on: October 10, 2012, 08:11:37 am
oh....that's great , thanks alot smiley
2  Using Arduino / Project Guidance / Problem about serial monitor on: October 10, 2012, 08:06:29 am
Hey everyone

I have been facing a problem. Actually I am doing a simple thing and that is I am reading data on the serial monitor from 2 arduino boards who are attached with the two serial ports of my laptop. So obviously I have to switch between the ports to see the values on serial monitor but when I switches the ports on serial monitor the previous values related to that port vanishes. I mean for example I am getting the values on serial monitor from port 3 now when I will change the port on serial monitor to port 4 to read the values from other arduino and then when i will switch again to port 3 then it will not show the old values prior to switching and I want to keep record of all the values from the start from both arduinos.

So kindly guide what I need to do.

Thanks
3  Using Arduino / Project Guidance / Timer Clock on: April 01, 2012, 11:46:11 am
Hello Everyone!

I want to ask that can we give external high frequency clock (more than 16 MHz) to the timer of the arduino?
4  Using Arduino / Project Guidance / Re: Measuring Pulse Width on: April 01, 2012, 11:43:22 am
@ Rob

I have made few changes in the code and now the code is working fine smiley check it out but it only misses out 1 count I don't know how we can improve that? I mean for 1 microsecond pulse it is doing 15 counts (theoretically 16) can we give a external high clock to the timer of the arduino? The code is given below

Code:
#include <avr/io.h>
#include <avr/interrupt.h>

volatile uint16_t cnt = 0;
unsigned int pulse_counts = 0;

void setup()
{
  Serial.begin(115200);
  Serial.println("PulseWidthMeter (timer1) 0.1");
  pinMode(3, INPUT);
}

void loop()
{
  // initialize Timer1
  cli();
  // reset counters
  cnt = 0;
  TCNT1 = 0;
  // reset registers
  TCCR1A = 0;
  TCCR1B = 0;

  pulse_counts++;
  // wait for HIGH
  while ((PIND & B00001000) == B00000000);
  // Set CS10 bit so timer runs at clock speed: 16 MHz
  TCCR1B |= (1 << CS10);
  // enable Timer1 overflow interrupt:
  TIMSK1 = (1 << TOIE1);

  // enable global interrupts:
//  sei();

  // keep counting until LOW
  while ((PIND & B00001000) == B00001000);
  // stop IRQ's


  TIMSK1 = 0;
  TCCR1B = 0;
 // cli();

    // Read the counters and convert to long
  uint16_t x = TCNT1;  // work copy
  uint32_t total = (uint32_t)cnt  + (uint32_t)x;
  float usec = (1.0 * total) / 16;

  // Display values
  Serial.print(x, DEC);
  Serial.print(" \t ");
  Serial.print(usec, 2);
  Serial.print(" \t ");
  Serial.print("Count = ");
  Serial.println(pulse_counts);

  // Wait a while
//  delay(1000);
}

// count the overflows in IRQ
ISR(TIMER1_OVF_vect)
{
  cnt++;
}
5  Using Arduino / Project Guidance / Re: Measuring Pulse Width on: March 31, 2012, 11:05:46 am
@ Rob

I am using a simple function generator and giving the pulses from it and yes I have connected both the grounds of the arduino board. I am applying the pulses to the BNC connector and from there I am giving the pulses to the digital pin 3 (D3) and I am not using pull down/up resistor. But did you also check the code output? Can you too check the output and then make the comparison with mine?

Thanks
6  Using Arduino / Project Guidance / Re: Measuring Pulse Width on: March 31, 2012, 08:49:11 am
Attached is the output of the image for pulses from 1 to 10 microsecond I applied 1 microsecond pulse width and then changed it into steps upto 10 microsecond
7  Using Arduino / Project Guidance / Re: Code Correction on: March 30, 2012, 11:56:16 am
I am measuring pulse widths between 5 microseconds to 15 microseconds. I am giving these pulses from function generator by setting 1 Hz frequency. The code which I posted in my thread displays 1 microsecond or 0.5 microsecond when I give 1 microsecond width pulse similarly it gives either 10 or 9.5 when I apply 10 microsecond pulse width and so on so if for example when I give 10.3 or 10.2 or 10.1 it keeps on giving me 10 or 10.5 so it is not giving me correct reading for such values and that's what my problem is....

So what do you think now?
8  Using Arduino / Project Guidance / Re: Code Correction on: March 30, 2012, 10:53:53 am
Thanks for following up but actually I don't need 1 count per microsecond I am already getting 3 counts per microsecond but I need accuracy in my measurements for which it is not enough. What do you think using a external fast counter with following sequence would solve my problem?

providing 12 MHz clock from function generator
providing the pulse to the enable input.
Make an interrupt into the Arduino when the pulse has a negative edge (end of pulse.)
Read and reset the counter from the Arduino.

If I use 8 bit external fast counter with the above sequence?

9  Using Arduino / Project Guidance / Code Correction on: March 30, 2012, 09:40:20 am
Hello Everyone the code given below is used for pulse width measurement for pulses as short as 5 to 5 microseconds which I am giving to arduino from function generator. The code makes almost 3 counts every 3 microsecond which is not good since the count should be much more for a 16MHz clock frequency of arduino so if anyone can help me with this in achieving the correct counts every microsecond.

Thank you all in advance!

Code:

#include<stdlib.h>

unsigned int pulse_counts = 0;

unsigned int count = 0;
void setup()
{
  Serial.begin(9600);
  pinMode(3, INPUT);  
}

void loop()
{
  count = 0;
  pulse_counts++;
  while ((PIND & B00001000) == B00000000); // wait for HIGH
  while ((PIND & B00001000) == B00001000) count++; // start counting until LOW

  float usec = 1.0 * count * 6/12;
  Serial.print("Count = ");
  Serial.print(pulse_counts);
  Serial.print(" , Width = ");
  Serial.print(usec, 2);
  Serial.println ("  microseconds");


//  delay(1000);
}
10  Using Arduino / Project Guidance / Code Improvement on: March 29, 2012, 03:35:26 am
Hello Everyone!

I have posted my code below which I have been using to measure pulse widths for 5 to 15 microsecond pulses. I am giving pulses from function generator with 1 or 2 Hz frequency. But my code makes one count every four microseconds so it measures pulse widths if the pulse is 4 microsecond or 8 or 12 and so on but not the values in between , for example for 10 microsecond pulse it measures either 8 or 12. I thought of using a external fast counter to improve get the accuracy but I have come to know that 16 MHz clock of arduino is more than enough to get the right results so if someone can help me out here with my code I would be extremely grateful to all of you.

Thanks all in advance and here is my code


#define ICP PINB0
//Variables holding three timestamps
  volatile uint16_t ov_counter, rising, falling;
//capture Flag
  volatile unsigned int flag = 0;
  volatile uint32_t counts;
  volatile uint16_t time;
  int val = 0;     // variable to store the read value
  int lastPulse = LOW;
  int count = 1;
//Initialize timer
  float pulse_width= 0.0;

//capture ISR
ISR(TIMER1_CAPT_vect)
{

//if(ICP)
//if (digitalRead (smiley-cool == HIGH)

if ((PINB & B00000001) == B00000001)

            {

            //save start time

            rising=ICR1;

            //set to trigger on falling edge

            //TCCR1B&=~(1<<ICES1);
             TCCR1B &= 0xBF;
            //reset overflow counter

            ov_counter=0;

   }

else

            {

            //save falling time

            falling=ICR1;
            TCNT1 = 0;
            //rising edge triggers next
           
           //TCCR1B|=(1<<ICES1);
            TCCR1B |= 0x40;
           
            counts=(uint32_t)falling-(uint32_t)rising + (uint32_t)ov_counter;
       
            /*you can convert coutns to seconds and send to LCD*/
 
           
             }
}
//Overflow ISR
ISR(TIMER1_OVF_vect)
{
//increment overflow counter
ov_counter++;
}

void setup()
{
  Serial.begin(9600) ;
  delay(100);
  Serial.println("test");
//Set Initial Timer value
TCNT1=0;
//First capture on rising edge
TCCR1B|=(1<<ICES1)| (1<<CS10) | (1<<ICNC1);
//TCCR1B|=(1<<ICES1)| (1<<CS10);
//Enable input capture and overflow interrupts
TIMSK1|=(1<<ICIE1)|(1<<TOIE1);
//Enable global interrutps
sei();
}


void loop()
{

   val = digitalRead (smiley-cool;   // read the input pin
            if (val != lastPulse)
   {
   
               lastPulse = val;
               
              if (val == LOW)   
          {       
           
             //   cli();
                pulse_width = counts*4;
                Serial.print("width = ");
                Serial.print(pulse_width);
                Serial.print("  count = ");
                Serial.println(count++);
                                //clear overflow counters;
                ov_counter=0;

                //clear interrupt flags to avoid any pending interrupts
            //    TIFR1=(1<<ICF1)|(1<<TOV1);
                //enable input capture and overflow interrupts
             //   TIMSK1|=(1<<ICIE1)|(1<<TOIE1);
           //   highCounter++;
             
            //    sei();

              }
         
   }


   
 
}
 
11  Using Arduino / Project Guidance / Re: Measuring Pulse Width on: March 28, 2012, 02:08:02 pm
@Robtillaart

Thanks alot and actually I am back to my room and I would check it now tomorrow and then would confirm you, thanks again
12  Using Arduino / Project Guidance / Re: External Counter on: March 28, 2012, 11:16:04 am
it is a continuous train of pulses I am providing the pulses from function generator with 1 Hz frequency
13  Using Arduino / Project Guidance / External Counter on: March 28, 2012, 08:54:57 am
Hello Everyone!

I am stuck with my problem from quite some time now and could not get the solution yet. Actually I have to measure pulse widths accurately but my code is not giving me good resolution and hence the accuracy since the pulses are very short only 5 to 15 microseconds in  duration, my code measures the widths after every 1 microsecond but not the values in between them- Here is my code


#include<stdlib.h>

unsigned int pulse_counts = 0;
char buffer[20];
char buffer2[20];
char s[4]=" , ";

unsigned int count = 0;
void setup()
{
  Serial.begin(9600);
//  Serial.println("pulse width measurment");

  pinMode(3, INPUT); 
}

void loop()
{
  count = 0;
  pulse_counts++;
  while ((PIND & B00001000) == B00000000); // wait for HIGH
  while ((PIND & B00001000) == B00001000) count++; // start counting until LOW

  float usec = 1.0 * count * 6/12;
 
  // For text file output - Uncomment this
 
//  Serial.print("#S|AAA|[");
//  Serial.print(dtostrf(usec,5,2,buffer));
//  Serial.print(s);
//  Serial.print(itoa((pulse_counts), buffer2, 10));
//  Serial.println("]#");


  // For serial output display - Uncomment this
 
  Serial.print("Count = ");
  Serial.print(pulse_counts);
  Serial.print(" , Width = ");
  Serial.print(usec, 2);
  Serial.println ("  microseconds");


//  delay(1000);
}

So I have to now use some external fast counter which can bring more accuracy and I have found one fast counter given by the link below but I don't know whether and how I could use this to achieve better results so please guide.

http://se.farnell.com/stmicroelectronics/m74hc590b1r/ic-counter-receiver-8bit-binary/dp/1652001?ref=lookahead

Thank you all in advance!
14  Using Arduino / Project Guidance / Help!!!! on: March 28, 2012, 03:04:16 am
Hello Everyone!

I have been trying to fix my problem from quite some time now but I could not. I have to measure the pulse widths of very short pulses between widths 5 to 15 microseconds accurately and I need a very good resolution for that. The best I could do by doing programming is measuring pulse widths after every microsecond like if the pulse width is 1 microsecond I could measure it and if it is 2 I could still measure it but not the values in between so the resolution is not good smiley-sad . Now there are two alternatives either to use a fast external adc like the one given by the link below it has a 0.42 ┬Ás conversion time (or if someone can tell me a better adc with such conversion time and whose interfacing is easy as well?)

http://www.farnell.com/datasheets/10894.pdf

or to use a external fast counter like the one shown below and if this counter is provided with lets say 10 MHz clock and the signal whose width is to be measured is applied to enable input and then making an interrupt into the Arduino when the pulse has a negative edge (end of pulse.)
Read and reset the counter from the Arduino.

So please guide me here everyone I would be grateful to all of you.

15  Using Arduino / Project Guidance / External ADC on: March 27, 2012, 12:46:00 pm
Hello all!

Can anyone tell me that whether I can use the external fast adc with arduino nano board. The adc can be seen through tha link below. I saw that there are almost 16 pins are required to interface it with arduino and in our nano board we have only 14 digital pins so can we still interface it with arduino somehow, please let me know about it

http://uk.farnell.com/analog-devices/ad7822bnz/ic-8bit-adc-7822-dip20/dp/1079304
Pages: [1] 2 3 ... 5