NM500 TEST PGM

Dependencies:   NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed

main.cpp

Committer:
Nasungil
Date:
2017-05-18
Revision:
9:7970a5638913
Parent:
8:c41405662e53
Child:
10:74e762848659

File content as of revision 9:7970a5638913:

#include "mbed.h"
#include "NM500.h"

int data_learn(void);

unsigned char vector[NEURONSIZE];

int main() {
    int minif,maxif=0,gcr,learn=0,classify=0;

    //NM500 & SD Card Init
    if(begin() == 0)
        printf("\nNM500 Init\n");
    else
        error("Init error");
        
    //kNN Mode 설정   
    //setKNN();          

    //minif test
    write(NM_MINIF,3);     
    minif = read(NM_MINIF);
    
    //maxif test
    write(NM_MAXIF,10000);  
    maxif = read(NM_MAXIF);
    
    //GCR test
    write(NM_GCR,5);
    gcr = read(NM_GCR);
               
    //Neuron learn
    data_learn();
    
    //data save
    int save = NeuronToSD();
    
    forget();
    int forget = NCOUNT();
    printf("forget : %d", forget);
    
    SDToNeurons();
       
    printf("\nMINIF  : %d\n", minif);
    printf("\nMAXIF  : %d\n", maxif);
    printf("\nGCR    : %d\n", gcr);
    printf("\nSAVE   : %d\n", save);
    printf("\nFORGET : %d\n", forget);//
//    printf("\nMinif  : %d\n", minif);
//    printf("\nMinif  : %d\n", minif);
//    printf("\nMinif  : %d\n", minif);                
        
        
}
int data_learn(void)
{
        int ncnt=0,old_ncnt=0;  //ncount, old ncount
        
        //number of neuron 576*2
        for(int i=1;i<=MAXNEURONS;i++){ 
            // ex
            //      1.      0 1 0 1.... 
            //      2.      0 2 0 2.... 
            //      3.      0 3 0 3....
            //      .....
            //      255.    0 255 0 255....
            //      256.    1 0 1 0....
            //      257.    1 1 1 1....
            for(int j =0;j<NEURONSIZE;j=j+2){   
                vector[j] = i>>8;          //upper bit save
                vector[j+1] = i;           //low bit save
            }
            //data learn
            ncnt = learn(vector, NEURONSIZE, i);    //input : data, neuronsize, cat,   return : ncount
            printf("ncount # %d\n",ncnt);
            
            if(ncnt == old_ncnt)                    //ncount가 변화가 없으면       
                return 0;       //학습 실패 or ncount 레지스터 불량
            else                                    //ncount가 증가하였을 경우
                old_ncnt = ncnt;    //old ncount 갱신

            
            //test display
            printf("vector : ");
            for(int j=0;j<NEURONSIZE;j++)
                printf(" %d,",vector[j]);
            printf(" cat : %d\n", i);
        } 
        //학습 완료 후 ncount가 MAXNEURONS보다 작을 경우
        if(ncnt < MAXNEURONS)
            return 2;       //데이지체인 불량
        return ncnt;        //정상 출력
}