Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed NeuroShield
Diff: main.cpp
- Revision:
- 1:2d0abf41b7a3
- Parent:
- 0:c56eb46c7bee
- Child:
- 2:995d7426e3ba
--- a/main.cpp Thu Aug 17 23:35:06 2017 +0000
+++ b/main.cpp Thu Jan 25 02:37:42 2018 +0000
@@ -1,8 +1,10 @@
/******************************************************************************
- * NM500 NeuroSheild Board SimpleScript
+ * NM500 NeuroShield Board SimpleScript
* Simple Test Script to understand how the neurons learn and recognize
- * revision 1.0, 8/18, 2017
+ * revision 1.1.3, 01/03, 2018
* Copyright (c) 2017 nepes inc.
+ *
+ * Please use the NeuroShield library v1.1.3 or later
******************************************************************************/
#include "mbed.h"
@@ -22,15 +24,26 @@
int i, j;
uint8_t value;
uint8_t vector[NEURON_SIZE];
+ uint16_t vector16[NEURON_SIZE];
uint16_t ncr, cat, aif, ncount, minif, response_nbr, norm_lsup = 0;
uint16_t dists[READ_COUNT], cats[READ_COUNT], nids[READ_COUNT];
+ uint16_t fpga_version;
- printf("\n#### NM500 NeuroShield Board ####\n");
arduino_con = LOW;
sdcard_ss = HIGH;
wait(0.5);
if (hnn.begin() != 0) {
+ fpga_version = hnn.fpgaVersion();
+ if ((fpga_version & 0xFF00) == 0x0000) {
+ printf("\n\n#### NeuroShield Board (Board v%d.0 / FPGA v%d.0) ####\n", ((fpga_version >> 4) & 0x000F), (fpga_version & 0x000F));
+ }
+ else if ((fpga_version & 0xFF00) == 0x0100) {
+ printf("\n\n#### Prodigy Board (Board v%d.0 / FPGA v%d.0) ####\n", ((fpga_version >> 4) & 0x000F), (fpga_version & 0x000F));
+ }
+ else {
+ printf("\n\n#### Unknown Board (Board v%d.0 / FPGA v%d.0) ####\n", ((fpga_version >> 4) & 0x000F), (fpga_version & 0x000F));
+ }
printf("\nNM500 is initialized!\n");
printf("There are %d neurons\n", hnn.total_neurons);
}
@@ -59,11 +72,11 @@
ncount = hnn.learn(vector, VECTOR_LENGTH, 100);
// display the content of the committed neurons
printf("\nDisplay the neurons, count = %d", ncount);
- for (i = 0; i < ncount; i++) {
- hnn.readNeuron(i, vector, &ncr, &aif, &cat);
- printf("\nneuron#%d \tmodel=", (i + 1));
+ for (i = 1; i <= ncount; i++) {
+ hnn.readNeuron(i, vector16, &ncr, &aif, &cat);
+ printf("\nneuron#%d \tmodel=", i);
for (j = 0; j < VECTOR_LENGTH; j++)
- printf("%d, ", vector[j]);
+ printf("%d, ", vector16[j]);
if (cat & 0x8000)
printf("\tncr=%d \taif=%d \tcat=%d (degenerated)", ncr, aif, (cat & 0x7FFF));
else
@@ -106,11 +119,11 @@
ncount = hnn.learn(vector, VECTOR_LENGTH, 100);
// display the content of the committed neurons
printf("\nDisplay the neurons, count = %d", ncount);
- for (i = 0; i < ncount; i++) {
- hnn.readNeuron(i, vector, &ncr, &aif, &cat);
- printf("\nneuron#%d \tmodel=", (i + 1));
+ for (i = 1; i <= ncount; i++) {
+ hnn.readNeuron(i, vector16, &ncr, &aif, &cat);
+ printf("\nneuron#%d \tmodel=", i);
for (j = 0; j < VECTOR_LENGTH; j++)
- printf("%d, ", vector[j]);
+ printf("%d, ", vector16[j]);
if (cat & 0x8000)
printf("\tncr=%d \taif=%d \tcat=%d (degenerated)", ncr, aif, (cat & 0x7FFF));
else
@@ -124,11 +137,11 @@
ncount = hnn.learn(vector, VECTOR_LENGTH, 77);
// display the content of the committed neurons
printf("\nDisplay the neurons, count = %d", ncount);
- for (i = 0; i < ncount; i++) {
- hnn.readNeuron(i, vector, &ncr, &aif, &cat);
- printf("\nneuron#%d \tmodel=", (i + 1));
+ for (i = 1; i <= ncount; i++) {
+ hnn.readNeuron(i, vector16, &ncr, &aif, &cat);
+ printf("\nneuron#%d \tmodel=", i);
for (j = 0; j < VECTOR_LENGTH; j++)
- printf("%d, ", vector[j]);
+ printf("%d, ", vector16[j]);
if (cat & 0x8000)
printf("\tncr=%d \taif=%d \tcat=%d (degenerated)", ncr, aif, (cat & 0x7FFF));
else
@@ -144,11 +157,11 @@
hnn.setContext(1);
// display the content of the committed neurons
printf("\nDisplay the neurons, count = %d", ncount);
- for (i = 0; i < ncount; i++) {
- hnn.readNeuron(i, vector, &ncr, &aif, &cat);
- printf("\nneuron#%d \tmodel=", (i + 1));
+ for (i = 1; i <= ncount; i++) {
+ hnn.readNeuron(i, vector16, &ncr, &aif, &cat);
+ printf("\nneuron#%d \tmodel=", i);
for (j = 0; j < VECTOR_LENGTH; j++)
- printf("%d, ", vector[j]);
+ printf("%d, ", vector16[j]);
if (cat & 0x8000)
printf("\tncr=%d \taif=%d \tcat=%d (degenerated)", ncr, aif, (cat & 0x7FFF));
else