Hello. Mi project consist of a 7 segment display in which i write them once a at time and very quickly using a PIT interrupt. So, the PIT ISR (that works correctly) is in charge of the display. In this ISR, what i want to display is what I write on the vector unsigned int DISPB[5]; which is a global variable in the Events.c.
Now, what I want to do is to display the time. I do the following procedure:
initialize the RTC (using fuctions provided by processor expert)
getting the time (using fuctions provided by processor expert)
call a fuction in which I overwrite the DISPB with the new time
my problem is that I watch the initialized time, but not the current time. In other words, I cant overwrite DISPB more than one time.
I attach my main.c and my evects.c.
Thanks
/* ###################################################################
** Filename : main.c
** Project : MEGALUX II
** Processor : MKE02Z64VLH2
** Version : Driver 01.01
** Compiler : GNU C Compiler
** Date/Time : 2015-03-04, 12:31, # CodeGen: 0
** Abstract :
** Main module.
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.01
** @brief
** Main module.
** This module contains user's application code.
*/
/*!
** @addtogroup main_module main module documentation
** @{
*/
/* MODULE main */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "PTD5.h"
#include "BitIoLdd1.h"
#include "PTH0.h"
#include "BitIoLdd2.h"
#include "PTB0.h"
#include "BitIoLdd3.h"
#include "PTA0.h"
#include "BitIoLdd4.h"
#include "PTB2.h"
#include "BitIoLdd5.h"
#include "PTB3.h"
#include "BitIoLdd6.h"
#include "Red.h"
#include "BitIoLdd7.h"
#include "Blue.h"
#include "BitIoLdd8.h"
#include "PTD0.h"
#include "BitIoLdd9.h"
#include "PTD1.h"
#include "BitIoLdd10.h"
#include "RTC1.h"
#include "PIT.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
LDD_TDeviceData *MyRTCPtr;
LDD_RTC_TTime Time;
LDD_TError Error;
int i;
int k;
char *DayOfWeekName[] = {
"Sunday",
"Monday",
"Tuesady",
"Wensday",
"Thursday",
"Friday",
"Saturday"
};
unsigned int buffer_hora;
void inicializar_rtc (){
MyRTCPtr = RTC1_Init((LDD_TUserData *)NULL, FALSE); /* Initialize the device, reset all RTC registers */
}
/*void mostrar_fecha_y_hora (){
RTC1_GetTime(MyRTCPtr, &Time);
DISPB[0] = 0;
asignar_numero(Time.Minute / 10);
DISPB[1] = buffer_hora;
asignar_numero(Time.Minute % 10);
DISPB[2] = buffer_hora;
asignar_numero(Time.Second / 10);
DISPB[3] = buffer_hora;
asignar_numero(Time.Second % 10);
DISPB[4] = buffer_hora;
}
*/
/* User includes (#include below this line is not maintained by Processor Expert) */
/*lint -save -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
MyRTCPtr = RTC1_Init((LDD_TUserData *)NULL, FALSE);
for(;;){
RTC1_GetTime(MyRTCPtr, &Time);
asignar_hora_a_DISPB(Time.Minute/10, Time.Minute%10,Time.Second/10,Time.Second%10);
}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/
/* ###################################################################
** Filename : Events.c
** Project : MEGALUX II
** Processor : MKE02Z64VLH2
** Component : Events
** Version : Driver 01.00
** Compiler : GNU C Compiler
** Date/Time : 2015-03-04, 12:31, # CodeGen: 0
** Abstract :
** This is user's event module.
** Put your event handler code here.
** Settings :
** Contents :
** Cpu_OnNMIINT - void Cpu_OnNMIINT(void);
**
** ###################################################################*/
/*!
** @file Events.c
** @version 01.00
** @brief
** This is user's event module.
** Put your event handler code here.
*/
/*!
** @addtogroup Events_module Events module documentation
** @{
*/
/* MODULE Events */
#include "Cpu.h"
#include "Events.h"
unsigned int DISPC=0; //variable global para ser utlizada en el ISR del display
unsigned int DISPB[5]= {0x8E,0x9E,0x9C,0x6E,0xEE};
//unsigned int DISPB[5]= {0x00,0x02,0x02,0x02,0x00};
unsigned int numero_display = 0;
unsigned int boton_apretado;
unsigned int ultimo_display_escrito;
unsigned int cont=0;
unsigned int buffer_hora;
int i;
int k;
void seleccionar_display(int numero_display){
switch (numero_display){
case 0:
PTA0_ClrVal ();
PTB0_ClrVal ();
PTB2_ClrVal (); //queremos que se prenda el primer display
break;
case 1:
PTA0_SetVal ();
PTB0_ClrVal ();
PTB2_ClrVal (); //queremos que se prenda el segundo display
break;
case 2:
PTA0_ClrVal ();
PTB0_SetVal ();
PTB2_ClrVal (); //queremos que se prenda el tercer display
break;
case 3:
PTA0_SetVal ();
PTB0_SetVal ();
PTB2_ClrVal (); //queremos que se prenda el cuarto display
break;
case 4:
PTA0_ClrVal ();
PTB0_ClrVal ();
PTB2_SetVal (); //queremos que se prenda el quinto
break;
case 5:
PTA0_SetVal ();
PTB0_ClrVal ();
PTB2_SetVal (); //queremos que se prenda el quinto
break;
case 6:
PTA0_ClrVal ();
PTB0_SetVal ();
PTB2_SetVal (); //queremos que se prenda el quinto
break;
case 7:
PTA0_SetVal ();
PTB0_SetVal ();
PTB2_SetVal (); //queremos que se prenda el quinto
break;
default:
PTA0_SetVal ();
PTB0_SetVal ();
PTB2_SetVal (); //queremos que se prenda ningun display
break;
}
}
void mandar_dato_a_display(unsigned int dato){
for(i=0;i<8;i++){
unsigned char bit_salida = dato & 1;
dato = dato >> 1;
//mandamos el bit
if (bit_salida == 0) PTD5_ClrVal ();
else PTD5_SetVal ();
for(k=0;k<10;k++) //software delay para clock del CD4015
PTH0_SetVal (); //subimos ponemos el clock en alto por un tiempo
PTH0_ClrVal (); //bajamos el clock por un tiempo
for(k=0;k<100;k++) {}
}
}
void buscar_boton_apretado (){
if ( !PTD1_GetVal ()){
if (DISPC == 0)
boton_apretado = 0xBE ; // 6
if (DISPC == 1)
boton_apretado = 0x66 ; // 4
if (DISPC == 2)
boton_apretado = 0x3E ; // B
if (DISPC == 3)
boton_apretado = 0xB6 ; // 5
if (DISPC == 4)
boton_apretado = 0x9C ; // C
if (DISPC == 5)
boton_apretado = 0xE0 ; // 7
if (DISPC == 6)
boton_apretado = 0xFE ; // 8
if (DISPC == 7)
boton_apretado = 0xF6 ; // 9
}
if ( !PTD0_GetVal ()){
if (DISPC == 0)
boton_apretado = 0xF2 ; // 3
if (DISPC == 1)
boton_apretado = 0x60 ; // 1
if (DISPC == 2)
boton_apretado = 0xEE ; // A
if (DISPC == 3)
boton_apretado = 0xDA ; // 2
if (DISPC == 4)
boton_apretado = 0x7A ; // D
if (DISPC == 5)
boton_apretado = 0x9E ; // E
if (DISPC == 6)
boton_apretado = 0xFC ; // 0
if (DISPC == 7)
boton_apretado = 0x8E ; // F
}}
void ingresar_boton_a_la_izquierda (){
for ( i=0 ; i<4 ; i++)
DISPB[i] = DISPB[i+1];
DISPB[4] = boton_apretado;
}
void asignar_numero(unsigned int numero){
if (numero == 0)
buffer_hora = 0xFC;
if (numero == 1)
buffer_hora = 0x60;
if (numero == 2)
buffer_hora = 0xDA;
if (numero == 3)
buffer_hora = 0xF2;
if (numero == 4)
buffer_hora = 0x66;
if (numero == 5)
buffer_hora = 0xB6;
if (numero == 6)
buffer_hora = 0xBE;
if (numero == 7)
buffer_hora = 0xE0;
if (numero == 8)
buffer_hora = 0xFE;
if (numero == 9)
buffer_hora = 0xF6;
}
void asignar_hora_a_DISPB (int MM, int mm, int SS, int ss){
DISPB[0] = 0;
asignar_numero(MM);
DISPB[1] = buffer_hora;
asignar_numero(mm);
DISPB[2] = buffer_hora;
asignar_numero(SS);
DISPB[3] = buffer_hora;
asignar_numero(ss);
DISPB[4] = buffer_hora;
}
void ISR_PIT_display (void){
Red_SetVal ();
Blue_ClrVal();
PTB3_SetVal (); //inicialmente el enable esta en alto
if(DISPC <= 4 ){
unsigned int dato = DISPB [DISPC];
mandar_dato_a_display(dato);
}
seleccionar_display(numero_display);
PTB3_ClrVal (); //seteamos el enable en alto para mandar los datos
for(k=0;k<2000;k++){}
if (cont == 8)
if ( !PTD1_GetVal () || !PTD0_GetVal () ){
buscar_boton_apretado();
ingresar_boton_a_la_izquierda ();
}
PTB3_SetVal ();
if(numero_display == 7 ) numero_display = 0;
else numero_display ++;
if(DISPC == 7 ) DISPC = 0;
else DISPC ++;
if(cont == 8 ) cont = 0; //contador para prevenir rebotes
else cont ++;
}
#ifdef __cplusplus
extern "C" {
#endif
/* User includes (#include below this line is not maintained by Processor Expert) */
/*
** ===================================================================
** Event : Cpu_OnNMIINT (module Events)
**
** Component : Cpu [MKE02Z64QH2]
*/
/*!
** @brief
** This event is called when the Non maskable interrupt had
** occurred. This event is automatically enabled when the [NMI
** interrupt] property is set to 'Enabled'.
*/
/* ===================================================================*/
void Cpu_OnNMIINT(void)
{
/* Write your code here ... */
}
/* END Events */
#ifdef __cplusplus
} /* extern "C" */
#endif
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/
Hi, Juan,
Regarding your question, I think this code in main() function is incorrect, you are not required to update the display in so fast speed:
for(;;)
{
RTC1_GetTime(MyRTCPtr, &Time);
asignar_hora_a_DISPB(Time.Minute/10, Time.Minute%10,Time.Second/10,Time.Second%10);
}
Pls update the display in the ISR of PIT as you have down. In otherwords, pls put the above code into ISR of PIT:
void ISRofPIT(void)
{
RTC1_GetTime(MyRTCPtr, &Time);
asignar_hora_a_DISPB(Time.Minute/10, Time.Minute%10,Time.Second/10,Time.Second%10);
}
If I misunderstand you, I am sorry in advance.
BR
XiangJun Rong
Hi Juan
I can't help with the PE generated code but I have attached binaries for the FRDM-KE02Z and FRDM-KE02Z40M (assuming you have one of these as reference) that use the RTC as 1Hz interrupt and a PIT with 500us interrupt rate toggling the LED (also a SW timer togging an LED at 2.5Hz so that it looks to be blinking with different colours).
You can attach the OpenSDA COM port at 115200 Baud and set a date/time in the Administrator menu:
Admin. menu =================== up go to main menu show_config Show configuration save Save configuration to FLASH reject Reset non-saved changes restore Restore factory settings show_time Display date/time set_time Set time hh:mm:ss set_date Set Date dd:mm:yyyy show_alarm Display alarm d/t set_alarm Set alarm (date)(+)[time] del_alarm Delete alarm show_lp Show low power mode and options set_lp [option] Set low power mode reset Reset device last_rst Reset cause help Display menu specific help quit Leave command mode set_date 16.3.2015 New date set 16.03.2015 04:23:41 #set_time 15:30:00 New time set 16.03.2015 15:30:00
In the I/O menu there is a memory debugging interface so you can look at the RTC registers using
md 4003d000 l 3 Memory Display 0x4003d000 00008740 000001ff 00000142 ...@.......B
There you will also see the counter running.
This solution adds Gregorian date/time to the RTC and also allows the time/date to be maintained across software resets.
If you check the register values and compare with ones configured by your code you may find the cause of any problems.
Regards
Mark
Kinetis: µTasker Kinetis support
KE: µTasker FRDM-KE02Z support / µTasker FRDM-KE02Z40M support / µTasker FRDM-KE06Z support
Time Management: http://www.utasker.com/docs/uTasker/uTasker_Time.pdf
Hardware Timers: http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF
For the complete "out-of-the-box" Kinetis experience and faster time to market
Hi Troisi
Can you provide the screenshot of the RTC settings too? I think you need to activate the interrupt. The first thing I would recommend you to check is that the RTC counter is being updated every second. so for that activate the interrupts in RTC. On generating the code, in Event.c you will have on second function so try to print or do some activity in that function which will let you know if the time is getting updated in RTC. This will help in making your project. One main thing I forgot, Did you activated the RTC clock in the PE?? without that RTC won't work. In the clock generation tab you will get that option in CPU settings. u can take that snapshot and post it, That will make others work easier to recreate the issue and resolve it.
Regards
Amit
Hello. I attach the screeshot of the RTC PE settings. However, everything seems to be set correctly. Could it be that when a PIT starts the RTC stops owing to the activation or desactivation of any RTC register? Thanks,Juan Ignacio Troisi
Date: Sun, 15 Mar 2015 22:24:42 -0700
From: admin@community.freescale.com
To: ignacio_troisi@hotmail.com
Subject: Re: - RTC problem. Cant display current time (procesor expert)
RTC problem. Cant display current time (procesor expert)
reply from Amit Kumar in Kinetis Microcontrollers - View the full discussion
Hi Troisi
Can you provide the screenshot of the RTC settings too? I think you need to activate the interrupt. The first thing I would recommend you to check is that the RTC counter is being updated every second. so for that activate the interrupts in RTC. On generating the code, in Event.c you will have on second function so try to print or do some activity in that function which will let you know if the time is getting updated in RTC. This will help in making your project. One main thing I forgot, Did you activated the RTC clock in the PE?? without that RTC won't work. In the clock generation tab you will get that option in CPU settings. u can take that snapshot and post it, That will make others work easier to recreate the issue and resolve it.
Regards
Amit
Did your question get answered?
If so, say thanks by clicking Correct Answer in the community thread!
Reply to this message by replying to this email, or go to the message on Freescale Community
Start a new discussion in Kinetis Microcontrollers by email or at Freescale Community
Following RTC problem. Cant display current time (procesor expert) in these streams:
Inbox