Added comments and changed labels of plot.
This commit is contained in:
parent
2686fb6938
commit
7d88e8635d
|
@ -1,11 +1,11 @@
|
||||||
#include "msp430.h"
|
#include "msp430.h"
|
||||||
|
|
||||||
#define TRIG BIT4
|
|
||||||
#define ECHO BIT5
|
|
||||||
|
|
||||||
#define TXD BIT2
|
#define TXD BIT2
|
||||||
#define RXD BIT1
|
#define RXD BIT1
|
||||||
|
|
||||||
|
#define TRIG BIT4
|
||||||
|
#define ECHO BIT5
|
||||||
|
|
||||||
#define SOUND 34029 // speed of sound in cm/s
|
#define SOUND 34029 // speed of sound in cm/s
|
||||||
#define US 1000000 // microseconds in a second
|
#define US 1000000 // microseconds in a second
|
||||||
|
|
||||||
|
@ -33,23 +33,23 @@ void main(void) {
|
||||||
P1DIR &= ~ECHO;
|
P1DIR &= ~ECHO;
|
||||||
P1IE |= ECHO;
|
P1IE |= ECHO;
|
||||||
|
|
||||||
TACTL = TASSEL_2 | ID_0 | MC_2; // set timer to count up
|
TACTL = TASSEL_2 | MC_2; // set SMCLK timer to count up
|
||||||
__enable_interrupt();
|
__enable_interrupt();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
P1OUT |= TRIG; // start trigger signal
|
P1OUT |= TRIG; // start trigger signal
|
||||||
__delay_cycles(15); // we need a >10 us pulse but one clock cycle is 1 us
|
__delay_cycles(15); // we need a >10 us pulse and one clock cycle is 1 us
|
||||||
P1OUT &= ~TRIG; // end trigger signal
|
P1OUT &= ~TRIG; // end trigger signal
|
||||||
|
|
||||||
P1IES &= ~ECHO;
|
P1IES &= ~ECHO; // interrupt on low to high
|
||||||
__bis_SR_register(LPM0_bits + GIE);
|
__bis_SR_register(LPM0_bits + GIE);
|
||||||
TAR = 0;
|
TAR = 0;
|
||||||
P1IES |= ECHO;
|
P1IES |= ECHO; // interrupt on high to low
|
||||||
__bis_SR_register(LPM0_bits + GIE);
|
__bis_SR_register(LPM0_bits + GIE);
|
||||||
|
|
||||||
TXByte = TAR; // time elapsed in us (approx)
|
TXByte = TAR; // time elapsed in us (no risk of overflow since echo will lower at 36000 us regardless)
|
||||||
while (!(IFG2 & UCA0TXIFG)); // wait for TX buffer to be ready for new data
|
while (!(IFG2 & UCA0TXIFG)); // wait for TX buffer to be ready for new data
|
||||||
UCA0TXBUF = TXByte * SOUND / US / 2; // curiously, this is a factor of 2 off
|
UCA0TXBUF = TXByte * SOUND / US / 2; // distance in cm (curiously, this is a factor of 2 off)
|
||||||
|
|
||||||
__delay_cycles(100000); // wait 100 ms before measuring again
|
__delay_cycles(100000); // wait 100 ms before measuring again
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ times=np.arange(0,50,1.0) # 50 from 0 to 49.
|
||||||
|
|
||||||
#create a plot:
|
#create a plot:
|
||||||
fig = Figure()
|
fig = Figure()
|
||||||
ax = fig.add_subplot(111,xlabel='Time Step',ylabel='Temp (deg F)')
|
ax = fig.add_subplot(111,xlabel='Time Step',ylabel='Distance (cm)')
|
||||||
ax.set_ylim(0,255) # set limits of y axis.
|
ax.set_ylim(0,255) # set limits of y axis.
|
||||||
|
|
||||||
canvas = FigureCanvas(fig) #put the plot onto a canvas
|
canvas = FigureCanvas(fig) #put the plot onto a canvas
|
||||||
|
@ -72,7 +72,7 @@ win.set_title("ready to receive data");
|
||||||
|
|
||||||
line, = ax.plot(times,yvals)
|
line, = ax.plot(times,yvals)
|
||||||
#open a data file for the output
|
#open a data file for the output
|
||||||
outFile = open("time_and_temp.txt","w")
|
outFile = open("time_and_dist.txt","w")
|
||||||
start_time = time()
|
start_time = time()
|
||||||
ser.flushInput()
|
ser.flushInput()
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ while(1): #loop forever
|
||||||
outFile.write(str(time()-start_time)+" "+str(yvals[49])+"\n") #write to file
|
outFile.write(str(time()-start_time)+" "+str(yvals[49])+"\n") #write to file
|
||||||
line.set_ydata(yvals) # draw the line
|
line.set_ydata(yvals) # draw the line
|
||||||
fig.canvas.draw() # update the canvas
|
fig.canvas.draw() # update the canvas
|
||||||
win.set_title("Temp: "+str(yvals[49])+" deg F")
|
win.set_title("Distance: "+str(yvals[49])+" cm")
|
||||||
while gtk.events_pending(): #makes sure the GUI updates
|
while gtk.events_pending(): #makes sure the GUI updates
|
||||||
gtk.main_iteration()
|
gtk.main_iteration()
|
||||||
# sleep(.05) # don't eat the cpu. This delay limits the data rate to ~ 200 samples/s
|
# sleep(.05) # don't eat the cpu. This delay limits the data rate to ~ 200 samples/s
|
||||||
|
|
Loading…
Reference in New Issue