Class library for internal ADC and DAC connected by SPI. ADC is triggered by TIM2. This library support clock generator using TIM3 for switched-capacitor filter to smooth output signal of DAC. This library includes derivative class to support interrupt occured in end of AD conversion. Slave select of SPI for DAC is generated using TIM4. Validated for ST Nucleo F401RE, F411RE. New version. 内蔵 ADC と,SPI 接続の DAC のためのクラスライブラリ.ADC の変換開始トリガは TIM2 で発生.DAC の出力信号を平滑化するためのスイッチトキャパシタフィルタ用のクロックは TIM3 を使用.DAC の SPI 用スレーブ選択信号は TIM4 で発生.ST Nucleo F401RE,F411RE で動作を確認.新バージョン

Dependents:   UIT2_MovingAverage UIT2_AllpassReverb UIT2_CombReverb UIT2_FIR_LPF_Symmetry ... more

ADC_Interrupt.hpp

Committer:
MikamiUitOpen
Date:
2015-01-11
Revision:
16:0001d3e93bee
Parent:
0:6e0ed5adfe47

File content as of revision 16:0001d3e93bee:

//------------------------------------------------------
// Derived class of ADC_Base for use interrupt
//
// 2014/10/04, Copyright (c) 2014 MIKAMI, Naoki
//------------------------------------------------------

#ifndef ADC_INTERRUPT_HPP
#define ADC_INTERRUPT_HPP

#include "ADC_Base.hpp"

namespace Mikami
{
    class ADC_Intr : public ADC_Base
    {
    private:       
        // for inhibition of copy constructor
        ADC_Intr(const ADC_Intr&);
        // for inhibition of substitute operator
        ADC_Intr& operator=(const ADC_Intr&);

    public:
        ADC_Intr(PinName pin1, int frequency,
                 PinName pin2 = NC, PinName pin3 = NC)
            : ADC_Base(pin1, frequency, pin2, pin3)
        { myAdc_->CR1 |= ADC_CR1_EOCIE; }   // Interrupt enable

        // Set interrupt vector and enable IRQ of ADC
        void SetIntrVec(void (*Func)())
        {
            NVIC_SetVector(ADC_IRQn, (uint32_t)Func);   // See "cmsis_nvic.h"
            NVIC_EnableIRQ(ADC_IRQn);                   // See "core_cm4.h"
        }       

        // Read ADC, range: [0, 0x0FFF]
        virtual uint16_t Read_u16()
        { return myAdc_->DR; }

        // Read ADC, range: [0, 0x0FFF]
        virtual uint16_t ReadWait_u16()
        {
            WaitDone();
            return myAdc_->DR;
        }

        // Read ADC, range: [-1.0f, 1.0f]
        virtual float Read()
        { return AMP_*((int16_t)myAdc_->DR - 2048); }
        
        // Clear pending IRQ and enable IRQ
        void ClearPending_EnableIRQ()
        {
            NVIC_ClearPendingIRQ(ADC_IRQn);
            NVIC_EnableIRQ(ADC_IRQn);
        }

        // Software start with disable IRQ
        virtual void SoftStart()
        {
            NVIC_DisableIRQ(ADC_IRQn);
            myAdc_->CR2 |= ADC_CR2_SWSTART;
        }        
    };
}
#endif  // ADC_INTERRUPT_HPP