betuse
Junior Member level 3
- Joined
- Oct 17, 2013
- Messages
- 26
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 173
#include "Resources.h"
sbit ENCODER at GPIO_PORTG_DATA.B4;
sbit ENCODER_Direction at GPIO_PORTG_DIR4_bit;
unsigned int RPM, Cnt = 0;
unsigned char Txt[4];
unsigned char DsplyCnt = 0;
// TFT module connections
char TFT_DataPort at GPIO_PORTJ_DATA;
sbit TFT_RST at GPIO_PORTH_DATA5_bit;
sbit TFT_RS at GPIO_PORTG_DATA7_bit;
sbit TFT_CS at GPIO_PORTH_DATA6_bit;
sbit TFT_RD at GPIO_PORTC_DATA5_bit;
sbit TFT_WR at GPIO_PORTH_DATA4_bit;
sbit TFT_BLED at GPIO_PORTA_DATA3_bit;
char TFT_DataPort_Direction at GPIO_PORTJ_DIR;
sbit TFT_RST_Direction at GPIO_PORTH_DIR5_bit;
sbit TFT_RS_Direction at GPIO_PORTG_DIR7_bit;
sbit TFT_CS_Direction at GPIO_PORTH_DIR6_bit;
sbit TFT_RD_Direction at GPIO_PORTC_DIR5_bit;
sbit TFT_WR_Direction at GPIO_PORTH_DIR4_bit;
sbit TFT_BLED_Direction at GPIO_PORTA_DIR3_bit;
// End TFT module connections
void DrawScr() {
TFT_Init_ILI9341_8bit(320, 240);
TFT_Fill_Screen(CL_WHITE);
TFT_Set_Pen(CL_Black, 2);
TFT_Line(20, 205, 300, 205);
TFT_Line(20, 40, 300, 40);
TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_RED, FO_HORIZONTAL);
TFT_Write_Text("DC Motor with LMD18200", 40, 14);
TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_RED, FO_HORIZONTAL);
TFT_Write_Text("Tiva C", 19, 210);
TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_RED, FO_HORIZONTAL);
TFT_Write_Text("TI", 220, 210);
TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_Black, FO_HORIZONTAL);
TFT_Write_Text("Speed (RPM): ", 90, 50);
TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_Black, FO_HORIZONTAL);
TFT_Write_Text("Direction (CW / CCW): ", 60, 120);
}
void Timer0A_interrupt() iv IVT_INT_TIMER0A_16_32_bit {
TIMER_ICR_TATOCINT_bit = 1;
RPM = 6*Cnt; // Speed in RPM
IntToStr(RPM, Txt); // Convert to string
Cnt = 0;
DsplyCnt++;
if(DsplyCnt == 10) { // 1 s ?
DsplyCnt = 0;
TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_Red, FO_HORIZONTAL);
TFT_Write_Text(Txt, 125, 80);
}
}
void main(){
GPIO_Digital_Input(&GPIO_PORTG, _GPIO_PINMASK_4);
GPIO_Digital_Output(&GPIO_PORTF, _GPIO_PINMASK_4); // Enable digital output on PORTF, bit4 za PWM
GPIO_PORTF_DATA.B4 = 1; //PWM pinot od LMD, vrti
TFT_Set_Default_Mode();
DrawScr();
SYSCTL_RCGC1_TIMER0_bit = 1; // Enable clock gating for timer module 0
EnableInterrupts(); // Enables the processor interrupt.
TIMER_CTL_TAEN_bit = 0; // Disable timer
TIMER0_CFG = 0; // Set 32-bit timer configuration
TIMER0_TAMR |= 2; // Set periodic mode
TIMER0_TAILR = Get_Fosc_kHz()*100; // Set interval load
NVIC_IntEnable(IVT_INT_TIMER0A_16_32_bit); // Enable timer interrupt
TIMER_IMR_TATOIM_bit = 1; // Enable time-out timer A interrupt
TIMER_CTL_TAEN_bit = 1; // Enable timer A
while(1){
while(ENCODER == 0); // Wait if 0
Cnt++; // Increment encoder count
while(ENCODER == 1); // Wait if 1
}
}
void Timer0A_interrupt() iv IVT_INT_TIMER0A_16_32_bit {
static unsigned char OldTxt[4]={' '};
TIMER_ICR_TATOCINT_bit = 1;
RPM = 6*Cnt; // Speed in RPM
IntToStr(RPM, Txt); // Convert to string
Cnt = 0;
DsplyCnt++;
if(DsplyCnt == 10) { // 1 s ?
DsplyCnt = 0;
// erase old text
TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_WHITE, FO_HORIZONTAL);
TFT_Write_Text(OldTxt, 125, 80);
// write new text
TFT_Set_Font(&HandelGothic_BT21x22_Regular, CL_Red, FO_HORIZONTAL);
TFT_Write_Text(Txt, 125, 80);
// save currect text for erase
memcpy(OldTxt, Txt, 4);
}
}
IntToStr(RPM, Txt);
sprintf(Txt,"%3d", RPM);
say RPM is a 16 bit integer and UARTPutChar() sends a byteHorace1, one more question for you, according previous project you help me,
now I need to save in array, every 1ms, RPM from motor, and send to PC via UART,
exactly,
every 1ms, I read RPM value, and send to PC via UART i array...
can you advice how to send via UART RPM value?
RPM is integer, so I need to split on two digit, right?
can you advice please?
best regards
UART2PutChar(RPM >> 8); // send most significant byte
UART2PutChar(RPM); // send least significant byte
just thinking about the RPM for nowHorace1,
at the start sorry because I wrote directly to you, but because you help me with concrete solution, I think is not a problem,
I have several conclusion:
I read RPM app 890 on TFT, but expected value need to be app 2000 RPM,
I check my calculations and I think I have a problem with slow procedure for TFT writing and I lost some values from RPM?
is it possible?
unsigned char Txt[6];
store the data as integer convert to characters just before transmission, e.g. code something along the lines ofTFT display? I will not use it,
only measure Cnt from encoder (not convert to RPM), save in array, after 10 sec, send array to PC...
how can I create array with 1000 members, each with max 4 digit dec number?
also how to send that array via UART?
int RPM[1000];
int RPMindex=0;
void Timer0A_interrupt() iv IVT_INT_TIMER0A_16_32_bit {
TIMER_ICR_TATOCINT_bit = 1;
// store data in array until it is full
if(RMPindex<1000) RPM[RPMindex++] = 6*Cnt; // Speed in RPM
Cnt = 0;
DsplyCnt++;
}
int mian(void)
{
...
while(1)
{
// if array is full transmit data
if(RPMindex == 1000)
{
for(i=0;i < 1000; i++)
{
IntToStr(RPM[i], Txt); // Convert to string
UARTprintString(Txt); // transmit the string
}
RPMindex=0; // reset array index
}
}
}
while(1){
while(ENCODER == 0); // wait if 0
Cnt++; // Inc ENCODER
while(ENCODER == 1); // wait if 1
}
try putting them togetherHorace, in while (1) I have Cnt procedure
Code:while(1){ while(ENKODER == 0); // cekaj ako e 0 Cnt++; // Zgolemi ENKODER while(ENKODER == 1); // cekaj ako e 1 }
Your advice for "if array is full" is also in while(1), I will have a problem if I put together?
sbit ENKODER at GPIO_PORTH_DATA.B0; //encoder PH0
unsigned int Cnt = 0;
unsigned char Txt[4];
int RPM[1000];
int RPMindex = 0;
int i = 0;
void Timer0A_interrupt() iv IVT_INT_TIMER0A_16_32_bit { //interapt
TIMER_ICR_TATOCINT_bit = 1;
if(RPMindex < 1000) RPM[RPMindex++] = 6*Cnt; // Speed in RPM
Cnt = 0;
}
void main(){
UART0_Init(57600);
GPIO_Digital_Input(&GPIO_PORTH, _GPIO_PINMASK_0); //PH0 digital inpui
GPIO_Digital_Output(&GPIO_PORTG, _GPIO_PINMASK_4); //PG4 digital output
GPIO_PORTG_DATA.B4 = 1; //motor drive
SYSCTL_RCGC1_TIMER0_bit = 1; //
EnableInterrupts(); //
TIMER_CTL_TAEN_bit = 0; //
TIMER0_CFG = 0; //
TIMER0_TAMR |= 2; //
TIMER0_TAILR = Get_Fosc_kHz()*100; // interval 100ms
NVIC_IntEnable(IVT_INT_TIMER0A_16_32_bit); // Enable tajmer interapt
TIMER_IMR_TATOIM_bit = 1; // Enable time-out timer A interrupt
TIMER_CTL_TAEN_bit = 1; // Enable timer A
while(1){
// if array is full transmit data
if(RPMindex == 1000){
for(i = 0; i < 1000; i++){
IntToStr(RPM[i], Txt); // Convert to string
UART_Write_Text(Txt); // transmit the string
}
RPMindex = 0; // reset array index
}
while(ENKODER == 0); // wait if 0
Cnt++; // Inc ENCODER
while(ENKODER == 1); // wait if 1
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?