Está en la página 1de 19

CARRERA DE INGENIERIA ELECTRICA.

Prácticas de Laboratorio de Electrónica III. Practica No. 10

INSTTITUTO POLITECNICO NACIONAL


Escuela Superior de Ingeniería Mecánica y Eléctrica

INGENIERIA ELECTRICA

LABORATORIO DE ELECTRONICA III.

PRACTICA No. 10 (OCT-2021)

Reloj del Arduino RTC

Número de Equipo: 4

Grupo: 6EM2

INTEGRANTES

Nombre de los Alumnos: No. de Boleta:

1). Sánchez Nequiz Zelzin 2019301647


2). Serrano Rosales Carmen Lorena 2015011068

Nombre de los Profesores:


Prof. Titular: Delgado Mendoza José Luis

Fecha de realización:

Calificación:

JLDM
Pá gina 1 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

PRÀCTICA No. 10: Reloj del Arduino RTC.

OBJETIVOS:

a) Conocimientos de los diferentes tipos de Reloj en el Microcontrolador.


b) Conocer el funcionamiento del Reloj del Sistema de Microcontrolador.
c) Configuración de Reloj en la programación con el Programa Arduino, en su versión 1.6, para
configuración del microcontrolador ATSAM3X8E.
d) Saber la inicialización con el Reloj Interno del Microcontrolador.

Introducción Teórica.

Material y equipo utilizado

1 Computadora
1 Software Arduino.
1 Tarjeta Arduino Uno.

DESARROLLO DE LA PRÁCTICA.

Programa de Reloj: Fecha y tiempo sobre el serial monitor.


/*
* Pratica 10b. Fecha:
* Grupo: 6EV Equipo:00
* Objetivo: Este sketch usa La library de tiempo para desplegar
* el tiempo del día:
*/
#include <TimeLib.h>
time_t T0, T1 ; // Variables que Contienen fechas

void setup()
{ Serial.begin(115200); }

void loop()
{ T0 = SetFecha(2017, 06, 5, 20, 17, 0); // 5 Jun 2017 20:17
printFecha(T0) ;
T1 = SetFecha(2017, 07, 1, 11, 00, 0); // 1 Jul 2017 11:00
printFecha(T1) ;
printFecha(T1 - T0);

Serial.println("--------------------------------------------------");
time_t H = T1 - T0 ;

Serial.print(String(year(H )- 2000)+" años," + String(month(H)-1 )+" meses,");

JLDM
Pá gina 2 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10
Serial.println(String(day(H))+ " dias," + String(hour(H))+ " horas");
Serial.println("---------------------------------------------------");
}

void printFecha(time_t t)
{
Serial.print(day(t)) ; Serial.print(+ "/") ; Serial.print(month(t)); Serial.print(+ "/") ;
Serial.print(year(t)); Serial.print( " ") ;
Serial.print(hour(t)); Serial.print(+ ":") ; Serial.print(minute(t)); Serial.print(":") ;
Serial.println(second(t));
delay(1000);
}

time_t SetFecha(int y, int m, int d, int h, int mi, int s )


{ tmElements_t Fecha ;
Fecha.Second = s;
Fecha.Minute = mi;
Fecha.Hour = h;
Fecha.Day = d ;
Fecha.Month = m ;
Fecha.Year = y -1970 ;

return makeTime(Fecha);
}

Visualizacion sobre el Serial Monitor:

JLDM
Pá gina 3 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10
Reloj de Tiempo Real RTC Modulo DS1302 o DS1307:

El pin SQW, es una salida digital del chip DS1307, que nos permite generar una señal cuadrada de frecuencia
programable (De 1Hz, 4kHz, 8kHz,32kHz) que podemos emplear como base de tiempos para el reloj de cualquier
circuito sin necesidad de un cristal adicional de cuarzo y circuito oscilador (Que ya lleva el propio Tiny RTC).

Basta con que instalemos el modulo correspondiente al nuevo reloj DS1307. Y para ello descargamos e instalamos
una nueva librería, aquí Librería DS1307RTC,

Como lo normal cuando instalas un RTC, es que no tenga la hora ajustada, vamos a empezar por ahí. Vamos a ver si
el chip ha sido puesto en hora:

#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

