added counter compare value to timerInitOutputCompare() + timerSetCounterCompareValue() + typos and doku

interrupts
polymurph 4 years ago
parent 56d8e45a99
commit 4f74617700

@ -130,6 +130,15 @@ void timerClearCounter(timerNo_t timer);
/* Second stage configuration */ /* Second stage configuration */
/*!
* @brief Initializes the counter of the timer
*
* @param timer The desired timer
* @param prescaler the prescaler value for the counter clock
* @param autoReload The autoreload value for the counter
* @param direction The counter direction
*
*/
void timerInitCounter( timerNo_t timer, void timerInitCounter( timerNo_t timer,
uint32_t prescaler, uint32_t prescaler,
uint32_t autoReload, uint32_t autoReload,
@ -154,14 +163,28 @@ void timerInitPwm( timerNo_t timer,
* @param timerIoChannel The internal Timer Capture compare channel to be used. * @param timerIoChannel The internal Timer Capture compare channel to be used.
* @param pinNo The desired Pin Number to be used as outpujt * @param pinNo The desired Pin Number to be used as outpujt
* @param altFuntion The Alternate funtion No for the given Pin * @param altFuntion The Alternate funtion No for the given Pin
* @param polarity Sets the <F2> the given Pin * @param polarity Sets the the given Pin
* @param ccValue Capture Compare Value
*/ */
void timerInitOutputCompare( timerNo_t timer, void timerInitOutputCompare( timerNo_t timer,
timerOutputCompareMode_t mode, timerOutputCompareMode_t mode,
uint8_t timerIoChannel, uint8_t timerIoChannel,
pinNo_t pinNo, pinNo_t pinNo,
uint16_t altFunction, uint16_t altFunction,
uint8_t polarity); uint8_t polarity,
uint32_t ccValue);
/*!
* @brief Sets the counter compare calue of the desired timer io channel
*
* @param timer The desired timer number
* @param timerIoChannel The internal Timer Capture compare channel to be used.
* @param ccValue Capture Compare Value
*/
void timerSetCounterCompareValue(timerNo_t timer,
uint8_t timerIoChannel,
uint32_t ccValue);
/*! /*!
* @brief Set the outoreload value of the timer * @brief Set the outoreload value of the timer
* *

@ -106,12 +106,16 @@ void timerInitOutputCompare( timerNo_t timer,
uint8_t timerIoChannel, uint8_t timerIoChannel,
pinNo_t pinNo, pinNo_t pinNo,
uint16_t altFunction, uint16_t altFunction,
uint8_t polarity) uint8_t polarity,
uint32_t ccValue)
{ {
timerStop(timer); timerStop(timer);
pinSetMode(pinNo,alternate); pinSetMode(pinNo,alternate);
pinSetAlternate(pinNo,altFunction); pinSetAlternate(pinNo,altFunction);
// TODO: check for value existing register size
//if(ccValue)
// timerThrowError(timerError_t error)
switch(timerIoChannel) switch(timerIoChannel)
{ {
case 1: case 1:
@ -120,6 +124,7 @@ void timerInitOutputCompare( timerNo_t timer,
BASE->CCER |= TIM_CCER_CC1E; BASE->CCER |= TIM_CCER_CC1E;
BASE->CCER |= (1&&polarity) << TIM_CCER_CC1P_Pos; BASE->CCER |= (1&&polarity) << TIM_CCER_CC1P_Pos;
BASE->CCER &= ~TIM_CCER_CC1NP; BASE->CCER &= ~TIM_CCER_CC1NP;
BASE->CCR1 = (uint16_t)ccValue;
break; break;
case 2: case 2:
BASE->CCMR1 &= ~TIM_CCMR1_OC2M; BASE->CCMR1 &= ~TIM_CCMR1_OC2M;
@ -127,6 +132,7 @@ void timerInitOutputCompare( timerNo_t timer,
BASE->CCER |= TIM_CCER_CC2E; BASE->CCER |= TIM_CCER_CC2E;
BASE->CCER |= (1&&polarity) << TIM_CCER_CC2P_Pos; BASE->CCER |= (1&&polarity) << TIM_CCER_CC2P_Pos;
BASE->CCER &= ~TIM_CCER_CC2NP; BASE->CCER &= ~TIM_CCER_CC2NP;
BASE->CCR2 = (uint16_t)ccValue;
break; break;
case 3: case 3:
BASE->CCMR2 &= ~TIM_CCMR2_OC3M; BASE->CCMR2 &= ~TIM_CCMR2_OC3M;
@ -134,6 +140,7 @@ void timerInitOutputCompare( timerNo_t timer,
BASE->CCER |= TIM_CCER_CC3E; BASE->CCER |= TIM_CCER_CC3E;
BASE->CCER |= (1&&polarity) << TIM_CCER_CC3P_Pos; BASE->CCER |= (1&&polarity) << TIM_CCER_CC3P_Pos;
BASE->CCER &= ~TIM_CCER_CC3NP; BASE->CCER &= ~TIM_CCER_CC3NP;
BASE->CCR3 = (uint16_t)ccValue;
break; break;
case 4: case 4:
BASE->CCMR2 &= ~TIM_CCMR2_OC4M; BASE->CCMR2 &= ~TIM_CCMR2_OC4M;
@ -141,6 +148,30 @@ void timerInitOutputCompare( timerNo_t timer,
BASE->CCER |= TIM_CCER_CC4E; BASE->CCER |= TIM_CCER_CC4E;
BASE->CCER |= (1&&polarity) << TIM_CCER_CC4P_Pos; BASE->CCER |= (1&&polarity) << TIM_CCER_CC4P_Pos;
BASE->CCER &= ~TIM_CCER_CC4NP; BASE->CCER &= ~TIM_CCER_CC4NP;
BASE->CCR4 = (uint16_t)ccValue;
break;
default:
timerThrowError(ccChannelNoOutOfRange);
break;
};
}
void timerSetCounterCompareValue(timerNo_t timer,
uint8_t timerIoChannel,
uint32_t ccValue)
{
switch(timerIoChannel) {
case 1:
BASE->CCR1 = (uint16_t)ccValue;
break;
case 2:
BASE->CCR2 = (uint16_t)ccValue;
break;
case 3:
BASE->CCR3 = (uint16_t)ccValue;
break;
case 4:
BASE->CCR4 = (uint16_t)ccValue;
break; break;
default: default:
timerThrowError(ccChannelNoOutOfRange); timerThrowError(ccChannelNoOutOfRange);

@ -22,16 +22,26 @@ void timer_test(timerNo_t timer, pinNo_t pin)
void timer_capture_compare_test(timerNo_t timer) void timer_capture_compare_test(timerNo_t timer)
{ {
timerInitCounter(timer, 1000, 999, downCounting); uint16_t i = 0;
timerInitCounter(timer, 100, 99, downCounting);
// We use pin PA3 (Arduino header A2) // We use pin PA3 (Arduino header A2)
timerInitOutputCompare(timer, toggle, 4, pinA3, 2,0); //timerInitOutputCompare(timer, toggle, 4, pinA3, 2,0, 300);
timerInitOutputCompare(timer, pwm_normal, 2, pinB3, 2,0, 900);
timerSart(timer); timerSart(timer);
while(1){
delayMs(200);
timerSetCounterCompareValue(timer, 2, i);
i += 10;
if(i>99) i = 0;
}
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
uint8_t i = 0; uint8_t i = 0;
// making array with all available timers
timerNo_t timers[MAX_TIMER_CHANNEL_COUNT] = {timer_1, timer_2, timer_3, timer_14, timer_16, timer_17}; timerNo_t timers[MAX_TIMER_CHANNEL_COUNT] = {timer_1, timer_2, timer_3, timer_14, timer_16, timer_17};
@ -41,7 +51,7 @@ int main(int argc, char *argv[])
pinConfig(pinB3, output, pushPull, def_res, def_speed); pinConfig(pinB3, output, pushPull, def_res, def_speed);
pinConfig(pinA0, input, def_stage, pullDown, def_speed); pinConfig(pinA0, input, def_stage, pullDown, def_speed);
setupInit(); // This is the sescond call of System init the asebly start code is calling it before the main. setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main.
usartInit( usart2, usartInit( usart2,
pinA2, pinA2,
pinA15, pinA15,

Loading…
Cancel
Save