AMTS/Mieke/SW/MT/ne555.c

67 lines
1.7 KiB
C
Raw Normal View History

2018-04-03 15:32:24 +00:00
/*
Manufacturing tests for the new cortex minimal system
Copyright (C) 2018 Andreas Mieke
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2018-03-18 22:43:59 +00:00
#include "ne555.h"
volatile uint32_t *NE555STick, NE555STickCur;
uint8_t old_state;
void init_ne555(volatile uint32_t *SysTickCnt)
{
2018-04-03 15:18:28 +00:00
// Enable GPIOb clock
2018-03-18 22:43:59 +00:00
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
2018-04-03 15:18:28 +00:00
// Create gpio struct and fill it with default values
2018-03-18 22:43:59 +00:00
GPIO_InitTypeDef gpio;
GPIO_StructInit(&gpio);
2018-04-03 15:18:28 +00:00
// Set PB0 to input floating
2018-03-18 22:43:59 +00:00
gpio.GPIO_Mode = GPIO_Mode_IN_FLOATING;
gpio.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOB, &gpio);
NE555STick = SysTickCnt;
return;
}
void run_ne555(float *freq)
{
uint8_t state;
*freq = 0.0f;
NE555STickCur = *NE555STick;
2018-04-03 15:18:28 +00:00
// Run for one second
2018-03-18 22:43:59 +00:00
while((*NE555STick - NE555STickCur) <= 1000)
{
state = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0);
2018-04-03 15:18:28 +00:00
// If the state changes low -> high or high -> low increment freq and save state
2018-03-18 22:43:59 +00:00
if (state != old_state)
{
(*freq)++;
old_state = state;
}
}
2018-04-03 15:18:28 +00:00
// Divide freq by two to get the frequency
2018-03-18 22:43:59 +00:00
*freq /= 2;
return;
}
void deinit_ne555(void)
{
return;
}