y=expf(x); Why does "x" change and affect "LPC_TMR16B1->TC"?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

y=expf(x); Why does "x" change and affect "LPC_TMR16B1->TC"?

546 Views
Wei_Lang
Contributor II
//  y=expf(x); Why does "x" change and affect "LPC_TMR16B1->TC"?
 
#include <LPC112x.h>
#include "wdt.h"
#include "math.h"
 
volatile uint32_t msTicks;/* counts 10ms timeTicks */
volatile uint32_t jishuzhi=0;/* 计数值 */
int32_t clk[12]={0};
int32_t mV0,mV50,mV100,t14,t750;
float c_o2,vo2,tt;
float vo2b,k82,k0,k_299,vt,outmA;
 
/*----------------------------------------------------------------------------
  SysTick_Handler
#define __SYSTEM_CLOCK  (__MAIN_CLOCK / SYSAHBCLKDIV_Val)
__XTAL_CLK * 4  (__MAIN_CLOCK / 1)
#define __MAIN_CLOCK    (__SYS_PLLCLKOUT)
#define __SYS_PLLCLKOUT (__SYS_PLLCLKIN * ((SYSPLLCTRL_Val & 0x01F) + 1))
(__SYS_PLLCLKIN * (3+1))
#define __SYS_PLLCLKIN  (__SYS_OSC_CLK)
#define __SYS_OSC_CLK   (   __XTAL_CLK)=11059200
 *----------------------------------------------------------------------------*/
void SysTick_Handler(void) {
  msTicks++;
}
/*****************************************************
**函数名称:TIMER16_1_IRQHandler()
**函数功能:定时/计数器1中断服务程序
******************************************************/
void TIMER16_1_IRQHandler(void)//UART1
{
LPC_TMR16B1->IR=(1UL << 5);
}
void CT16B1_Initialize(void)
{
LPC_IOCON->PIO3_5 = 0xD1;//PIO3_5 CT16B1_CAP1
LPC_SYSCON->SYSAHBCLKCTRL |= (1UL << 8);/* enable clock for CT16B1 */
 
LPC_TMR16B1->IR=(1UL << 5);
LPC_TMR16B1->TCR=3;//Enable and Reset
LPC_TMR16B1->PR=0;//4x11059200不分频
LPC_TMR16B1->CCR = 0;//((1UL << 3) | (1UL << 5));//Interrupt on CT16Bn_CAP1 event
LPC_TMR16B1->CTCR=5;//计数器,上升沿,CT16B1_CAP1
LPC_TMR16B1->TCR=1;//Enable and Go
 
NVIC_EnableIRQ(17);
}
/*----------------------------------------------------------------------------
  delays number of tick Systicks (1-250 ms)
 *----------------------------------------------------------------------------*/
void Delay (uint32_t dlyTicks) {
  uint32_t curTicks;
 
  curTicks = msTicks;
  while ((msTicks - curTicks) < dlyTicks) { __NOP(); }
}
/*----------------------------------------------------------------------------
  delays number of tick Systicks (3276800约1.195s)
 *----------------------------------------------------------------------------*/
void Delay1 (uint32_t dlyTicks) {
  for(;dlyTicks > 0;dlyTicks--) { __NOP(); }
}
 
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {
__disable_irq();
k0=0.0;
  SystemCoreClockUpdate();                      /* Get Core Clock Frequency   */
msTicks=0;
  if (SysTick_Config(SystemCoreClock / 800)) {  /* SysTick 1/800 s interrupts */
    while (1) __NOP();                          /* Capture error               */
  }
Delay1 (400);
Wdt_Initialize();
CT16B1_Initialize();
msTicks=0;
__enable_irq();
 
  while(1) {
if(msTicks>=200) {
msTicks=0;
clk[0]=LPC_TMR16B1->TC;//PIO3_5 CT16B1_CAP1
LPC_TMR16B1->TCR=3;
Delay1 (4);
LPC_TMR16B1->TCR=1;
 
c_o2=expf(k0);
if((k0>=-6.0 && k0<-5.0) || (k0>=2.5 && k0<3.5)) k0+=0.1;
else if(k0==-5.0) k0=2.5;
else if(k0==3.5) k0=-6.0;
else k0=-6.0;
Wdt_Feed();
}
}
}
Labels (1)
Tags (1)
0 Kudos
Reply
2 Replies

517 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @Wei_Lang 

Do you mean that the variation of LPC_TMR16B1->TC is determined by the number of rising edges of the external input to PIO3_5 pin?

BR

Harry

0 Kudos
Reply

504 Views
Wei_Lang
Contributor II

Thank you for your reply!

1. PIO3_5 CT16B1_CAP1

void CT16B1_Initialize(void)
{
LPC_IOCON->PIO3_5 = 0xD1;//PIO3_5 CT16B1_CAP1
LPC_SYSCON->SYSAHBCLKCTRL |= (1UL << 8);/* enable clock for CT16B1 */
LPC_TMR16B1->IR=(1UL << 5);
LPC_TMR16B1->TCR=3;//Enable and Reset
LPC_TMR16B1->PR=0;//4x11059200不分频
LPC_TMR16B1->CCR = 0;//((1UL << 3) | (1UL << 5));//Interrupt on CT16Bn_CAP1 event
LPC_TMR16B1->CTCR=5;//计数器,上升沿,CT16B1_CAP1
LPC_TMR16B1->TCR=1;//Enable and Go
NVIC_EnableIRQ(17);
}

//It has the problem

 

2. PIO3_5 GPIO3_5  EINT3

void EINT3_Initialize()
{
LPC_IOCON->PIO3_5 = 0xD0;//GPIO3_5 Pull-up resistor enabled
LPC_SYSCON->SYSAHBCLKCTRL |= (1UL << 6);     /* enable clock for GPIO      */
LPC_GPIO3->DIR  &= ~(1UL << 5);
LPC_GPIO3->IS   &= ~(1UL << 5);
LPC_GPIO3->IBE  &=~(1UL << 5);
LPC_GPIO3->IEV  &= ~(1UL << 5);
LPC_GPIO3->IE   |=  (1UL << 5);
LPC_GPIO3->IC   |=  (1UL << 5);
NVIC_EnableIRQ(28);
// NVIC_SetPriority (19, 2);  /* set Priority for Systick Interrupt */
}
//It also has the problem.
 
3.
After I changed
     "LPC_GPIO3->IBE  &=~(1UL << 5);"   in 2
to "LPC_GPIO3->IBE |= (1UL << 5);",
it looked fine, but I don't understand why.

 

0 Kudos
Reply