hello everyone,
I'm working on a simple aplicattion. Where I want to make a PWM vary the dutycicle and print the current dutycicle in the terminal. I based my code on the hetPwm and adcDisplay examples. The code is working fine but I'd like the dutyCicle value to be print as decimal.
here is my code:
/* Include Files */ #include "sys_common.h" /* USER CODE BEGIN (1) */ #include "het.h" #include "sci.h" #define TSIZE1 8 uint8 TEXT1[TSIZE1]= {'\r','\n','|','\t','M','A','I','N'}; #define TSIZE2 14 uint8 TEXT2[TSIZE2]= {'\r','\n','|','\t','L','O','O','P','.','W','H','I','L','E'}; #define TSIZE3 20 uint8 TEXT3[TSIZE3]= {'\r','\n','|','\t','L','O','O','P','.','D','U','T','Y','_','C','I','C','L','E','\t'}; #define TSIZE4 8 uint8 TEXT4[TSIZE4]= {'\r','\n','|','\t','W','A','I','T'}; void setPwm (uint32 dutyCicle, float64 period_us); void sciDisplayText(sciBASE_t *sci, uint8 *text, uint32 length); void sciDisplayData(sciBASE_t *sci, uint8 *text,uint32 length); void wait (uint32 time); /* USER CODE END */ /** @fn void main(void) * @brief Application main function * @note This function is empty by default. * * This function is called after startup. * The user can use this function to implement the application. */ /* USER CODE BEGIN (2) */ uint32 time; uint32 dutyCicle; float64 period_us; uint32 value; /* USER CODE END */ int main(void) { /* USER CODE BEGIN (3) */ sciInit(); sciDisplayText(scilinREG,&TEXT1[0],TSIZE1); hetInit(); dutyCicle = 50; period_us = 100.0; time = 1000.0; setPwm(dutyCicle, period_us); while(1) { sciDisplayText(scilinREG,&TEXT2[0],TSIZE2); dutyCicle=0; value = dutyCicle; while(dutyCicle<=100) { sciDisplayText(scilinREG,&TEXT3[0],TSIZE3); sciDisplayData(scilinREG,(uint8*)&value,4); value = dutyCicle; setPwm(dutyCicle, period_us); // __delay_cycles(50000000); dutyCicle+=5; wait(0xFFFFFF); } pwmStop(hetRAM1,pwm0); sciDisplayText(scilinREG,&TEXT4[0],TSIZE4); wait(0xFFFFFF); } /* USER CODE END */ } /* USER CODE BEGIN (4) */ void setPwm (uint32 dutyCicle, float64 period_us) { hetInit(); hetSIGNAL_t pwmSignal; pwmSignal.duty = dutyCicle; pwmSignal.period = period_us; pwmSetSignal(hetRAM1,pwm0,pwmSignal); pwmSetDuty(hetRAM1,pwm0,pwmSignal.duty); pwmStart(hetRAM1,pwm0); } void sciDisplayText(sciBASE_t *sci, uint8 *text,uint32 length) { while(length--) { while ((scilinREG->FLR & 0x4) == 4); /* wait until busy */ sciSendByte(scilinREG,*text++); /* send out text */ }; } void sciDisplayData(sciBASE_t *sci, uint8 *text,uint32 length) { uint8 txt = 0; uint8 txt1 = 0; #if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1)) text = text + (length -1); #endif while(length--) { #if ((__little_endian__ == 1) || (__LITTLE_ENDIAN__ == 1)) txt = *text--; #else txt = *text++; #endif txt1 = txt; txt &= ~(0xF0); txt1 &= ~(0x0F); txt1 =txt1>>4; if(txt<=0x9) { txt +=0x30; } else if(txt > 0x9 && txt < 0xF) { txt +=0x37; } else { txt = 0x30; } if(txt1 <= 0x9) { txt1 +=0x30; } else if((txt1 > 0x9) && (txt1 <= 0xF)) { txt1 +=0x37; } else { txt1 = 0x30; } while ((scilinREG->FLR & 0x4) == 4); /* wait until busy */ sciSendByte(scilinREG,txt1); /* send out text */ while ((scilinREG->FLR & 0x4) == 4); /* wait until busy */ sciSendByte(scilinREG,txt); /* send out text */ }; } void wait(uint32 time) { while(time)time--; }
My teacher suggested that it could be a terminal configuration. But I tried on three different terminal software, no success.
Any suggestion is welcome.