Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Impedance_Fast_Circuitry by
quadrature.cpp
- Committer:
- timmey9
- Date:
- 2015-01-31
- Revision:
- 45:d591d138cdeb
File content as of revision 45:d591d138cdeb:
#include "quadrature.h" void quad_init() { // Enable clock for FTM2 SIM_SCGC3 |= SIM_SCGC3_FTM2_MASK; // there are two of them for some reason SIM_SCGC6 |= SIM_SCGC6_FTM2_MASK; // // Enable clock for PortB SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK; //enable the counter FTM2_MODE |= FTM_MODE_WPDIS_MASK; // unlock write protection on certain FTM bits and registers FTM2_MODE |= FTM_MODE_FTMEN_MASK; //enable the counter to run in the BDM mode FTM2_CONF |= FTM_CONF_BDMMODE(3); //load the Modulo register and counter initial value FTM2_MOD = 4095; FTM2_CNTIN = 0; //configuring FTM for quadrature mode FTM2_QDCTRL |= FTM_QDCTRL_QUADEN_MASK; // enable Quadrature decoding FTM2_QDCTRL &= ~FTM_QDCTRL_QUADMODE_MASK; // select phase A and phase B decoding mode (this is what the angle encoder uses) // start the timer clock, source is the external clock FTM2_SC |= FTM_SC_CLKS(3); //configuring the input pins: PORTB_PCR18 = PORT_PCR_MUX(6); // FTM2_QD_PHA (PTB18) ALT6 PORTB_PCR19 = PORT_PCR_MUX(6); // FTM2_QD_PHB (PTB19) ALT6 // Enable write protection FTM2_MODE |= FTM_MODE_WPDIS_MASK; // Lock write protection on certain FTM bits and registers } int32_t quad_read() { //int32_t* temp = (int32_t*)0x4003a004; return FTM2_CNT; // this is the register with the counter in it. }