チーム16A1
課題名
光の周波数解析
研究者名
加勢田浩之
岡田良輝
概要
点滅間隔の違う光の点滅を1つのPSoCでつくりだし、もう1つのPSoCの光センサーでそれを読み取る。
そのデータを離散フーリエ変換して周波数を分析する。
周波数の異なる点滅をさせるPSoCのソースコード
#include <device.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
void main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */ unsigned char i = 1; unsigned char j = 10; double k = 1/j; char str[20]; LCD_Char_1_Start(); LCD_Char_1_ClearDisplay(); LCD_Char_1_Position(0, 0); LCD_Char_1_PrintString("T = "); LCD_Char_1_PrintNumber(j); LCD_Char_1_PrintString(" ms"); LCD_Char_1_Position(1, 0); sprintf(str, "%lf Hz", &k); LCD_Char_1_PrintString(str); /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
for(;;) { /* Place your application code here. */ if(SW_Read()){ j = j + 30; k = 1/j; Pin_1_Write(i); CyDelay(j); i ^= 1; if(j >= 200){ j = 10; k = 1/j; Pin_1_Write(i); CyDelay(j); i ^= 1; } LCD_Char_1_ClearDisplay(); LCD_Char_1_Position(0, 0); LCD_Char_1_PrintString("T = "); LCD_Char_1_PrintNumber(j); LCD_Char_1_PrintString(" ms"); LCD_Char_1_Position(1, 0); sprintf(str, "%lf Hz", &k); LCD_Char_1_PrintString(str); } Pin_1_Write(i); CyDelay(j); i ^= 1; }
}
周波数の異なる点滅をさせるPSoCのソースコード解説
LEDが光るかどうかの論理値を遅延時間ごとに反転させることで点滅を実現している。
またスイッチを押すごとに遅延時間の値を変更することで点滅間隔の違う点滅ができるようにした。
光センサーで読み取り、離散フーリエ変換で分析するPSoCのソースコード
/* ========================================
* * Copyright YOUR COMPANY, THE YEAR * All Rights Reserved * UNPUBLISHED, LICENSED SOFTWARE. * * CONFIDENTIAL AND PROPRIETARY INFORMATION * WHICH IS THE PROPERTY OF your company. * * ========================================
/
#include <device.h>
#include<math.h>
#include "fft.h"
int16 adcResult=0;
void main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */ unsigned char j = 50; int i=0; ADC_DelSig_1_Start(); ADC_DelSig_1_StartConvert(); LCD_Char_1_Start(); /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */ for(;;) { /* Place your application code here. */ if(ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT)) { LCD_Char_1_Position(0, 6); LCD_Char_1_PrintString(" "); LCD_Char_1_Position(0, 6); adcResult = ADC_DelSig_1_GetResult16(); data_re[i] = adcResult; LCD_Char_1_PrintNumber((uint16)adcResult); CyDelay(j); } i++; if(i == 64) break; } /* double data[N_points] = {100,100,100,0,0,0,0,100,100,100,0,0,0,0, 100,100,100,0,0,0,0,100,100,100,0,0,0,0, 100,100,100,0,0,0,0,100,100,100,0,0,0,0, 100,100,100,0,0,0,0,100,100,100,0,0,0,0}; */ FFT(1,exponent,data_re,data_re); //for(;;){ for(i=0;i<16;i++){ //D1=156 LCD_Char_1_DrawVerticalBG(1, i%16,8, mod[i]*10000); //LCD_Char_1_PrintNumber((uint16)mod[i]); } // }
}
/* [] END OF FILE */
考察
光センサーの抵抗の値をAD変換し,フーリエ変換することで光の周波数成分を求めた.
また,2つのPSOCを使い,一つは,AD変換するもの,もう一つはLEDの点滅を特定の周波数で起こすものを作成した.
基底周波数はサンプリング周波数/ポイント数であるから,約156Hzとなる.
今回,最も早い点滅は100Hzだったため,100Hzの点滅で実験を行ったが,
なかなか毎回同じような結果が出ることはなかった.
これは光センサーへの光の当たり方が毎回安定してなかったためと考える.
- 最終更新:2016-05-09 16:52:18