Old serial system

This commit is contained in:
IMback
2018-09-01 21:19:29 +02:00
parent 1cbff35a33
commit 91971f5380
30 changed files with 2792 additions and 839 deletions

80
pwm.cpp
View File

@ -2,31 +2,64 @@
//16bit
Pwm16b::Pwm16b()
Pwm16b::Pwm16b( volatile unsigned char *timerControlRegisterA, volatile unsigned char *timerControlRegisterB, volatile uint16_t *compareRegisterA, volatile uint16_t *compareRegisterB, volatile uint16_t *inputCaptureRegister, const uint8_t speed, const bool enableA, const bool enableB)
{
DDRB |= (1<<PB1);
OCR1A = 0x00; //0% pwm to start A
TCNT1=0;
TCCR1A|=(1<<COM1A1); //enable OCR1A only;
ICR1=100;
on();
_timerControlRegisterA = timerControlRegisterA;
_compareRegisterA = compareRegisterA;
_compareRegisterB = compareRegisterB;
_enableA =enableA;
_enableB =enableB;
*_timerControlRegisterA = 0x00;
*timerControlRegisterB = 0x00;
*inputCaptureRegister = 0xFFFF;
*timerControlRegisterB |= (1<<WGM13) | (1<<WGM12);
*timerControlRegisterB |= 0b00000111 & speed;
*_timerControlRegisterA|= (1<<WGM11);
*_compareRegisterA = 0;
*_compareRegisterB = 0;
}
bool Pwm16b::isOn()
{
return (*_timerControlRegisterA != (1<<WGM11));
}
void Pwm16b::off()
{
TCCR1B = 0x00;
*_timerControlRegisterA = 0x00;
*_timerControlRegisterA |= (1<<WGM11);
}
void Pwm16b::on()
{
// Phase and freq correct 16 bit PWM start pwm with /1024 prescaller
TCCR1B|=(1<<WGM13) | (1<<WGM10);
TCCR1B|= (1 << CS00) | (1 << CS01);
off();
if(_enableA) *_timerControlRegisterA|= (1<<COM1A1);
if(_enableB) *_timerControlRegisterA|= (1<<COM1B1);
}
void Pwm16b::setDuty(const uint16_t duty)
uint16_t Pwm16b::getValueA()
{
OCR1A = duty;
return *_compareRegisterA;
}
uint16_t Pwm16b::getValueB()
{
return *_compareRegisterB;
}
void Pwm16b::setDutyA(const uint16_t duty)
{
*_compareRegisterA = duty;
}
void Pwm16b::setDutyB(const uint16_t duty)
{
*_compareRegisterB = duty;
}
Pwm16b::~Pwm16b()
@ -36,7 +69,7 @@ Pwm16b::~Pwm16b()
//8bit
Pwm8b::Pwm8b( volatile unsigned char *timerControlRegisterA, volatile unsigned char *timerControlRegisterB, volatile unsigned char *compareRegisterA, volatile unsigned char *compareRegisterB, const uint8_t speed, const bool enableA, const bool enableB, const uint8_t dutyA, const uint8_t dutyB)
Pwm8b::Pwm8b( volatile unsigned char *timerControlRegisterA, volatile unsigned char *timerControlRegisterB, volatile unsigned char *compareRegisterA, volatile unsigned char *compareRegisterB, const uint8_t speed, const bool enableA, const bool enableB)
{
_timerControlRegisterA = timerControlRegisterA;
_compareRegisterA = compareRegisterA;
@ -47,7 +80,6 @@ Pwm8b::Pwm8b( volatile unsigned char *timerControlRegisterA, volatile unsigned c
*_timerControlRegisterA = 0x00;
*timerControlRegisterB = 0x00;
//off();
//fast 8 bit PWM pwm A
if(_enableA) *_timerControlRegisterA|= (1<<COM0A1);
@ -58,8 +90,11 @@ Pwm8b::Pwm8b( volatile unsigned char *timerControlRegisterA, volatile unsigned c
*_compareRegisterA = 0; //0% pwm to start0
*_compareRegisterB = 0; //0% pwm to start0
//on();
}
bool Pwm8b::isOn()
{
return (*_timerControlRegisterA & 0x11111100) != 0);
}
void Pwm8b::off()
@ -75,6 +110,17 @@ void Pwm8b::on()
}
uint8_t Pwm8b::getValueA()
{
return *_compareRegisterA;
}
uint8_t Pwm8b::getValueB()
{
return *_compareRegisterB;
}
void Pwm8b::setDutyA(const uint8_t duty)
{
*_compareRegisterA = duty;