Not applicable
May 29, 2017
11:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 29, 2017
11:30 AM
Hi! I want o understand the following Code. Can you explain me Please? I am new to dave:(
#include //Declarations from DAVE Code Generation (includes SFR declaration)
uint8_t expired;
uint32_t DutyCycle;
XMC_VADC_RESULT_SIZE_t result;
void timer()
{
expired=1;
}
void delay(uint32_t us)
{
uint32_t TimerId;
TimerId = (uint32_t)SYSTIMER_CreateTimer(us,SYSTIMER_MODE_PERIODIC,(void*)timer,NULL);
if (TimerId != 0U)
{
expired=0;
SYSTIMER_StartTimer(TimerId);
while(expired==0)
{}
SYSTIMER_StopTimer(TimerId);
SYSTIMER_DeleteTimer(TimerId);
}
}
int main(void)
{
DAVE_Init();
while(1U)
{
ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);
result = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_0);
if(result >= 2000)
{
//control servo
PWM_SetDutyCycle(&PWM_0,270);
PWM_Start(&PWM_0);
delay(1000000);
PWM_Stop(&PWM_0);
}
else if(result >=1000 && result <= 2000)
{
PWM_SetDutyCycle(&PWM_0,400);
PWM_Start(&PWM_0);
delay(1000000);
PWM_Stop(&PWM_0);
}
else if(result < 1000)
{
PWM_SetDutyCycle(&PWM_0,750);
PWM_Start(&PWM_0);
delay(1000000);
PWM_Stop(&PWM_0);
}
}
}
#include
uint8_t expired;
uint32_t DutyCycle;
XMC_VADC_RESULT_SIZE_t result;
void timer()
{
expired=1;
}
void delay(uint32_t us)
{
uint32_t TimerId;
TimerId = (uint32_t)SYSTIMER_CreateTimer(us,SYSTIMER_MODE_PERIODIC,(void*)timer,NULL);
if (TimerId != 0U)
{
expired=0;
SYSTIMER_StartTimer(TimerId);
while(expired==0)
{}
SYSTIMER_StopTimer(TimerId);
SYSTIMER_DeleteTimer(TimerId);
}
}
int main(void)
{
DAVE_Init();
while(1U)
{
ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);
result = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_0);
if(result >= 2000)
{
//control servo
PWM_SetDutyCycle(&PWM_0,270);
PWM_Start(&PWM_0);
delay(1000000);
PWM_Stop(&PWM_0);
}
else if(result >=1000 && result <= 2000)
{
PWM_SetDutyCycle(&PWM_0,400);
PWM_Start(&PWM_0);
delay(1000000);
PWM_Stop(&PWM_0);
}
else if(result < 1000)
{
PWM_SetDutyCycle(&PWM_0,750);
PWM_Start(&PWM_0);
delay(1000000);
PWM_Stop(&PWM_0);
}
}
}
- Tags:
- IFX
1 Reply
May 30, 2017
07:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 30, 2017
07:42 AM
What exactly is it you don't understand?
To get started, you should read the API documentation of the DAVE Apps you are using:
1. Move your cursor to an ADC_MEASUREMENT_*, PWM_*, or SYSTIMER_* function.
2. Hit [F3].
3. A new editor tab should open and show the declaration of the function with the accompanying docstring.
Another way is to select the app in DAVE's "APP Dependency" view and press [ALT]+[F3].
This fires up Windows' Help viewer showing the App's documentation generated from the docstrings.
HTH
To get started, you should read the API documentation of the DAVE Apps you are using:
1. Move your cursor to an ADC_MEASUREMENT_*, PWM_*, or SYSTIMER_* function.
2. Hit [F3].
3. A new editor tab should open and show the declaration of the function with the accompanying docstring.
Another way is to select the app in DAVE's "APP Dependency" view and press [ALT]+[F3].
This fires up Windows' Help viewer showing the App's documentation generated from the docstrings.
HTH