PWM ansteuerbar und TOP wird returned

This commit is contained in:
Tristan Krause 2019-05-28 12:32:31 +02:00
parent 1f53117577
commit 2c47159df3
78 changed files with 459 additions and 148 deletions

BIN
control/bin/b15fcli Executable file

Binary file not shown.

View file

@ -0,0 +1,30 @@
# Name: Makefile
# Project: B15F (board15 Famulus Edition)
# Author: Tristan Krause
# Creation Date: 2019-05-15
# Environment
COMPILER_PATH = g++
# Options
CFLAGS = -std=c++17 -O3 -Wall -Wextra
LDFLAGS = -lb15fdrv
OBJECTS = main.o
OUT = main.elf
COMPILE = $(COMPILER_PATH) $(CFLAGS)
main: $(OBJECTS)
$(COMPILE) $(OBJECTS) -o $(OUT) $(LDFLAGS)
help:
@echo "This Makefile has the following targets:"
@echo "make main .... to compile"
@echo "make clean ... to delete objects and executables"
clean:
@echo "Cleaning..."
rm -f $(OBJECTS) $(OUT) *.bin gnuplotscript.gp
.cpp.o:
$(COMPILE) -c $< -o $@

View file

@ -0,0 +1,14 @@
#include <iostream>
#include <cmath>
#include <b15f/b15f.h>
#include <b15f/plottyfile.h>
const char PLOT_FILE[] = "plot.bin";
int main()
{
B15F& drv = B15F::getInstance();
std::cout << "TOP: " << (int) drv.pwmSetFrequency(100000) << std::endl;
drv.pwmSetValue(40);
}

View file

@ -289,6 +289,47 @@ void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset
delay_us(10);
}
uint8_t B15F::pwmSetFrequency(uint32_t freq)
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_PWM_SET_FREQ,
static_cast<uint8_t>((freq >> 0) & 0xFF),
static_cast<uint8_t>((freq >> 8) & 0xFF),
static_cast<uint8_t>((freq >> 16) & 0xFF),
static_cast<uint8_t>((freq >> 24) & 0xFF)
};
int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
if(n_sent != sizeof(rq))
abort("Sent failed");
uint8_t byte = usart.readByte();
delay_us(10);
return byte;
}
bool B15F::pwmSetValue(uint8_t value)
{
usart.clearInputBuffer();
uint8_t rq[] =
{
RQ_PWM_SET_VALUE,
value
};
int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
if(n_sent != sizeof(rq))
abort("Sent failed");
uint8_t aw = usart.readByte();
delay_us(10);
return aw == MSG_OK;
}
void B15F::delay_ms(uint16_t ms)
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));

View file

@ -194,6 +194,22 @@ public:
*/
void analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count);
/**
* Setzt die Register so, dass näherungsweise die gewünschte Frequenz erzeugt wird.
* Ist freq == 0 wird PWM deaktiviert.
* \param freq PWM Frequenz
* \return Top Wert des PWM Value für die gesetzte Frequenz
* \throws DriverException
*/
uint8_t pwmSetFrequency(uint32_t freq);
/**
* Setzt den PWM Wert.
* \param value PWM Wert [0..0xFF]
* \throws DriverException
*/
bool pwmSetValue(uint8_t value);
/*************************/
@ -233,6 +249,8 @@ private:
constexpr static uint8_t RQ_AA1 = 11;
constexpr static uint8_t RQ_ADC = 12;
constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
constexpr static uint8_t RQ_PWM_SET_FREQ = 14;
constexpr static uint8_t RQ_PWM_SET_VALUE = 15;
};
#endif // B15F_H

View file

@ -85,7 +85,12 @@ void USART::writeInt(uint16_t d)
throw USARTException("Fehler beim Senden: writeInt()");
}
void USART::writeU32(uint32_t w)
{
int sent = write(file_desc, reinterpret_cast<char*>(&w), 4);
if(sent != 4)
throw USARTException("Fehler beim Senden: writeU32()");
}
int USART::read_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout)
{

View file

@ -76,11 +76,18 @@ public:
/**
* Sendet ein Integer über die USART Schnittstelle
* \param b das zu sendende Byte
* \param b das zu sendende Int
* \throws USARTException
*/
void writeInt(uint16_t d);
/**
* Sendet ein uint32_t über die USART Schnittstelle
* \param b das zu sendende uint32_t
* \throws USARTException
*/
void writeU32(uint32_t d);
/**
* Empfängt ein Byte über die USART Schnittstelle
* \throws USARTException