Changed the `load.h` and `load.c` files for better documentation and differnt threshold values.
This commit is contained in:
parent
ea7341d6c8
commit
0287c67281
|
@ -22,21 +22,23 @@
|
||||||
#include "MockRegEdit.h"
|
#include "MockRegEdit.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//These two arrays allow us to track the A and B ports to know when
|
//These two arrays allow us to track the A and B ports to know when
|
||||||
//one has been disabled before.
|
//one has been disabled before.
|
||||||
static bool porta_disabled[8] = {0};
|
static bool porta_disabled[8] = {0};
|
||||||
static bool portb_disabled[8] = {0};
|
static bool portb_disabled[8] = {0};
|
||||||
|
|
||||||
|
|
||||||
static bool valid_load(uint16_t val)
|
static bool valid_load(uint16_t val)
|
||||||
{
|
{
|
||||||
if(val > 527 && val < 1000) {
|
if(val > LOWTHRESH && val < HIGHTHRESH) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint16_t sample_adc(uint8_t adc_pin)
|
||||||
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
|
||||||
{
|
{
|
||||||
ADC_Init(adc_pin);
|
ADC_Init(adc_pin);
|
||||||
ADC_Enable();
|
ADC_Enable();
|
||||||
|
@ -44,6 +46,13 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||||
uint16_t val = ADC_ReadValue(adc_pin);
|
uint16_t val = ADC_ReadValue(adc_pin);
|
||||||
|
|
||||||
ADC_Disable();
|
ADC_Disable();
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||||
|
{
|
||||||
|
uint16_t val = sample_adc(adc_pin);
|
||||||
|
|
||||||
if(valid_load(val) && !porta_disabled[adc_pin]){
|
if(valid_load(val) && !porta_disabled[adc_pin]){
|
||||||
RegEdit_SetBit((void *) &PORTA.DIR, out_pin);
|
RegEdit_SetBit((void *) &PORTA.DIR, out_pin);
|
||||||
RegEdit_SetBit((void *) &PORTA.OUT, out_pin);
|
RegEdit_SetBit((void *) &PORTA.OUT, out_pin);
|
||||||
|
@ -56,12 +65,8 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||||
|
|
||||||
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
||||||
{
|
{
|
||||||
ADC_Init(adc_pin);
|
uint16_t val = sample_adc(adc_pin);
|
||||||
ADC_Enable();
|
|
||||||
ADC_SetPin(adc_pin);
|
|
||||||
uint16_t val = ADC_ReadValue(adc_pin);
|
|
||||||
|
|
||||||
ADC_Disable();
|
|
||||||
if(valid_load(val) && !portb_disabled[adc_pin]){
|
if(valid_load(val) && !portb_disabled[adc_pin]){
|
||||||
RegEdit_SetBit((void *) &PORTB.DIR, out_pin);
|
RegEdit_SetBit((void *) &PORTB.DIR, out_pin);
|
||||||
RegEdit_SetBit((void *) &PORTB.OUT, out_pin);
|
RegEdit_SetBit((void *) &PORTB.OUT, out_pin);
|
||||||
|
@ -71,3 +76,11 @@ void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
||||||
portb_disabled[adc_pin] = true;
|
portb_disabled[adc_pin] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Load_SoftResetDisabledLoads()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 8; i++){
|
||||||
|
porta_disabled[i] = false;
|
||||||
|
portb_disabled[i] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,23 +10,45 @@
|
||||||
#ifndef LOAD_H
|
#ifndef LOAD_H
|
||||||
#define LOAD_H
|
#define LOAD_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Low Threshold
|
* @brief Low Threshold
|
||||||
*
|
* Anything below or equal to the value will cause the pin to lock into the disabled
|
||||||
|
* state.
|
||||||
*/
|
*/
|
||||||
#define LOWTHRESH 527
|
#define LOWTHRESH 517
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief High Threshold
|
* @brief High Threshold
|
||||||
*
|
* Anything equal or above the value will cause the pin to lock into the disabled
|
||||||
|
* state.
|
||||||
*/
|
*/
|
||||||
#define HIGHTHRESH 1000
|
#define HIGHTHRESH 830
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the adc pin is inbetween LOWTHRESH and HIGHTHRESH and then
|
||||||
|
* sets or disables the output pin on PORTA.
|
||||||
|
* @param adc_pin the pin number that the load value is read from.
|
||||||
|
* @param out_pin The pin that is set high if the adc_pin input is valid.
|
||||||
|
*/
|
||||||
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin);
|
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the adc pin is inbetween LOWTHRESH and HIGHTHRESH and then
|
||||||
|
* sets or disables the output pin on PORTB.
|
||||||
|
* @param adc_pin the pin number that the load value is read from.
|
||||||
|
* @param out_pin The pin that is set high if the adc_pin input is valid.
|
||||||
|
*/
|
||||||
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin);
|
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin);
|
||||||
|
|
||||||
void Load_HandlePinLoads(void);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resets the disabled array state.
|
||||||
|
*/
|
||||||
|
void Load_SoftResetDisabledLoads(void);
|
||||||
|
|
||||||
#endif /* LOAD_H */
|
#endif /* LOAD_H */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue