adc working

This commit is contained in:
Wolfgang Hottgenroth 2016-08-31 15:00:25 +02:00
parent a4bb34cffb
commit 686156db83
13 changed files with 154 additions and 29 deletions

View File

@ -24,7 +24,7 @@
<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.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.cc.1115664253" name="C++ Source File" superClass="dk.xpg.msp430eclipse.tool.compiler.gcc.input.cc"/>
</tool>

View File

@ -1,6 +1,7 @@
eclipse.preferences.version=1
msp430/DeviceSerialNumber=
msp430/MSP430TARGETMCU=msp430g2553
msp430/MSPDebugConnection=
msp430/MSPDebugConnection=USB
msp430/MSPDebugDriver=rf2500
msp430/MSPDebugProtocol=SBW
msp430/MSPDebugTTYDevice=

View File

@ -19,16 +19,18 @@ void schInit() {
tasks[i].period = 0;
tasks[i].run = 0;
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++) {
if (tasks[i].exec == NULL) {
tasks[i].delay = delay;
tasks[i].period = period;
tasks[i].run = 0;
tasks[i].exec = exec;
tasks[i].handle = handle;
break;
}
}
@ -38,7 +40,7 @@ void schExec() {
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
if (tasks[i].exec != NULL && tasks[i].run > 0) {
tasks[i].run--;
tasks[i].exec();
tasks[i].exec(tasks[i].handle);
if (tasks[i].period == 0) {
tasks[i].exec = NULL;
}

View File

@ -13,19 +13,20 @@
#define MAX_NUM_OF_TASKS 3
#define MAX_NUM_OF_TASKS 5
typedef struct {
uint32_t delay;
uint32_t period;
uint8_t run;
void (*exec)(void);
void (*exec)(void *handle);
void *handle;
} tTask;
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 schUpdate();

View File

@ -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++) {
gpioSetPin(d, LOW);
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;
activeDigit++;

View File

@ -9,8 +9,8 @@
#define DISPLAY_H_
void displayInit();
void displayExec();
void displayInit(void *handleArg);
void displayExec(void *handleArg);
void displaySetValue(uint8_t v);

View File

@ -42,7 +42,8 @@ typedef enum {
SEG_G,
DIGIT_0,
DIGIT_1,
TESTPIN,
TESTPIN1,
TESTPIN2,
PINS_END
} tPin;

View File

@ -17,5 +17,6 @@ tPinCfg pinCfg[PINS_END] = {
{PORT2, BIT2, LOW}, //G
{PORT2, BIT0, HIGH}, //0
{PORT1, BIT5, HIGH}, //1
{PORT1, BIT7, LOW}, // TESTPIN
{PORT1, BIT1, LOW}, // TESTPIN1
{PORT1, BIT2, LOW}, // TESTPIN2
};

View File

@ -8,12 +8,14 @@
#include <msp430g2553.h>
#include <stdint.h>
#include <intrinsics.h>
#include <stdlib.h>
#include "gpio.h"
#include "time.h"
#include "display.h"
#include "PontCoopScheduler.h"
#include "testTask.h"
// #include "testTask.h"
#include "measure.h"
int main() {
@ -32,13 +34,24 @@ int main() {
// interrupts are required for delay function in displayInit();
__enable_interrupt();
displayInit();
displayInit(NULL);
__disable_interrupt();
testTaskInit();
// tTestTaskHandle testTaskHandle1;
// testTaskInit(&testTaskHandle1, TESTPIN1);
//
// tTestTaskHandle testTaskHandle2;
// testTaskInit(&testTaskHandle2, TESTPIN2);
// schAdd(displayExec, 0, 100);
schAdd(testTaskExec, 0, 100);
measureInit(NULL);
schAdd(displayExec, NULL, 0, 100);
// schAdd(testTaskExec, &testTaskHandle1, 0, 20);
// schAdd(testTaskExec, &testTaskHandle2, 2, 20);
// schAdd(measureStartConversion, NULL, 0, 1000);
__enable_interrupt();
while (1) {
schExec();

59
src/measure.c Normal file
View 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
View 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_ */

View File

@ -6,21 +6,39 @@
*/
#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) {
toggle = 1;
gpioSetPin(TESTPIN, HIGH);
void testTaskSwitchOff(void *handleArg) {
tTestTaskHandle *handle = handleArg;
if (handle->toggle == 0) {
handle->toggle = 1;
gpioSetPin(handle->pin, HIGH);
} else {
toggle = 0;
gpioSetPin(TESTPIN, LOW);
handle->toggle = 0;
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);
}

View File

@ -8,8 +8,17 @@
#ifndef 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_ */