NM500 TEST PGM

Dependencies:   NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed

main.cpp

Committer:
Nasungil
Date:
2017-05-18
Revision:
8:c41405662e53
Parent:
7:daaefdca1f78
Child:
9:7970a5638913

File content as of revision 8:c41405662e53:

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

#define SD_CS      D6    
#define SD_MOSI    D11    
#define SD_MISO    D12    
#define SD_SCK     D13   

#define MAX_SIZE 100


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);
    printf("Minif : %d\n", 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();
    
    NeuronToSD();
    SDToNeurons();
       

        
        
        
}
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;        //정상 출력
}