sort of working
This commit is contained in:
parent
12c6ef61a0
commit
4099b7dea9
|
@ -4,16 +4,18 @@
|
|||
#include "dfi.h"
|
||||
|
||||
|
||||
#define DATA_LINES 6
|
||||
#define MODULES 10
|
||||
#define FET_COUNT 8
|
||||
#define BYTE_PER_FET 6
|
||||
#define SEGMENTS 6
|
||||
|
||||
volatile uint8_t data[FET_COUNT][BYTE_PER_FET];
|
||||
volatile uint8_t data[DATA_LINES][MODULES][FET_COUNT][SEGMENTS];
|
||||
static virtual_timer_t mosfet_timer;
|
||||
|
||||
// prototypes
|
||||
void initializeSRData(void);
|
||||
static void refreshDisplay(void *arg);
|
||||
void shiftOut(uint8_t);
|
||||
void shiftOut(uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t);
|
||||
|
||||
|
||||
THD_WORKING_AREA(wa_dfiFunc, DFI_THREAD_STACK_SIZE);
|
||||
|
@ -26,16 +28,32 @@ THD_FUNCTION(dfiFunc, p) {
|
|||
static uint8_t counterDigit = 0;
|
||||
static uint8_t counterBit = 0;
|
||||
chVTObjectInit(&mosfet_timer);
|
||||
chVTSet(&mosfet_timer, MS2ST(10), refreshDisplay, NULL);
|
||||
chVTSet(&mosfet_timer, US2ST(1500), refreshDisplay, NULL);
|
||||
|
||||
while(true) {
|
||||
|
||||
if(ST2MS(chVTTimeElapsedSinceX(last_time_simul)) > 100) {
|
||||
if(ST2MS(chVTTimeElapsedSinceX(last_time_simul)) > 20) {
|
||||
|
||||
for(int dataline = 0; dataline < DATA_LINES; dataline++) {
|
||||
|
||||
data[dataline][0][0][1] = counterBit;
|
||||
data[dataline][1][0][1] = 255 - counterBit;
|
||||
data[dataline][2][0][1] = counterBit;
|
||||
data[dataline][3][0][1] = counterBit;
|
||||
data[dataline][4][0][1] = counterBit;
|
||||
data[dataline][5][0][1] = counterBit;
|
||||
data[dataline][6][0][1] = counterBit;
|
||||
data[dataline][7][0][1] = counterBit;
|
||||
data[dataline][8][0][1] = counterBit;
|
||||
data[dataline][9][0][1] = counterBit;
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
for(int fet=0; fet<FET_COUNT; fet++) {
|
||||
for(int digit=0; digit<BYTE_PER_FET; digit++) {
|
||||
if(fet == counterFet && digit == counterDigit) {
|
||||
data[fet][digit] = 0xff; //(1 << counterBit);
|
||||
if(fet == 0 && digit == counterDigit) {
|
||||
data[fet][digit] = 0xff; // (1 << counterBit);
|
||||
} else {
|
||||
data[fet][digit] = 0xff;
|
||||
}
|
||||
|
@ -53,7 +71,8 @@ THD_FUNCTION(dfiFunc, p) {
|
|||
counterFet %= FET_COUNT;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
counterBit++;
|
||||
last_time_simul = chVTGetSystemTimeX();
|
||||
palTogglePad(GPIOC, GPIOC_LED);
|
||||
}
|
||||
|
@ -64,14 +83,8 @@ THD_FUNCTION(dfiFunc, p) {
|
|||
void initializeSRData() {
|
||||
palSetPad(GPIOE, GPIOE_PIN1); //Tells all SRs that uController is sending data
|
||||
|
||||
for(int digit = 0; digit < BYTE_PER_FET; digit++) {
|
||||
shiftOut(0);
|
||||
}
|
||||
|
||||
for(int fet=0; fet<FET_COUNT; fet++) {
|
||||
for(int digit=0; digit<BYTE_PER_FET; digit++) {
|
||||
data[fet][digit] = 0xff;
|
||||
}
|
||||
for(int seg = 0; seg < SEGMENTS; seg++) {
|
||||
shiftOut(0,0,0,0,0,0);
|
||||
}
|
||||
|
||||
palClearPad(GPIOE, GPIOE_PIN1); //Tells all SRs that uController is done sending data
|
||||
|
@ -89,17 +102,27 @@ static void refreshDisplay(void *arg) {
|
|||
|
||||
// switch fets
|
||||
|
||||
for(int digit = 0; digit < BYTE_PER_FET; digit++) {
|
||||
shiftOut(data[fet][digit]);
|
||||
for(int module = MODULES-1; module >= 0; module--) {
|
||||
for(int seg = 0; seg < SEGMENTS; seg++) {
|
||||
shiftOut(data[0][module][fet][seg],
|
||||
data[1][module][fet][seg],
|
||||
data[2][module][fet][seg],
|
||||
data[3][module][fet][seg],
|
||||
data[4][module][fet][seg],
|
||||
data[5][module][fet][seg]);
|
||||
}
|
||||
}
|
||||
|
||||
palClearPort(GPIOD, 0xff00);
|
||||
palClearPort(GPIOD, 0xff00); // fets off
|
||||
|
||||
palSetPad(GPIOE, GPIOE_PIN1); // latch
|
||||
for (int w = 0; w < 1000; w++);
|
||||
palClearPad(GPIOE, GPIOE_PIN1); // latch
|
||||
for (int w = 0; w < 125; w++); // wait ca 8µS
|
||||
|
||||
palSetPad(GPIOE, GPIOE_PIN1); // latch high
|
||||
for (int w = 0; w < 25; w++); // wait ca 1,6µS = 25
|
||||
palClearPad(GPIOE, GPIOE_PIN1); // latch low
|
||||
|
||||
|
||||
for (int w = 0; w < 13; w++); // wait ca 1µS
|
||||
|
||||
// switch fets
|
||||
//palSetPort(GPIOD, (1 << (fet+8)));
|
||||
|
@ -115,7 +138,7 @@ static void refreshDisplay(void *arg) {
|
|||
|
||||
//palClearPort(GPIOD, 0xff00);
|
||||
|
||||
chVTSetI(&mosfet_timer, MS2ST(2), refreshDisplay, NULL);
|
||||
chVTSetI(&mosfet_timer, US2ST(1500), refreshDisplay, NULL);
|
||||
chSysUnlockFromISR();
|
||||
|
||||
}
|
||||
|
@ -123,25 +146,31 @@ static void refreshDisplay(void *arg) {
|
|||
|
||||
|
||||
|
||||
void shiftOut(uint8_t val) {
|
||||
void shiftOut(uint8_t val1, uint8_t val2, uint8_t val3,
|
||||
uint8_t val4, uint8_t val5, uint8_t val6) {
|
||||
|
||||
uint8_t i;
|
||||
|
||||
uint8_t bitbit = false;
|
||||
for (i = 0; i < 8; i++) {
|
||||
//bitbit = !!((val & (1 << i)));
|
||||
bitbit = (val & (1 << i)) >> i;
|
||||
/*
|
||||
if(bitbit == 1) {
|
||||
palSetPad(GPIOE, GPIOE_PIN2);
|
||||
} else {
|
||||
palClearPad(GPIOE, GPIOE_PIN2);
|
||||
}*/
|
||||
palWritePad(GPIOE, GPIOE_PIN2, bitbit);
|
||||
|
||||
palWritePad(GPIOE, GPIOE_PIN2, (val1 & (1 << i)) >> i);
|
||||
palWritePad(GPIOE, GPIOE_PIN3, (val2 & (1 << i)) >> i);
|
||||
palWritePad(GPIOE, GPIOE_PIN4, (val3 & (1 << i)) >> i);
|
||||
palWritePad(GPIOE, GPIOE_PIN5, (val4 & (1 << i)) >> i);
|
||||
palWritePad(GPIOE, GPIOE_PIN6, (val5 & (1 << i)) >> i);
|
||||
palWritePad(GPIOE, GPIOE_PIN7, (val6 & (1 << i)) >> i);
|
||||
|
||||
palSetPad(GPIOE, GPIOE_PIN0); //clock
|
||||
for (int w = 0; w < 1000; w++);
|
||||
|
||||
asm ("nop");
|
||||
asm ("nop"); asm ("nop");
|
||||
asm ("nop");
|
||||
asm ("nop");
|
||||
asm ("nop");
|
||||
asm ("nop");
|
||||
asm ("nop");
|
||||
asm ("nop");
|
||||
palClearPad(GPIOE, GPIOE_PIN0); //clock
|
||||
for (int w = 0; w < 1000; w++);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue