NM500 TEST PGM

Dependencies:   NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed

Committer:
Nasungil
Date:
Thu May 18 06:06:13 2017 +0000
Revision:
9:7970a5638913
Parent:
8:c41405662e53
Child:
10:74e762848659
save mode complete
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nasungil 8:c41405662e53 1 #include "mbed.h"
Nasungil 8:c41405662e53 2 #include "NM500.h"
Nasungil 8:c41405662e53 3
Nasungil 8:c41405662e53 4 int data_learn(void);
Nasungil 8:c41405662e53 5
Nasungil 8:c41405662e53 6 unsigned char vector[NEURONSIZE];
Nasungil 8:c41405662e53 7
Nasungil 8:c41405662e53 8 int main() {
Nasungil 8:c41405662e53 9 int minif,maxif=0,gcr,learn=0,classify=0;
Nasungil 8:c41405662e53 10
Nasungil 8:c41405662e53 11 //NM500 & SD Card Init
Nasungil 8:c41405662e53 12 if(begin() == 0)
Nasungil 8:c41405662e53 13 printf("\nNM500 Init\n");
Nasungil 8:c41405662e53 14 else
Nasungil 8:c41405662e53 15 error("Init error");
Nasungil 8:c41405662e53 16
Nasungil 8:c41405662e53 17 //kNN Mode 설정
Nasungil 9:7970a5638913 18 //setKNN();
Nasungil 8:c41405662e53 19
Nasungil 8:c41405662e53 20 //minif test
Nasungil 9:7970a5638913 21 write(NM_MINIF,3);
Nasungil 8:c41405662e53 22 minif = read(NM_MINIF);
Nasungil 8:c41405662e53 23
Nasungil 8:c41405662e53 24 //maxif test
Nasungil 9:7970a5638913 25 write(NM_MAXIF,10000);
Nasungil 8:c41405662e53 26 maxif = read(NM_MAXIF);
Nasungil 8:c41405662e53 27
Nasungil 8:c41405662e53 28 //GCR test
Nasungil 9:7970a5638913 29 write(NM_GCR,5);
Nasungil 8:c41405662e53 30 gcr = read(NM_GCR);
Nasungil 9:7970a5638913 31
Nasungil 8:c41405662e53 32 //Neuron learn
Nasungil 8:c41405662e53 33 data_learn();
Nasungil 8:c41405662e53 34
Nasungil 9:7970a5638913 35 //data save
Nasungil 9:7970a5638913 36 int save = NeuronToSD();
Nasungil 9:7970a5638913 37
Nasungil 9:7970a5638913 38 forget();
Nasungil 9:7970a5638913 39 int forget = NCOUNT();
Nasungil 9:7970a5638913 40 printf("forget : %d", forget);
Nasungil 9:7970a5638913 41
Nasungil 8:c41405662e53 42 SDToNeurons();
Nasungil 8:c41405662e53 43
Nasungil 9:7970a5638913 44 printf("\nMINIF : %d\n", minif);
Nasungil 9:7970a5638913 45 printf("\nMAXIF : %d\n", maxif);
Nasungil 9:7970a5638913 46 printf("\nGCR : %d\n", gcr);
Nasungil 9:7970a5638913 47 printf("\nSAVE : %d\n", save);
Nasungil 9:7970a5638913 48 printf("\nFORGET : %d\n", forget);//
Nasungil 9:7970a5638913 49 // printf("\nMinif : %d\n", minif);
Nasungil 9:7970a5638913 50 // printf("\nMinif : %d\n", minif);
Nasungil 9:7970a5638913 51 // printf("\nMinif : %d\n", minif);
Nasungil 8:c41405662e53 52
Nasungil 8:c41405662e53 53
Nasungil 8:c41405662e53 54 }
Nasungil 8:c41405662e53 55 int data_learn(void)
Nasungil 8:c41405662e53 56 {
Nasungil 8:c41405662e53 57 int ncnt=0,old_ncnt=0; //ncount, old ncount
Nasungil 8:c41405662e53 58
Nasungil 8:c41405662e53 59 //number of neuron 576*2
Nasungil 8:c41405662e53 60 for(int i=1;i<=MAXNEURONS;i++){
Nasungil 8:c41405662e53 61 // ex
Nasungil 8:c41405662e53 62 // 1. 0 1 0 1....
Nasungil 8:c41405662e53 63 // 2. 0 2 0 2....
Nasungil 8:c41405662e53 64 // 3. 0 3 0 3....
Nasungil 8:c41405662e53 65 // .....
Nasungil 8:c41405662e53 66 // 255. 0 255 0 255....
Nasungil 8:c41405662e53 67 // 256. 1 0 1 0....
Nasungil 8:c41405662e53 68 // 257. 1 1 1 1....
Nasungil 8:c41405662e53 69 for(int j =0;j<NEURONSIZE;j=j+2){
Nasungil 8:c41405662e53 70 vector[j] = i>>8; //upper bit save
Nasungil 8:c41405662e53 71 vector[j+1] = i; //low bit save
Nasungil 8:c41405662e53 72 }
Nasungil 8:c41405662e53 73 //data learn
Nasungil 8:c41405662e53 74 ncnt = learn(vector, NEURONSIZE, i); //input : data, neuronsize, cat, return : ncount
Nasungil 8:c41405662e53 75 printf("ncount # %d\n",ncnt);
Nasungil 8:c41405662e53 76
Nasungil 8:c41405662e53 77 if(ncnt == old_ncnt) //ncount가 변화가 없으면
Nasungil 8:c41405662e53 78 return 0; //학습 실패 or ncount 레지스터 불량
Nasungil 8:c41405662e53 79 else //ncount가 증가하였을 경우
Nasungil 8:c41405662e53 80 old_ncnt = ncnt; //old ncount 갱신
Nasungil 8:c41405662e53 81
Nasungil 8:c41405662e53 82
Nasungil 8:c41405662e53 83 //test display
Nasungil 8:c41405662e53 84 printf("vector : ");
Nasungil 8:c41405662e53 85 for(int j=0;j<NEURONSIZE;j++)
Nasungil 8:c41405662e53 86 printf(" %d,",vector[j]);
Nasungil 8:c41405662e53 87 printf(" cat : %d\n", i);
Nasungil 8:c41405662e53 88 }
Nasungil 8:c41405662e53 89 //학습 완료 후 ncount가 MAXNEURONS보다 작을 경우
Nasungil 8:c41405662e53 90 if(ncnt < MAXNEURONS)
Nasungil 8:c41405662e53 91 return 2; //데이지체인 불량
Nasungil 8:c41405662e53 92 return ncnt; //정상 출력
Nasungil 8:c41405662e53 93 }
Nasungil 8:c41405662e53 94
Nasungil 8:c41405662e53 95
Nasungil 9:7970a5638913 96