Timer test
This commit is contained in:
@@ -1,6 +1,26 @@
|
||||
#include <cstdio>
|
||||
#include "SHAL.h"
|
||||
|
||||
#define SER PIN(B10)
|
||||
#define RCLK PIN(B9)
|
||||
#define SRCLK PIN(B8)
|
||||
|
||||
void scanOutputs(uint8_t num_outputs) {
|
||||
|
||||
for (size_t i = 0; i < num_outputs + 1; i++) {
|
||||
if (i == 0) {
|
||||
SER.setHigh();
|
||||
}
|
||||
else {
|
||||
SER.setLow();
|
||||
}
|
||||
RCLK.setHigh();
|
||||
SRCLK.setHigh();
|
||||
RCLK.setLow();
|
||||
SRCLK.setLow();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
SHAL_init();
|
||||
@@ -9,11 +29,41 @@ int main() {
|
||||
|
||||
PIN(A8).setAlternateFunction(GPIO_Alternate_Function::AF2);
|
||||
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
||||
RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
|
||||
|
||||
SER.setPinMode(PinMode::OUTPUT_MODE);
|
||||
RCLK.setPinMode(PinMode::OUTPUT_MODE);
|
||||
SRCLK.setPinMode(PinMode::OUTPUT_MODE);
|
||||
|
||||
SHAL_TIM1.init(48,100);
|
||||
SHAL_TIM1.setOutputCompareMode(SHAL_Timer_Channel::CH1,SHAL_TIM_Output_Compare_Mode::PWMMode1);
|
||||
SHAL_TIM1.enableChannel(SHAL_Timer_Channel::CH1,SHAL_Timer_Channel_Main_Output_Mode::Polarity_Reversed,SHAL_Timer_Channel_Complimentary_Output_Mode::Disabled);
|
||||
SHAL_TIM1.setCaptureCompareValue(SHAL_Timer_Channel::CH1, 5);
|
||||
SHAL_TIM1.configurePWM(SHAL_Timer_Channel::CH1, 4800, 100, 20);
|
||||
SHAL_TIM1.start();
|
||||
|
||||
SER.setLow();
|
||||
RCLK.setLow();
|
||||
SRCLK.setLow();
|
||||
|
||||
uint8_t numDisplays = 6;
|
||||
uint8_t count = 0;
|
||||
|
||||
while (true) {
|
||||
|
||||
if (count == 0) {
|
||||
SER.setLow();
|
||||
}
|
||||
else {
|
||||
SER.setHigh();
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
RCLK.setHigh();
|
||||
SRCLK.setHigh();
|
||||
RCLK.setLow();
|
||||
SRCLK.setLow();
|
||||
if (count == numDisplays) {
|
||||
count = 0;
|
||||
}
|
||||
SHAL_delay_us(50);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user