Difference between revisions of "Lesson 8--Microduino "Pulse Recorder""

From Microduino Wiki
Jump to: navigation, search
m (photo added)
m (photo added)
Line 79: Line 79:
 
For stabilization,add a 104 ceramic capacitors in signal change port, you can see a better result.
 
For stabilization,add a 104 ceramic capacitors in signal change port, you can see a better result.
 
[[File:lesson8-capacitance.jpg|600px|center|thumb]]
 
[[File:lesson8-capacitance.jpg|600px|center|thumb]]
 +
[[File:lesson8Result.jpg|600px|center|thumb]]
 +
 
==Video==
 
==Video==
 
|}
 
|}

Revision as of 06:32, 3 July 2015

Language: English  • 中文

Objective

The lesson shows us how to use the button and aviod shaking issue. The solution is to delay time. But this solution has a disadvantage. As to the delay time, it all depends since it takes different time for everyone to press the button. This lesson will introduce how to get the time to press a button, the program uses pulse timing calculation. Besides that, you can learn how to use arduino's serial and monitor the data using serial.

Equipment

Lesson8All.jpg

Pulse

Pulse is a process that a physical quantity quickly retun to its initial state after a short time mutation. In Microduino, pulse just a digital signal which changed between high and low in cyclical. Pulse timing is often used in the photoelectric encoder, Hall elements to calculate the speed.

Experimental schematic

Lesson8-schematic.jpg

Using the internal pull-up, external 104 ceramic capacitors for stabilization.

Program

int pin = 2;  //Define Pin D2
float time1,time2;  //Define variables to float
 
void setup()
{
  Serial.begin(115200);  //Serial port baud rate
  pinMode(pin,  INPUT_PULLUP); //Set pin to input mode with the internal pull-up
}
 
void loop()
{
    //Read low pulse from the pin, the maximum pulse interval is 60 seconds, and assign the result to the variable time1
  time1= pulseIn(pin, LOW,60000000)/1000;//Convert the time to ms
  Serial.print(time1); //Output the time1 by serial
  Serial.print("ms  ");
  time2= pulseIn(pin, LOW,60000000)/1000.0;//Convert the time to ms
  Serial.print(time2); //Output the time1 by serial
  Serial.println("ms");//Through the serial port to print out the unit and wrap to a new line to output the next value.
}

Serial monitoring

Open the serial port monitor

  • Click the Serial Monitor button, pop-up the serial monitor interface.
Lesson8-serialmonitor.jpg
Lesson8-serialwindow.jpg
  • Note:
    • In order to using serial, you need add sentence "Serial.begin(xxxx)" in function setup(),xxxx is the baud rate;
    • The baud rate should be same when using the serial monitor. The baud rate is a measure of the signal transmission rate. The baud rate is not a good match, it is easy garbled.
  • When convert the unit, need pat attention to the data type:
Lesson-calculate.jpg

PulseIn()function

  • Function:read a pulse(HIGH or LOW) from a pin. Such as, if the value is HIGHT, pulseIn() will start timer when pin is HIGH, then stop the timer after pin change to LOW.

The return value is the pulse time, unit is us. The timer range is 10us ~ 3mins. (1s=1000ms=1000000us)

  • Grammar:
    • pulseIn(pin, value)
    • pulseIn(pin, value, timeout)
  • Parameters:
    • pin: pulse timing I/O port(int)
    • value:pulse type,HIGH or LOW(int)
    • timeout (optional):Wait timer for pulse timing,unit is us, the default value is 1s.(unsigned long)

Result

For stabilization,add a 104 ceramic capacitors in signal change port, you can see a better result.

Lesson8-capacitance.jpg
Lesson8Result.jpg

Video


https://www.youtube.com/watch?v=Ge52Sx_8XeU