void setup()
{   Serial.begin(115200);
//while (!Serial) ;              // Solo para el Leonardo
setSyncProvider(RTC.get);      // Vamos a usar el RTC
setTime(21,46,00,8,11,2014); // Las 21:45:00 del dia 8 de Nov de 2014
if (timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else

JLDM
Pá gina 4 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

Serial.println("RTC has set the system time");


}
void loop()
{ digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay()
{     Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
void printDigits(int digits)
{     Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}

Primer ejercicio de Manejo de CLK principal.

JLDM
Pá gina 5 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

/*
* Practica 10a Fecha:17 Nov 2016
* Grupo: 6E_2 Equipo
* Participantes:
* Objetivo:
*
*
*/

// 84Mhz/128 = 656.250 KHz


// 42Mhz/44.1Khz = 952.38
// 10.5Mhz/44.1Khz = 238.09
// 2.625Hmz/44.1Khz = 59.5
// 656Khz/44.1Khz = 14.88 // 131200 / 656000 = .2 (.2 seconds)

// 84Mhz/44.1Khz = 1904 instructions per tick


const int led_pin = 12;
int state = false;
int interruptCtr = 1;
int S = 0;

void setup()
{
pinMode(led_pin, OUTPUT);
/* turn on the timer clock in the power management controller */
pmc_set_writeprotect(false); // disable write protection for pmc registers
pmc_enable_periph_clk(ID_TC7); // enable peripheral clock TC7

/* we want wavesel 01 with RC */


TC_Configure(/* clock */TC2,/* channel */1, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC |
TC_CMR_TCCLKS_TIMER_CLOCK4);
TC_SetRC(TC2, 1, 131200);
TC_Start(TC2, 1);

// enable timer interrupts on the timer


TC2->TC_CHANNEL[1].TC_IER=TC_IER_CPCS; // IER = interrupt enable register
TC2->TC_CHANNEL[1].TC_IDR=~TC_IER_CPCS; // IDR = interrupt disable register

/* Enable the interrupt in the nested vector interrupt controller */


/* TC4_IRQn where 4 is the timer number * timer channels (3) + the channel number (=(1*3)+1) for timer1 channel1 */
NVIC_EnableIRQ(TC7_IRQn);
}

void loop()
{
// do nothing timer interrupts will handle the blinking;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// INTERRUPT HANDLERS

JLDM
Pá gina 6 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void TC7_Handler()
{
// We need to get the status to clear it and allow the interrupt to fire again
TC_GetStatus(TC2, 1);
state = !state;
digitalWrite(led_pin, state);

if( interruptCtr++ >= 6 )


{
interruptCtr = 1;
S = !S; // are we flashing S or O
if( S ) // set time till next interrupt
TC_SetRC(TC2, 1, 131200); // 131200 / 656000 = .2 seconds
else
TC_SetRC(TC2, 1, 656000); // 656000/ 656000 = 1 second
}
}

Segundo Ejercicio

JLDM
Pá gina 7 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10
#include "Waveforms.h"

#define oneHzSample 1000000/maxSamplesNum  // sample for the 1Hz signal expressed in microseconds 

const int button0 = 2, button1 = 3;
volatile int wave0 = 0, wave1 = 0;

int i = 0;
int sample;

void setup() {
  analogWriteResolution(12);  // set the analog output resolution to 12 bit (4096 levels)
  analogReadResolution(12);   // set the analog input resolution to 12 bit 

  attachInterrupt(button0, wave0Select, RISING);  // Interrupt attached to the button connected to pin 2


  attachInterrupt(button1, wave1Select, RISING);  // Interrupt attached to the button connected to pin 3
}

void loop() {
  // Read the the potentiometer and map the value  between the maximum and the minimum sample available
  // 1 Hz is the minimum freq for the complete wave
  // 170 Hz is the maximum freq for the complete wave. Measured considering the loop and the analogRead() time
  sample = map(analogRead(A0), 0, 4095, 0, oneHzSample);
  sample = constrain(t_sample, 0, oneHzSample);

  analogWrite(DAC0, waveformsTable[wave0][i]);  // write the selected waveform on DAC0


  analogWrite(DAC1, waveformsTable[wave1][i]);  // write the selected waveform on DAC1

  i++;
  if(i == maxSamplesNum)  // Reset the counter to repeat the wave
    i = 0;

  delayMicroseconds(sample);  // Hold the sample value for the sample time


}

// function hooked to the interrupt on digital pin 2


void wave0Select() {
  wave0++;
  if(wave0 == 4)
    wave0 = 0;
}

// function hooked to the interrupt on digital pin 3


void wave1Select() {
  wave1++;
  if(wave1 == 4)
    wave1 = 0;
}

JLDM
Pá gina 8 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

Código de Waveforms.h

#ifndef _Waveforms_h_
#define _Waveforms_h_

#define maxWaveform 4
#define maxSamplesNum 120

static int waveformsTable[maxWaveform][maxSamplesNum] = {


// Sin wave
{
0x7ff, 0x86a, 0x8d5, 0x93f, 0x9a9, 0xa11, 0xa78, 0xadd, 0xb40, 0xba1,
0xbff, 0xc5a, 0xcb2, 0xd08, 0xd59, 0xda7, 0xdf1, 0xe36, 0xe77, 0xeb4,
0xeec, 0xf1f, 0xf4d, 0xf77, 0xf9a, 0xfb9, 0xfd2, 0xfe5, 0xff3, 0xffc,
0xfff, 0xffc, 0xff3, 0xfe5, 0xfd2, 0xfb9, 0xf9a, 0xf77, 0xf4d, 0xf1f,
0xeec, 0xeb4, 0xe77, 0xe36, 0xdf1, 0xda7, 0xd59, 0xd08, 0xcb2, 0xc5a,
0xbff, 0xba1, 0xb40, 0xadd, 0xa78, 0xa11, 0x9a9, 0x93f, 0x8d5, 0x86a,
0x7ff, 0x794, 0x729, 0x6bf, 0x655, 0x5ed, 0x586, 0x521, 0x4be, 0x45d,
0x3ff, 0x3a4, 0x34c, 0x2f6, 0x2a5, 0x257, 0x20d, 0x1c8, 0x187, 0x14a,
0x112, 0xdf, 0xb1, 0x87, 0x64, 0x45, 0x2c, 0x19, 0xb, 0x2,
0x0, 0x2, 0xb, 0x19, 0x2c, 0x45, 0x64, 0x87, 0xb1, 0xdf,
0x112, 0x14a, 0x187, 0x1c8, 0x20d, 0x257, 0x2a5, 0x2f6, 0x34c, 0x3a4,
0x3ff, 0x45d, 0x4be, 0x521, 0x586, 0x5ed, 0x655, 0x6bf, 0x729, 0x794
}
,

// Triangular wave
{
0x44, 0x88, 0xcc, 0x110, 0x154, 0x198, 0x1dc, 0x220, 0x264, 0x2a8,
0x2ec, 0x330, 0x374, 0x3b8, 0x3fc, 0x440, 0x484, 0x4c8, 0x50c, 0x550,
0x594, 0x5d8, 0x61c, 0x660, 0x6a4, 0x6e8, 0x72c, 0x770, 0x7b4, 0x7f8,
0x83c, 0x880, 0x8c4, 0x908, 0x94c, 0x990, 0x9d4, 0xa18, 0xa5c, 0xaa0,
0xae4, 0xb28, 0xb6c, 0xbb0, 0xbf4, 0xc38, 0xc7c, 0xcc0, 0xd04, 0xd48,
0xd8c, 0xdd0, 0xe14, 0xe58, 0xe9c, 0xee0, 0xf24, 0xf68, 0xfac, 0xff0,
0xfac, 0xf68, 0xf24, 0xee0, 0xe9c, 0xe58, 0xe14, 0xdd0, 0xd8c, 0xd48,
0xd04, 0xcc0, 0xc7c, 0xc38, 0xbf4, 0xbb0, 0xb6c, 0xb28, 0xae4, 0xaa0,
0xa5c, 0xa18, 0x9d4, 0x990, 0x94c, 0x908, 0x8c4, 0x880, 0x83c, 0x7f8,
0x7b4, 0x770, 0x72c, 0x6e8, 0x6a4, 0x660, 0x61c, 0x5d8, 0x594, 0x550,
0x50c, 0x4c8, 0x484, 0x440, 0x3fc, 0x3b8, 0x374, 0x330, 0x2ec, 0x2a8,
0x264, 0x220, 0x1dc, 0x198, 0x154, 0x110, 0xcc, 0x88, 0x44, 0x0
}
,

// Sawtooth wave
{
0x22, 0x44, 0x66, 0x88, 0xaa, 0xcc, 0xee, 0x110, 0x132, 0x154,
0x176, 0x198, 0x1ba, 0x1dc, 0x1fe, 0x220, 0x242, 0x264, 0x286, 0x2a8,
0x2ca, 0x2ec, 0x30e, 0x330, 0x352, 0x374, 0x396, 0x3b8, 0x3da, 0x3fc,
0x41e, 0x440, 0x462, 0x484, 0x4a6, 0x4c8, 0x4ea, 0x50c, 0x52e, 0x550,
0x572, 0x594, 0x5b6, 0x5d8, 0x5fa, 0x61c, 0x63e, 0x660, 0x682, 0x6a4,
0x6c6, 0x6e8, 0x70a, 0x72c, 0x74e, 0x770, 0x792, 0x7b4, 0x7d6, 0x7f8,
0x81a, 0x83c, 0x85e, 0x880, 0x8a2, 0x8c4, 0x8e6, 0x908, 0x92a, 0x94c,
0x96e, 0x990, 0x9b2, 0x9d4, 0x9f6, 0xa18, 0xa3a, 0xa5c, 0xa7e, 0xaa0,
0xac2, 0xae4, 0xb06, 0xb28, 0xb4a, 0xb6c, 0xb8e, 0xbb0, 0xbd2, 0xbf4,
0xc16, 0xc38, 0xc5a, 0xc7c, 0xc9e, 0xcc0, 0xce2, 0xd04, 0xd26, 0xd48,
0xd6a, 0xd8c, 0xdae, 0xdd0, 0xdf2, 0xe14, 0xe36, 0xe58, 0xe7a, 0xe9c,

JLDM
Pá gina 9 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10
0xebe, 0xee0, 0xf02, 0xf24, 0xf46, 0xf68, 0xf8a, 0xfac, 0xfce, 0xff0
}
,

// Square wave
{
0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
}

};

#endif

CALCULOS.

Desarrollar los cálculos correspondientes para la obtención de las diferentes frecuencias en función
de los dispositivos electrónicos.

SIMULACIONES.

Realizar las simulaciones de los circuitos, empleando el software Proteus.

COMENTARIOS Y APORTACIONES NUEVAS.

Para este punto describa sus comentarios obtenidos durante el desarrollo de esta práctica, y que
aportaciones usted haría de esta práctica.

CONCLUSIONES Y HALLAZGOS.

Conclusiones de cada uno de los integrantes, y que nuevos hallazgos logro descubrir de acuerdo a
su experiencia con el acercamiento de esta asignatura.

JLDM
Pá gina 10 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

BIBLIOGRAFIAS.

REFERENCIAS.

Para este punto usted debe incluir en el reporte cuando menos dos artículos, o temas de alguna
revista, libro o publicación actual, referente al tema tratado en esta práctica.

----------------------------------- FIN DE LA PRÁCTICA -----------------------------------

JLDM
Pá gina 11 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10
Simulaciones

JLDM
Pá gina 12 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

JLDM
Pá gina 13 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

JLDM
Pá gina 14 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

JLDM
Pá gina 15 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

JLDM
Pá gina 16 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

Conclusiones

Sánchez Nequiz Zelzin

Se logró observar el funcionamiento del Sistema Arduino y poder practicar, así como realizar
distintos circuitos para hacer Reset con into= e Int 1, por medio de la tarjeta Arduino 1 y poder
variar la velocidad, al contar con una de las ultimas versiones, llegaba a existir un fallo a la hora
de usar el código.

Referencias

 https://programarfacil.com/blog/arduino-blog/utilizar-boton-reinicio-
externo- arduino/
 https://www.arduino.cc/reference/es/language/functions/
communication/serial/pri ntln/
 https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-
7810-
 AutomotiveMicrocontrollers-ATmega328P_Datasheet.pdf

JLDM
Pá gina 17 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

JLDM
Pá gina 18 de 19
CARRERA DE INGENIERIA ELECTRICA.
Prácticas de Laboratorio de Electrónica III. Practica No. 10

JLDM
Pá gina 19 de 19

También podría gustarte