adc working
This commit is contained in:
parent
a4bb34cffb
commit
686156db83
@ -24,7 +24,7 @@
|
|||||||
<tool id="dk.xpg.msp430eclipse.tool.compiler.gcc.1489133124" name="MSP430 C Compiler" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc">
|
<tool id="dk.xpg.msp430eclipse.tool.compiler.gcc.1489133124" name="MSP430 C Compiler" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc">
|
||||||
<option defaultValue="dk.xpg.msp430eclipse.compiler.option.optimization.level.none" id="dk.xpg.msp430eclipse.compiler.option.optimization.level.925149145" name="Optimization Level" superClass="dk.xpg.msp430eclipse.compiler.option.optimization.level" valueType="enumerated"/>
|
<option defaultValue="dk.xpg.msp430eclipse.compiler.option.optimization.level.none" id="dk.xpg.msp430eclipse.compiler.option.optimization.level.925149145" name="Optimization Level" superClass="dk.xpg.msp430eclipse.compiler.option.optimization.level" valueType="enumerated"/>
|
||||||
<option defaultValue="dk.xpg.msp430eclipse.compiler.option.debugging.level.default" id="dk.xpg.msp430eclipse.compiler.option.debugging.level.154569899" name="Debugging Level" superClass="dk.xpg.msp430eclipse.compiler.option.debugging.level" valueType="enumerated"/>
|
<option defaultValue="dk.xpg.msp430eclipse.compiler.option.debugging.level.default" id="dk.xpg.msp430eclipse.compiler.option.debugging.level.154569899" name="Debugging Level" superClass="dk.xpg.msp430eclipse.compiler.option.debugging.level" valueType="enumerated"/>
|
||||||
<option id="dk.xpg.msp430eclipse.compiler.option.language.standard.1380069728" superClass="dk.xpg.msp430eclipse.compiler.option.language.standard" value="dk.xpg.msp430eclipse.compiler.option.language.standard.gnu99" valueType="enumerated"/>
|
<option id="dk.xpg.msp430eclipse.compiler.option.language.standard.1380069728" name="Standard" superClass="dk.xpg.msp430eclipse.compiler.option.language.standard" value="dk.xpg.msp430eclipse.compiler.option.language.standard.gnu99" valueType="enumerated"/>
|
||||||
<inputType id="dk.xpg.msp430eclipse.tool.compiler.gcc.input.1393043846" name="C Source File" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc.input"/>
|
<inputType id="dk.xpg.msp430eclipse.tool.compiler.gcc.input.1393043846" name="C Source File" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc.input"/>
|
||||||
<inputType id="dk.xpg.msp430eclipse.tool.compiler.gcc.input.cc.1115664253" name="C++ Source File" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc.input.cc"/>
|
<inputType id="dk.xpg.msp430eclipse.tool.compiler.gcc.input.cc.1115664253" name="C++ Source File" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc.input.cc"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
msp430/DeviceSerialNumber=
|
msp430/DeviceSerialNumber=
|
||||||
msp430/MSP430TARGETMCU=msp430g2553
|
msp430/MSP430TARGETMCU=msp430g2553
|
||||||
msp430/MSPDebugConnection=
|
msp430/MSPDebugConnection=USB
|
||||||
|
msp430/MSPDebugDriver=rf2500
|
||||||
msp430/MSPDebugProtocol=SBW
|
msp430/MSPDebugProtocol=SBW
|
||||||
msp430/MSPDebugTTYDevice=
|
msp430/MSPDebugTTYDevice=
|
||||||
|
@ -19,16 +19,18 @@ void schInit() {
|
|||||||
tasks[i].period = 0;
|
tasks[i].period = 0;
|
||||||
tasks[i].run = 0;
|
tasks[i].run = 0;
|
||||||
tasks[i].exec = NULL;
|
tasks[i].exec = NULL;
|
||||||
|
tasks[i].handle = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void schAdd(void (*exec)(void), uint32_t delay, uint32_t period) {
|
void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period) {
|
||||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||||
if (tasks[i].exec == NULL) {
|
if (tasks[i].exec == NULL) {
|
||||||
tasks[i].delay = delay;
|
tasks[i].delay = delay;
|
||||||
tasks[i].period = period;
|
tasks[i].period = period;
|
||||||
tasks[i].run = 0;
|
tasks[i].run = 0;
|
||||||
tasks[i].exec = exec;
|
tasks[i].exec = exec;
|
||||||
|
tasks[i].handle = handle;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,7 +40,7 @@ void schExec() {
|
|||||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||||
if (tasks[i].exec != NULL && tasks[i].run > 0) {
|
if (tasks[i].exec != NULL && tasks[i].run > 0) {
|
||||||
tasks[i].run--;
|
tasks[i].run--;
|
||||||
tasks[i].exec();
|
tasks[i].exec(tasks[i].handle);
|
||||||
if (tasks[i].period == 0) {
|
if (tasks[i].period == 0) {
|
||||||
tasks[i].exec = NULL;
|
tasks[i].exec = NULL;
|
||||||
}
|
}
|
||||||
|
@ -13,19 +13,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_NUM_OF_TASKS 3
|
#define MAX_NUM_OF_TASKS 5
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t delay;
|
uint32_t delay;
|
||||||
uint32_t period;
|
uint32_t period;
|
||||||
uint8_t run;
|
uint8_t run;
|
||||||
void (*exec)(void);
|
void (*exec)(void *handle);
|
||||||
|
void *handle;
|
||||||
} tTask;
|
} tTask;
|
||||||
|
|
||||||
|
|
||||||
void schInit();
|
void schInit();
|
||||||
void schAdd(void (*exec)(void), uint32_t delay, uint32_t period);
|
void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period);
|
||||||
void schExec();
|
void schExec();
|
||||||
void schUpdate();
|
void schUpdate();
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ uint8_t digitValues[2] = { EMPTY_ID, EMPTY_ID };
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void displayInit() {
|
void displayInit(void *handleArg) {
|
||||||
for (tPin d = DIGIT_0; d <= DIGIT_1; d++) {
|
for (tPin d = DIGIT_0; d <= DIGIT_1; d++) {
|
||||||
gpioSetPin(d, LOW);
|
gpioSetPin(d, LOW);
|
||||||
for (tPin s = SEG_A; s <= SEG_G; s++) {
|
for (tPin s = SEG_A; s <= SEG_G; s++) {
|
||||||
@ -86,7 +86,7 @@ void displaySetValue(uint8_t v) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayExec() {
|
void displayExec(void *handleArg) {
|
||||||
static uint8_t activeDigit = 0;
|
static uint8_t activeDigit = 0;
|
||||||
|
|
||||||
activeDigit++;
|
activeDigit++;
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
#define DISPLAY_H_
|
#define DISPLAY_H_
|
||||||
|
|
||||||
|
|
||||||
void displayInit();
|
void displayInit(void *handleArg);
|
||||||
void displayExec();
|
void displayExec(void *handleArg);
|
||||||
void displaySetValue(uint8_t v);
|
void displaySetValue(uint8_t v);
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +42,8 @@ typedef enum {
|
|||||||
SEG_G,
|
SEG_G,
|
||||||
DIGIT_0,
|
DIGIT_0,
|
||||||
DIGIT_1,
|
DIGIT_1,
|
||||||
TESTPIN,
|
TESTPIN1,
|
||||||
|
TESTPIN2,
|
||||||
PINS_END
|
PINS_END
|
||||||
} tPin;
|
} tPin;
|
||||||
|
|
||||||
|
@ -17,5 +17,6 @@ tPinCfg pinCfg[PINS_END] = {
|
|||||||
{PORT2, BIT2, LOW}, //G
|
{PORT2, BIT2, LOW}, //G
|
||||||
{PORT2, BIT0, HIGH}, //0
|
{PORT2, BIT0, HIGH}, //0
|
||||||
{PORT1, BIT5, HIGH}, //1
|
{PORT1, BIT5, HIGH}, //1
|
||||||
{PORT1, BIT7, LOW}, // TESTPIN
|
{PORT1, BIT1, LOW}, // TESTPIN1
|
||||||
|
{PORT1, BIT2, LOW}, // TESTPIN2
|
||||||
};
|
};
|
||||||
|
23
src/main.c
23
src/main.c
@ -8,12 +8,14 @@
|
|||||||
#include <msp430g2553.h>
|
#include <msp430g2553.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <intrinsics.h>
|
#include <intrinsics.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "PontCoopScheduler.h"
|
#include "PontCoopScheduler.h"
|
||||||
#include "testTask.h"
|
// #include "testTask.h"
|
||||||
|
#include "measure.h"
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -32,13 +34,24 @@ int main() {
|
|||||||
|
|
||||||
// interrupts are required for delay function in displayInit();
|
// interrupts are required for delay function in displayInit();
|
||||||
__enable_interrupt();
|
__enable_interrupt();
|
||||||
displayInit();
|
displayInit(NULL);
|
||||||
__disable_interrupt();
|
__disable_interrupt();
|
||||||
|
|
||||||
testTaskInit();
|
// tTestTaskHandle testTaskHandle1;
|
||||||
|
// testTaskInit(&testTaskHandle1, TESTPIN1);
|
||||||
|
//
|
||||||
|
// tTestTaskHandle testTaskHandle2;
|
||||||
|
// testTaskInit(&testTaskHandle2, TESTPIN2);
|
||||||
|
|
||||||
// schAdd(displayExec, 0, 100);
|
measureInit(NULL);
|
||||||
schAdd(testTaskExec, 0, 100);
|
|
||||||
|
|
||||||
|
schAdd(displayExec, NULL, 0, 100);
|
||||||
|
// schAdd(testTaskExec, &testTaskHandle1, 0, 20);
|
||||||
|
// schAdd(testTaskExec, &testTaskHandle2, 2, 20);
|
||||||
|
// schAdd(measureStartConversion, NULL, 0, 1000);
|
||||||
|
|
||||||
|
__enable_interrupt();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
schExec();
|
schExec();
|
||||||
|
59
src/measure.c
Normal file
59
src/measure.c
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* adc.cpp
|
||||||
|
*
|
||||||
|
* Created on: 03.10.2014
|
||||||
|
* Author: wn
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <msp430g2553.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "measure.h"
|
||||||
|
#include "PontCoopScheduler.h"
|
||||||
|
#include "display.h"
|
||||||
|
#include "gpio.h"
|
||||||
|
|
||||||
|
|
||||||
|
const float R_REF = 3000.0;
|
||||||
|
const uint16_t N_MAX = 1023;
|
||||||
|
const float PT1000_R0 = 1000.0;
|
||||||
|
const float PT1000_Coeff = 3.85e-3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void measureInit(void *handleArg) {
|
||||||
|
ADC10CTL0 = SREF1 | ADC10SHT_3 | ADC10SR | REFOUT | REFON | REF2_5V | ADC10ON;
|
||||||
|
ADC10CTL1 = INCH_3;
|
||||||
|
ADC10AE0 = BIT3;
|
||||||
|
}
|
||||||
|
|
||||||
|
void measureCollectAndProcessConversion(void *handleArg);
|
||||||
|
|
||||||
|
void measureStartConversion(void *handleArg) {
|
||||||
|
gpioSetPin(TESTPIN1, HIGH);
|
||||||
|
ADC10CTL0 |= ENC | ADC10SC;
|
||||||
|
schAdd(measureCollectAndProcessConversion, NULL, 10, 0);
|
||||||
|
gpioSetPin(TESTPIN1, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void measureCollectAndProcessConversion(void *handleArg) {
|
||||||
|
gpioSetPin(TESTPIN2, HIGH);
|
||||||
|
uint16_t n = 0xffff;
|
||||||
|
if ((ADC10CTL0 & ADC10IFG) != 0) {
|
||||||
|
n = ADC10MEM;
|
||||||
|
ADC10CTL0 &= ~(ADC10IFG | ENC);
|
||||||
|
}
|
||||||
|
|
||||||
|
// process adcValue
|
||||||
|
// store result in variable temperature
|
||||||
|
float r = ((((float)N_MAX) / ((float)n)) - 1.0) * R_REF;
|
||||||
|
float t = (r / PT1000_R0 - 1) / PT1000_Coeff;
|
||||||
|
|
||||||
|
uint8_t temperature = (uint8_t)t;
|
||||||
|
|
||||||
|
displaySetValue(temperature);
|
||||||
|
gpioSetPin(TESTPIN2, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
20
src/measure.h
Normal file
20
src/measure.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* adc.h
|
||||||
|
*
|
||||||
|
* Created on: 03.10.2014
|
||||||
|
* Author: wn
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MEASURE_H_
|
||||||
|
#define MEASURE_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void measureInit(void *handleArg);
|
||||||
|
void measureStartConversion(void *handleArg);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* MEASURE_H_ */
|
@ -6,21 +6,39 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
#include "TestTask.h"
|
||||||
|
#include "PontCoopScheduler.h"
|
||||||
|
|
||||||
|
|
||||||
void testTaskInit() {
|
void testTaskInit(void *handleArg, tPin pin) {
|
||||||
|
tTestTaskHandle *handle = handleArg;
|
||||||
|
handle->pin = pin;
|
||||||
|
handle->toggle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testTaskExec() {
|
|
||||||
static uint8_t toggle = 0;
|
|
||||||
|
|
||||||
if (toggle == 0) {
|
void testTaskSwitchOff(void *handleArg) {
|
||||||
toggle = 1;
|
tTestTaskHandle *handle = handleArg;
|
||||||
gpioSetPin(TESTPIN, HIGH);
|
|
||||||
|
if (handle->toggle == 0) {
|
||||||
|
handle->toggle = 1;
|
||||||
|
gpioSetPin(handle->pin, HIGH);
|
||||||
} else {
|
} else {
|
||||||
toggle = 0;
|
handle->toggle = 0;
|
||||||
gpioSetPin(TESTPIN, LOW);
|
gpioSetPin(handle->pin, LOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testTaskExec(void *handleArg) {
|
||||||
|
tTestTaskHandle *handle = handleArg;
|
||||||
|
if (handle->toggle == 0) {
|
||||||
|
handle->toggle = 1;
|
||||||
|
gpioSetPin(handle->pin, HIGH);
|
||||||
|
} else {
|
||||||
|
handle->toggle = 0;
|
||||||
|
gpioSetPin(handle->pin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
schAdd(testTaskSwitchOff, handle, 5, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,17 @@
|
|||||||
#ifndef TESTTASK_H_
|
#ifndef TESTTASK_H_
|
||||||
#define TESTTASK_H_
|
#define TESTTASK_H_
|
||||||
|
|
||||||
void testTaskInit();
|
|
||||||
void testTaskExec();
|
#include "gpio.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tPin pin;
|
||||||
|
uint8_t toggle;
|
||||||
|
} tTestTaskHandle;
|
||||||
|
|
||||||
|
void testTaskInit(void *handleArg, tPin pin);
|
||||||
|
void testTaskExec(void *handleArg);
|
||||||
|
|
||||||
|
|
||||||
#endif /* TESTTASK_H_ */
|
#endif /* TESTTASK_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user