Commit a85cf4ad authored by James Pallister's avatar James Pallister

Added number of runs measurement, and a measurement completed function

parent b8239f96
......@@ -118,7 +118,7 @@ int tperiod=500;
// Power data temporary storage /////////////////////////////////////
#define NUM_BUFFERS 64
#define NUM_BUFFERS 256
#define DMA_SHORTS 128
typedef struct {
......@@ -129,6 +129,7 @@ typedef struct {
power_data data_bufs[NUM_BUFFERS] = {0};
int running = 0; // Are we collecting measurements
int number_of_runs = 0;
// Implement a circular buffer in data_bufs
int head_ptr = 0, tail_ptr = 0;
......@@ -216,6 +217,7 @@ void start_measurement()
void stop_measurement()
{
running = 0;
number_of_runs++;
timer_disable_counter(TIM2);
gpio_clear(GPIOD, GPIO12);
}
......@@ -314,6 +316,17 @@ static int usbdev_control_request(usbd_device *usbd_dev, struct usb_setup_data *
*buf = &running;
break;
}
case 9: // Get number of runs
{
*len = sizeof(number_of_runs);
*buf = &number_of_runs;
break;
}
case 10: // Clear number of runs
{
number_of_runs = 0;
break;
}
default:
return 0;
}
......@@ -550,7 +563,9 @@ int main(void)
send_int = 0;
}
if(head_ptr != tail_ptr)
// If we receive lots of USB commands, we might not process our
// buffers fast enough, so lets do up to 16
for(n = 0; n < 16 && head_ptr != tail_ptr; ++n)
{
process_buffer(&data_bufs[head_ptr]);
......
......@@ -8,6 +8,8 @@ from collections import namedtuple
from logging import warning, error
# import multiprocessing
class Measurement(object):
def __init__(self):
pass
......@@ -55,19 +57,45 @@ class EnergyMonitor(object):
# Start measuring on m_point
def start(self, m_point=1):
self.clearNumberOfRuns()
self.dev.ctrl_transfer(0x41, 1, int(m_point), 0, None)
# Stop measuring on m_point
def stop(self, m_point=1):
self.dev.ctrl_transfer(0x41, 2, int(m_point), 0, None)
# Return whether the measurement point is currently taking
# measurements or not
def isRunning(self, m_point=1):
b = self.dev.ctrl_transfer(0xc1, 8, int(m_point), 0, 4)
running = unpack("=L", b)
return bool(running)
# Trigger
return bool(running[0])
# This counts the number of end measurement signals caught
# by the energy monitor.
def getNumberOfRuns(self, m_point=1):
b = self.dev.ctrl_transfer(0xc1, 9, int(m_point), 0, 4)
runs = unpack("=L", b)
return bool(runs[0])
# Reset the number of runs counts to 0
def clearNumberOfRuns(self, m_point=1):
self.dev.ctrl_transfer(0x41, 10, int(m_point), 0, None)
# Have we completed a measurement?
def measurementCompleted(self, m_point = 1):
runs = self.getNumberOfRuns()
if runs > 1:
warning("More than one measurement has completed (expected one)")
if not self.isRunning(m_point) and runs > 0:
self.clearNumberOfRuns()
return True
return False
# Set a particular port as a pin trigger for a measurement point
# e.g PA0
def setTrigger(self, port, m_point=1):
# TODO check port is of the form PA0
......@@ -145,18 +173,13 @@ if __name__ == "__main__":
em.toggleLEDs()
em.measurement_params[1]['resistor'] = 1
# em.enableMeasurementPoint(1)
em.start()
sleep(1)
em.stop()
sleep(0.1)
em.getMeasurement()
sleep(1)
em.setTrigger("PA0")
print "*** Press the blue button to make a measurement"
while True:
print em.isRunning()
while not em.measurementCompleted():
sleep(0.1)
em.getMeasurement()
sleep(0.1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment