написал програму для моргания светодиодом,включение и выключение его по кнопке
теперь хочу разобраться с АЦП,на плате имеется потенциометр,вот хочу сделать чтобы в зависимости от напряжения светодиод моргал по разному
вместе с платой была библиотека на потенциометр с настройкой АЦП портов и остального(она вроде смнимает значения один раз,но не суть)
проблема в том, что когда я в зависимости от напряжения делаю режим моргания светодиодом,то он просто загорается и горит,и не выключается даже хотя должен
Код
#include "inc/lm3s9b96.h"
#include "boards/dk-lm3s9b96/drivers/thumbwheel.c"
#include "boards/dk-lm3s9b96/drivers/thumbwheel.h"
volatile tBoolean g_bSampleRead = false;
unsigned short g_usThumbwheelmV = 0;
volatile unsigned long ulLoop;
//
// Application callback function which will be informed on the thumbwheel
// potentiometer voltage when a new sample is available. The parameter
// passed is scaled in millivolts.
//
void AppThumbwheelCallback(unsigned short usVoltagemV)
{
//
// Remember the voltage we were passed and signal the main loop that
// the thumbwheen has been read.
//
g_usThumbwheelmV = usVoltagemV;
g_bSampleRead = true;
}
void morg()
{
GPIO_PORTF_DATA_R |= 0x08;
for(ulLoop = 0; ulLoop < 20; ulLoop++);
GPIO_PORTF_DATA_R &= ~(0x08);
}
main(void)
{
//ob'yavlenie peremennoi zaderjki,inicializaciya portov
//PortF pin3-LED,PortJ pin7-switch button
volatile unsigned long ulLoop;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;
ulLoop = SYSCTL_RCGC2_R;
GPIO_PORTF_DIR_R = 0x08;
GPIO_PORTF_DEN_R = 0x08;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOJ;
ulLoop = SYSCTL_RCGC2_R;
GPIO_PORTJ_DEN_R = 0x80;
//
// Initialize the thumbwheel driver and provide it our callback
//
ThumbwheelInit();
ThumbwheelCallbackSet(AppThumbwheelCallback);
morg();
//
// Request a sample from the thumbwheel.
//
ThumbwheelTrigger();
//
// Wait until the sample is available.
//
while(!g_bSampleRead)
{
//
// Do something with the result.
//
ThumbwheelIntHandler();//этой строки в ихнем коде не было,но я думаю она нужна иначе как преобразовать значение в напряжение
if ( g_usThumbwheelmV > 1500 )
{
//morg();
//GPIO_PORTF_DATA_R &= ~(0x08);
}
else
{
morg();
GPIO_PORTF_DATA_R &= ~(0x08);
}
}
}
#include "boards/dk-lm3s9b96/drivers/thumbwheel.c"
#include "boards/dk-lm3s9b96/drivers/thumbwheel.h"
volatile tBoolean g_bSampleRead = false;
unsigned short g_usThumbwheelmV = 0;
volatile unsigned long ulLoop;
//
// Application callback function which will be informed on the thumbwheel
// potentiometer voltage when a new sample is available. The parameter
// passed is scaled in millivolts.
//
void AppThumbwheelCallback(unsigned short usVoltagemV)
{
//
// Remember the voltage we were passed and signal the main loop that
// the thumbwheen has been read.
//
g_usThumbwheelmV = usVoltagemV;
g_bSampleRead = true;
}
void morg()
{
GPIO_PORTF_DATA_R |= 0x08;
for(ulLoop = 0; ulLoop < 20; ulLoop++);
GPIO_PORTF_DATA_R &= ~(0x08);
}
main(void)
{
//ob'yavlenie peremennoi zaderjki,inicializaciya portov
//PortF pin3-LED,PortJ pin7-switch button
volatile unsigned long ulLoop;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;
ulLoop = SYSCTL_RCGC2_R;
GPIO_PORTF_DIR_R = 0x08;
GPIO_PORTF_DEN_R = 0x08;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOJ;
ulLoop = SYSCTL_RCGC2_R;
GPIO_PORTJ_DEN_R = 0x80;
//
// Initialize the thumbwheel driver and provide it our callback
//
ThumbwheelInit();
ThumbwheelCallbackSet(AppThumbwheelCallback);
morg();
//
// Request a sample from the thumbwheel.
//
ThumbwheelTrigger();
//
// Wait until the sample is available.
//
while(!g_bSampleRead)
{
//
// Do something with the result.
//
ThumbwheelIntHandler();//этой строки в ихнем коде не было,но я думаю она нужна иначе как преобразовать значение в напряжение
if ( g_usThumbwheelmV > 1500 )
{
//morg();
//GPIO_PORTF_DATA_R &= ~(0x08);
}
else
{
morg();
GPIO_PORTF_DATA_R &= ~(0x08);
}
}
}
ну и кручу я потенциометр,жму ресет на плате,светодиод если значение меньше 1500 начниает светится но не выключается(ну и то не всегда)
вот код ихней билиотеки
Код
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_adc.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
//*****************************************************************************
//
//! \addtogroup thumbwheel_api
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
// A pointer to the function to receive messages from the touch screen driver
// when events occur on the touch screen (debounced presses, movement while
// pressed, and debounced releases).
//
//*****************************************************************************
static void (*g_pfnThumbHandler)(unsigned short usThumbwheelmV);
//*****************************************************************************
//
// Handles the ADC interrupt for the thumbwheel.
//
// This function is called when the ADC sequence that samples the thumbwheel
// potentiometer has completed its acquisition.
//
// \return None.
//
//*****************************************************************************
void
ThumbwheelIntHandler(void)
{
unsigned short ulVoltage;
unsigned short usPotValue;
//
// Clear the ADC sample sequence interrupt.
//
HWREG(ADC0_BASE + ADC_O_ISC) = 1 << 2;
//
// Read the raw ADC value.
//
usPotValue = (unsigned short)HWREG(ADC0_BASE + ADC_O_SSFIFO2);
//
// Convert to millivolts.
//
ulVoltage = ((unsigned long)usPotValue * 3000) / 1024;
//
// Call the owner with the new value.
//
if(g_pfnThumbHandler)
{
g_pfnThumbHandler((unsigned short)ulVoltage);
}
}
//*****************************************************************************
//
//! Initializes the ADC to read the thumbwheel potentiometer.
//!
//! This function configures ADC sequence 2 to sample the thumbwheel
//! potentiometer under processor trigger control.
//!
//! \return None.
//
//*****************************************************************************
void
ThumbwheelInit(void)
{
//
// Enable the peripherals used by the touch screen interface.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//
// Configure the pin which the thumbwheel is attached to.
//
GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);
//
// Configure the ADC sample sequence used to read the thumbwheel
//
ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 2, 0,
ADC_CTL_CH10 | ADC_CTL_END | ADC_CTL_IE);
ADCSequenceEnable(ADC0_BASE, 2);
//
// Enable the ADC sample sequence interrupt.
//
ADCIntEnable(ADC0_BASE, 2);
IntEnable(INT_ADC0SS2);
}
//*****************************************************************************
//
//! Triggers the ADC to capture a single sample from the thumbwheel.
//!
//! This function triggers the ADC and starts the process of capturing a single
//! sample from the thumbwheel potentiometer. Once the sample is available,
//! the user-supplied callback function, provided via a call to
//! ThumbwheelCallbackSet{}, will be called with the result.
//!
//! \return None.
//
//*****************************************************************************
void
ThumbwheelTrigger(void)
{
ADCProcessorTrigger(ADC0_BASE, 2);
}
//*****************************************************************************
//
//! Sets the function that will be called when the thumbwheel has been sampled.
//!
//! \param pfnCallback is a pointer to the function to be called when
//! a thumbwheel sample is available.
//!
//! This function sets the address of the function to be called when a new
//! thumbwheel sample is available
//!
//! \return None.
//
//*****************************************************************************
void
ThumbwheelCallbackSet(void (*pfnCallback)(unsigned short usThumbwheelmV))
{
//
// Save the pointer to the callback function.
//
g_pfnThumbHandler = pfnCallback;
}
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_adc.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
//*****************************************************************************
//
//! \addtogroup thumbwheel_api
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
// A pointer to the function to receive messages from the touch screen driver
// when events occur on the touch screen (debounced presses, movement while
// pressed, and debounced releases).
//
//*****************************************************************************
static void (*g_pfnThumbHandler)(unsigned short usThumbwheelmV);
//*****************************************************************************
//
// Handles the ADC interrupt for the thumbwheel.
//
// This function is called when the ADC sequence that samples the thumbwheel
// potentiometer has completed its acquisition.
//
// \return None.
//
//*****************************************************************************
void
ThumbwheelIntHandler(void)
{
unsigned short ulVoltage;
unsigned short usPotValue;
//
// Clear the ADC sample sequence interrupt.
//
HWREG(ADC0_BASE + ADC_O_ISC) = 1 << 2;
//
// Read the raw ADC value.
//
usPotValue = (unsigned short)HWREG(ADC0_BASE + ADC_O_SSFIFO2);
//
// Convert to millivolts.
//
ulVoltage = ((unsigned long)usPotValue * 3000) / 1024;
//
// Call the owner with the new value.
//
if(g_pfnThumbHandler)
{
g_pfnThumbHandler((unsigned short)ulVoltage);
}
}
//*****************************************************************************
//
//! Initializes the ADC to read the thumbwheel potentiometer.
//!
//! This function configures ADC sequence 2 to sample the thumbwheel
//! potentiometer under processor trigger control.
//!
//! \return None.
//
//*****************************************************************************
void
ThumbwheelInit(void)
{
//
// Enable the peripherals used by the touch screen interface.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//
// Configure the pin which the thumbwheel is attached to.
//
GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);
//
// Configure the ADC sample sequence used to read the thumbwheel
//
ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 2, 0,
ADC_CTL_CH10 | ADC_CTL_END | ADC_CTL_IE);
ADCSequenceEnable(ADC0_BASE, 2);
//
// Enable the ADC sample sequence interrupt.
//
ADCIntEnable(ADC0_BASE, 2);
IntEnable(INT_ADC0SS2);
}
//*****************************************************************************
//
//! Triggers the ADC to capture a single sample from the thumbwheel.
//!
//! This function triggers the ADC and starts the process of capturing a single
//! sample from the thumbwheel potentiometer. Once the sample is available,
//! the user-supplied callback function, provided via a call to
//! ThumbwheelCallbackSet{}, will be called with the result.
//!
//! \return None.
//
//*****************************************************************************
void
ThumbwheelTrigger(void)
{
ADCProcessorTrigger(ADC0_BASE, 2);
}
//*****************************************************************************
//
//! Sets the function that will be called when the thumbwheel has been sampled.
//!
//! \param pfnCallback is a pointer to the function to be called when
//! a thumbwheel sample is available.
//!
//! This function sets the address of the function to be called when a new
//! thumbwheel sample is available
//!
//! \return None.
//
//*****************************************************************************
void
ThumbwheelCallbackSet(void (*pfnCallback)(unsigned short usThumbwheelmV))
{
//
// Save the pointer to the callback function.
//
g_pfnThumbHandler = pfnCallback;
}
в общем помогите кто чем может =)
ну и еще куда можно выводить эти значения?
просто с дисплеем на плате это будет довольно пролематично(уж слишком там все сложновато)