C 언어의 모듈러스 산술에 문제가 있습니다. 이 1ms마다 증가하는 전역 변수 uint16_t Tmr_1ms를 정의했습니다. 제가 에서 발진 상태는 아래 구조 여기C 언어의 모듈로 산법
// oscillator state (oscillator with fixed duty cycle)
typedef struct{
float period; // period of the oscillations (ms)
float T; // function execution period (ms)
BOOL start; // oscillator start signal (start==TRUE, stop==FALSE)
BOOL init; // initiate the oscillator state
float delta; // time after which expiration the oscillator output is negated
float start_time; // captured Tmr_1ms value
}Osc_t;
인스턴스에 저장
void OSC(uint32_t output, Osc_t *p){
float act_time;
if(p->start){
taskENTER_CRITICAL();
act_time = Tmr_1ms;
taskEXIT_CRITICAL();
if(p->init){
SetLogicSignal(output);
p->start_time = act_time;
p->delta = ((p->period)/(2*p->T));
p->init = FALSE;
}
if(((uint16_t)act_time - (uint16_t)(p->start_time)) >= ((uint16_t)(p->delta))){
NegLogicSignal(output); // my defined function for negation of a bit variable
p->start_time = act_time;
}
}else{
ClearLogicSignal(output);
p->init = TRUE;
}
}
함수 주어진 아래에 실현 된 소프트웨어 발진기 구현이 변수를 사용하고자하면 코드
// oscillator instance init
Test_Oscillator_state.T = 20;
Test_Oscillator_state.period = 1000;
Test_Oscillator_state.init = TRUE;
// calling the function
Test_Oscillator_state.start = TRUE;
OSC(LTestBlink, &Test_Oscillator_state);
문제는 다음 코드에
if(((uint16_t)act_time - (uint16_t)(p->start_time)) >= ((uint16_t)(p->delta))){
NegLogicSignal(output);
p->start_time = act_time;
}
출력 부정은 Tmr_1ms 오버 플로우 전에 만 기능합니다. 나는 왜 그런지 이해하지 못한다. 아무도 내게 어떤 안내를 줄 수 있습니까? 미리 감사드립니다.
[mcve]를 입력하고 [ask [. "funcional"이란 무엇을 의미합니까? Negation 연산자는 없으며 NegLogicSignal은 표준 함수가 아닙니다. 디버거 사용법을 익히십시오. – Olaf
코드에 모듈러스 연산자가 없으므로 어떤 모듈러스 산술 연산에 문제가 있는지 확실하지 않습니까? –
귀하의 질문/문제가 무엇인지 전혀 확신하지 못합니다. Tmr_1ms가 돌아 가면 다시 "if"문으로 들어가서 "NegLogicSignal (output)"을 호출하지 않는다는 것을 의미합니까? – Basya