Commit 357e8089 by zacharyc

Introduced usage of full 20 bits of PWM period counter


git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@7286 ddd99763-3ecb-0310-9145-efcb8ce7c51f
parent 0ed2935d
Showing with 20 additions and 12 deletions
...@@ -65,7 +65,7 @@ struct options opt[] = { ...@@ -65,7 +65,7 @@ struct options opt[] = {
int doStream(const char *address, uint8_t scanconfig, uint16_t scaninterval, int doStream(const char *address, uint8_t scanconfig, uint16_t scaninterval,
int *channel_list, int channel_count, int convert, int maxlines); int *channel_list, int channel_count, int convert, int maxlines);
int nerdDoStream(const char *address, int *channel_list, int channel_count, int precision, int nerdDoStream(const char *address, int *channel_list, int channel_count, int precision,
unsigned short period, int convert, int lines, int showmem); unsigned long period, int convert, int lines, int showmem);
int data_callback(int channels, uint16_t *data, void *context); int data_callback(int channels, uint16_t *data, void *context);
int columns_left = 0; int columns_left = 0;
...@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) ...@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
int nerdjack = 0; int nerdjack = 0;
int detect = 0; int detect = 0;
int precision = 0; int precision = 0;
int period = NERDJACK_CLOCK_RATE / desired_rate; unsigned long period = NERDJACK_CLOCK_RATE / desired_rate;
/* Parse arguments */ /* Parse arguments */
opt_init(&optind); opt_init(&optind);
...@@ -277,20 +277,23 @@ int main(int argc, char *argv[]) ...@@ -277,20 +277,23 @@ int main(int argc, char *argv[])
if (nerdjack_choose_scan(desired_rate, &actual_rate, &period) < 0) { if (nerdjack_choose_scan(desired_rate, &actual_rate, &period) < 0) {
info("error: can't achieve requested scan rate (%lf Hz)\n", info("error: can't achieve requested scan rate (%lf Hz)\n",
desired_rate); desired_rate);
return 1; //return 1;
} }
} else { } else {
if (ue9_choose_scan(desired_rate, &actual_rate, if (ue9_choose_scan(desired_rate, &actual_rate,
&scanconfig, &scaninterval) < 0) { &scanconfig, &scaninterval) < 0) {
info("error: can't achieve requested scan rate (%lf Hz)\n", info("error: can't achieve requested scan rate (%lf Hz)\n",
desired_rate); desired_rate);
return 1; //return 1;
} }
} }
if ((desired_rate != actual_rate) || verb_count) if ((desired_rate != actual_rate) || verb_count){
info("Actual scanrate is %lf Hz\n", actual_rate); info("Actual scanrate is %lf Hz\n", actual_rate);
info("Period is %ld\n",period);
}
if (verb_count && lines) { if (verb_count && lines) {
info("Stopping capture after %d lines\n", lines); info("Stopping capture after %d lines\n", lines);
...@@ -354,7 +357,7 @@ int main(int argc, char *argv[]) ...@@ -354,7 +357,7 @@ int main(int argc, char *argv[])
} }
int nerdDoStream(const char *address, int *channel_list, int channel_count, int precision, int nerdDoStream(const char *address, int *channel_list, int channel_count, int precision,
unsigned short period, int convert, int lines, int showmem) unsigned long period, int convert, int lines, int showmem)
{ {
int retval = -EAGAIN; int retval = -EAGAIN;
int fd_data; int fd_data;
......
...@@ -45,16 +45,21 @@ typedef struct __attribute__((__packed__)) { ...@@ -45,16 +45,21 @@ typedef struct __attribute__((__packed__)) {
/* Choose the best ScanConfig and ScanInterval parameters for the /* Choose the best ScanConfig and ScanInterval parameters for the
desired scanrate. Returns -1 if no valid config found */ desired scanrate. Returns -1 if no valid config found */
int nerdjack_choose_scan(double desired_rate, double *actual_rate, int *period) int nerdjack_choose_scan(double desired_rate, double *actual_rate, unsigned long *period)
{ {
//The +1 corrects a silicon bug. The timer resets to 1, not 0.
*period = floor((double) NERDJACK_CLOCK_RATE / desired_rate); *period = floor((double) NERDJACK_CLOCK_RATE / desired_rate) + 1;
if(*period > UINT16_MAX) { if(*period > 0x0fffff) {
info("Cannot sample that slowly\n"); info("Cannot sample that slowly\n");
*actual_rate = (double)NERDJACK_CLOCK_RATE / (double) 0x0ffffe;
//info("Sampling at slowest rate:%f\n",*actual_rate);
return -1; return -1;
} }
*actual_rate = (double) NERDJACK_CLOCK_RATE / (double) *period; //Period holds the period register for the NerdJack, so it needs to be right
*actual_rate = (double) NERDJACK_CLOCK_RATE / (double) (*period - 1);
if(*actual_rate != desired_rate) { if(*actual_rate != desired_rate) {
//info("Sampling at nearest rate:%f\n",*actual_rate);
return -1; return -1;
} }
return 0; return 0;
......
...@@ -51,6 +51,6 @@ int nerdjack_detect(char * ipAddress); ...@@ -51,6 +51,6 @@ int nerdjack_detect(char * ipAddress);
/* Choose the best ScanConfig and ScanInterval parameters for the /* Choose the best ScanConfig and ScanInterval parameters for the
desired scanrate. Returns -1 if no valid config found */ desired scanrate. Returns -1 if no valid config found */
int nerdjack_choose_scan(double desired_rate, double *actual_rate, int *period); int nerdjack_choose_scan(double desired_rate, double *actual_rate, unsigned long *period);
#endif #endif
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 sign in to comment