Programa para la realizacion del graficador de bode para PPs 2018 por OTERO y OSSO
Dependencies: mbed GraficadorDeBode ST7920 AD9833 Tipografia5x3 ST7920Libreries
Revision 0:27ce42c61d3a, committed 2018-12-06
- Comitter:
- JAgustinOtero
- Date:
- Thu Dec 06 00:11:53 2018 +0000
- Commit message:
- Programa para la realizacion del graficador de bode para PPs 2018 por OTERO y OSSO
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AD9833.lib Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/JAgustinOtero/code/AD9833/#1bc0260fa422
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GraficadorDeBode.lib Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/JAgustinOtero/code/GraficadorDeBode/#1f97d368029f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST7920.lib Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/JAgustinOtero/code/ST7920/#c7d041bdb718
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST7920Libreries.lib Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/JAgustinOtero/code/ST7920Libreries/#57ab35ab9926
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TARGET_KL25Z/README.txt Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,2 @@ +INICIALIZACION PARA INPUT CAPTURE +SU ALTERACION PODRIA PRODUCIR UNA FALLA EN LA MEDICION DE FASE \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TARGET_KL25Z/hal.c Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,64 @@ +#include "hal.h" +#include "pinmap.h" +#include "tpm.h" + +/* lowest timer clock is 48e6 / 128 = 375khz */ + +#define TPM_MODULUS 0xFFFF + +volatile uint32_t tx_pin_captured_value; +volatile uint32_t prev_rx_pin_captured_value; +volatile uint32_t rx_pin_captured_value; + +volatile char new_tx_value; // flag tx falling +volatile char new_rx_value; // flag rx rising + +static uint32_t hal_tick; /* make the timer effectively 32bit */ + +/* J10-1 PTE20 TPM1_CH0 (RX rising-edge and 1PPS) + * J10-3 PTE21 TPM1_CH1 (TX falling-edge) + */ + +void tpm1_isr() +{ + if (TPM1->CONTROLS[0].CnSC & TPM_CnSC_CHF_MASK) { + prev_rx_pin_captured_value = rx_pin_captured_value; + rx_pin_captured_value = TPM1->CONTROLS[0].CnV | hal_tick; + TPM1->CONTROLS[0].CnSC |= TPM_CnSC_CHF_MASK; + new_rx_value = 1; + /*HOLA=1; + HOLA=0;*/ + } + + if (TPM1->CONTROLS[1].CnSC & TPM_CnSC_CHF_MASK) { + tx_pin_captured_value = TPM1->CONTROLS[1].CnV | hal_tick; + TPM1->CONTROLS[1].CnSC |= TPM_CnSC_CHF_MASK; + new_tx_value = 1; + } + + if (TPM1->SC & TPM_SC_TOF_MASK) { /* 16bit overflow */ + TPM1->SC |= TPM_SC_TOF_MASK; + hal_tick += 0x10000; + } +} + +int capture_init(void) +{ + pin_function(PTE20, 3); // 3: TPM1_CH0 + pin_function(PTE21, 3); // 3: TPM1_CH1 + + /* Set interrupt handler */ + NVIC_SetVector(TPM1_IRQn, (uint32_t)tpm1_isr); + NVIC_EnableIRQ(TPM1_IRQn); + + /*Configure TPM1 in Interrupt Mode*/ + TPM_init_IC(TPM1, TPM_PLLFLL, TPM_MODULUS, TPM_CLK, PS_128); + + /* Configure Channel 0 from TPM1 as Input Capture for falling edge */ + TPM_CH_init(TPM1, 0, TPM_IC_RISING); // rx pin rising (and 1PPS) + TPM_CH_init(TPM1, 1, TPM_IC_RISING); // tx pin falling + + TPM_CLK_MODE(TPM1, TPM_CLK); // enable clock source to TPM1 + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TARGET_KL25Z/hal.h Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,24 @@ +#include <stdint.h> +//#include "DigitalOut.h" +#ifdef __cplusplus +extern "C" { +#endif + +//DigitalOut HOLA(PTE20); +/* KL25Z */ +#define TIMER_MAX_VALUE 0xffffffff +#define TICKS_PER_MS 375.0 /* 48e6 / 128 */ + +extern volatile char mode_rx_diff; // flag +extern volatile char new_rx_value; // flag +extern volatile char new_tx_value; // flag + +extern volatile uint32_t rx_pin_captured_value; +extern volatile uint32_t prev_rx_pin_captured_value; +extern volatile uint32_t tx_pin_captured_value; + +int capture_init(void); + +#ifdef __cplusplus +} +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TARGET_KL25Z/tpm.c Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,66 @@ +/* + * tpm.c + * + * Created on: Jul 16, 2013 + * Author: B34443 + */ + +#include "MKL25Z4.h" +#include "tpm.h" + +int TPM_init_IC(TPM_Type* TPMx, int clock_source, int modulo, int clock_mode, int ps) +{ + int val = 1; + int i; + + if (TPMx == TPM0) + SIM->SCGC6 |= SIM_SCGC6_TPM0_MASK; + else if (TPMx == TPM1) + SIM->SCGC6 |= SIM_SCGC6_TPM1_MASK; + else + SIM->SCGC6 |= SIM_SCGC6_TPM2_MASK; + + /* 0: disabled + * 1: MCGFLLCLK or MCGFLLCLK/2 + * 2: OSCERCLK + * 3: MCGIRCLK */ + SIM->SOPT2 |= SIM_SOPT2_TPMSRC(clock_source); + + TPMx->MOD = modulo; + + //TOIE: overflow interrupt enable + TPMx->SC = TPM_SC_TOIE_MASK | TPM_SC_CMOD(clock_mode) | TPM_SC_PS(ps); + + i = ps; + + while(i--) + { + val += val; + } + + val=(SystemCoreClock/2)/val; + + return val; +} + +void TPM_CLK_MODE (TPM_Type* TPMx, int clock_mode) +{ + int temp; + temp = TPMx->SC; + temp &= ~TPM_SC_CMOD(3); + temp |= TPM_SC_CMOD(clock_mode); + TPMx->SC = temp; +} + + +void TPM_clear_counter(TPM_Type* TPMx) +{ + TPMx->CNT = 0; +} + +void TPM_CH_init(TPM_Type* TPMx, int channel, int mode) +{ + TPMx->CONTROLS[channel].CnSC = mode | TPM_CnSC_CHIE_MASK; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TARGET_KL25Z/tpm.h Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,37 @@ +/* + * tpm.h + * + * Created on: Jul 16, 2013 + * Author: B34443 + */ + +#ifndef TPM_H_ +#define TPM_H_ + +#define TPM_PLLFLL 1 +#define TPM_OSCERCLK 2 +#define TPM_MCGIRCLK 3 + +#define TPM_CNT_DIS 0 +#define TPM_CLK 1 +#define TPM_EXT_CLK 2 + +#define PS_1 0 +#define PS_2 1 +#define PS_4 2 +#define PS_8 3 +#define PS_16 4 +#define PS_32 5 +#define PS_64 6 +#define PS_128 7 + +#define TPM_IC_RISING TPM_CnSC_ELSA_MASK +#define TPM_IC_FALLING TPM_CnSC_ELSB_MASK +#define TPM_IC_BOTH TPM_CnSC_ELSA_MASK|TPM_CnSC_ELSB_MASK + +extern int TPM_init_IC(TPM_Type* TPMx, int clock_source, int modulo, int clock_mode, int ps); +extern void TPM_CLK_MODE (TPM_Type* TPMx, int clock_mode); +extern void TPM_clear_counter(TPM_Type* TPMx); +extern void TPM_CH_init(TPM_Type* TPMx, int channel, int mode); + +#endif /* TPM_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tipografia5x3.lib Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/JAgustinOtero/code/Tipografia5x3/#265a9be32d7e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,42 @@ +/* +Graficador De Bode "OterOsso" +Juan Agustin Otero 6°A Técnica +Hernan Osso 6°A Técnica +Practicas profecionalizantes PIO IX 2018 +Desarrollo de software en proceso, desarrollo incompleto +*/ +#include "mbed.h" +#include "math.h" +#include "st7920.h" +#include "ST7920Libreries.h" +#include "GraficadorDeBode.h" +#include "AD9833.h" +#include "hal.h" + +Ticker TiempoFase; + +/*funcion principal: se analizan las funciones en base a los pulsadores (Interfaz Usuario)*/ +int main() +{ int ret; + ret = capture_init(); + if (ret != 0) { + printf("fail: %d = capture_init()\r\n", ret); + } + unsigned char opcion=0; + init(); + CLRScreen(); + grafico(); + SPI_INITIALIZATION(); + + while(1) { + //CLRScreen(); + setFreq(1000); + if(screen_pass() == 1) flechaY(2 , 12 + (9 * opcion) , 1 , 1);/*grafica una flecha para seleccionar una opcion en el menu principal*/ + else if(screen_pass() == 2) flechaY(2 , 12 + (9 * opcion) , 1 , 1);/*grafica una flecha para seleccionar una opcion en el menu del zoom*/ + PULSADORMENU_fun();/*analiza la opcion en la que se encuentra el menu y actua en base a eso*/ + opcion=PULSADORDOWN_fun();/*cambia la opcion en la que se encuentra el menu a una mas abajo de la actual y varia la posicion de la flecha*/ + opcion=PULSADORUP_fun();/*cambia la opcion en la que se encuentra el menu a una mas arriba de la actual y varia la posicion de la flecha*/ + PULSADORRIGHT_fun();/*varia las pantallas de zoom aumentando el rango de frecuencias que se muestra*/ + PULSADORLEFT_fun();/*varia las pantallas de zoom disminuyendo el rango de frecuencias que se muestra*/ + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 06 00:11:53 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539 \ No newline at end of file