Lower clock to 48 Mhz and add thermistor averaging
This commit is contained in:
parent
be01d51eff
commit
693076e37e
|
@ -1 +1 @@
|
|||
220
|
||||
233
|
||||
|
|
|
@ -40,11 +40,12 @@ static void InitStepper(void)
|
|||
| (0x01 << (4 * PIN_STEPPER_BP - 32)) // Output, max. 10 MHz
|
||||
;
|
||||
|
||||
TIM3->PSC = 72000000 / 100 / LTP1245_MAX_DRIVE_FREQ - 1;
|
||||
TIM3->PSC = 48000000 / 100 / LTP1245_MAX_DRIVE_FREQ - 1;
|
||||
TIM3->ARR = 100;
|
||||
TIM3->DIER = TIM_DIER_UIE;
|
||||
TIM3->CR1 = TIM_CR1_CEN;
|
||||
|
||||
NVIC_SetPriority(TIM3_IRQn, 1);
|
||||
NVIC_EnableIRQ(TIM3_IRQn);
|
||||
}
|
||||
|
||||
|
@ -71,7 +72,7 @@ static void InitDataLines(void)
|
|||
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
||||
RCC->AHBENR |= RCC_AHBENR_DMA1EN;
|
||||
|
||||
TIM2->PSC = 720 - 1; // Each tick corresponds to ten microseconds
|
||||
TIM2->PSC = 480 - 1; // Each tick corresponds to ten microseconds
|
||||
TIM2->ARR = 201; // 2 milliseconds
|
||||
TIM2->CCR3 = 1;
|
||||
TIM2->CCR4 = 1;
|
||||
|
@ -129,9 +130,11 @@ static void InitThermistor(void)
|
|||
|
||||
// Enable EOC interrupt
|
||||
ADC1->CR1 = ADC_CR1_EOCIE;
|
||||
NVIC_SetPriority(ADC1_2_IRQn, 7);
|
||||
NVIC_EnableIRQ(ADC1_2_IRQn);
|
||||
|
||||
// The thermistor is connected to ADC12_IN8 (PB0)
|
||||
ADC1->SQR1 = 0;
|
||||
ADC1->SQR3 = (8 << ADC_SQR3_SQ1_Pos);
|
||||
ADC1->SMPR2 = (7 << ADC_SMPR2_SMP8_Pos);
|
||||
|
||||
|
@ -151,7 +154,7 @@ static void InitCutter(void)
|
|||
;
|
||||
|
||||
// Servo pulse length should be between 1 and 2 ms with a period of 20 ms
|
||||
TIM4->PSC = 72 - 1; // Divide to one microsecond
|
||||
TIM4->PSC = 48 - 1; // Divide to one microsecond
|
||||
TIM4->ARR = 20000; // 50 Hz frequency
|
||||
TIM4->CCR2 = 1000; // 1 millisecond
|
||||
TIM4->CCMR1 = TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1;
|
||||
|
@ -428,6 +431,14 @@ void TIM3_IRQHandler(void)
|
|||
}
|
||||
|
||||
void ADC1_2_IRQHandler(void)
|
||||
{
|
||||
static unsigned average = 0;
|
||||
static int average_counter = 0;
|
||||
|
||||
average += ADC1->DR;
|
||||
average_counter++;
|
||||
|
||||
if(average_counter == 16)
|
||||
{
|
||||
const int READINGS[] =
|
||||
{
|
||||
|
@ -462,7 +473,7 @@ void ADC1_2_IRQHandler(void)
|
|||
4095.0 * (1.0 - LTP1245_TH_REXT / (LTP1245_TH_REXT + 1.47)) // 100 °C
|
||||
};
|
||||
|
||||
int adc = ADC1->DR;
|
||||
int adc = average / 16;
|
||||
|
||||
// Find first temperature higher than the measured one
|
||||
int lower_entry = 0;
|
||||
|
@ -488,6 +499,10 @@ void ADC1_2_IRQHandler(void)
|
|||
// a pulse with in microseconds
|
||||
PulseWidth = (285 * 178 - (int)(1000 * 178 * 0.003135) * (temp - 25))
|
||||
/ (int)((5 * 1.4 - 2.9) * (5 * 1.4 - 2.9));
|
||||
|
||||
average_counter = 0;
|
||||
average = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TIM4_IRQHandler(void)
|
||||
|
|
|
@ -12,8 +12,8 @@ void SystemInit(void)
|
|||
|
||||
FLASH->ACR |= FLASH_ACR_LATENCY_1;
|
||||
|
||||
// Set PLL to x9 (-> 72MHz system clock)
|
||||
RCC->CFGR |= RCC_CFGR_PLLMULL9 | RCC_CFGR_PLLSRC | RCC_CFGR_PPRE1_2;
|
||||
// Set PLL to x6 (-> 48MHz system clock)
|
||||
RCC->CFGR |= RCC_CFGR_PLLMULL6 | RCC_CFGR_PLLSRC | RCC_CFGR_PPRE1_2;
|
||||
|
||||
// Activate PLL and wait
|
||||
RCC->CR |= RCC_CR_PLLON;
|
||||
|
|
Loading…
Reference in a new issue