Controlling a single layer
Closed this issue · 5 comments
Milestone when a single layer can be controlled
Steps
- Write a function that uses a loop or loops to set certain 'pixels' in a layer, using the
LedCube_setPixel
function. To begin with a pattern could be red, green, blue, red, green, blue, red, green for row one, and so on. - Test if the data is correctly set in the CubeData by printing in to a terminal and checking the pattern.
- Install the boot loader on the MCU and make sure the MCU is programmable using the the boot loader program and a custom linker script.
- Check whether the configuration bits are right because the configuration bits can only be set at the time of writing the boot loader to the MCU. This check could be performed by checking reading the bits from the registers (if possible) or by pulsing an output pin and checking the frequency on a scope.
- Write a function that outputs a colour on a single led of every row one at a time in a loop with a delay.
- Connect all the wires to the PanelControl PCBs and check with the previously written function whether the wires are correctly connected. And close the LedCube box.
- Use the function written in step one to check if all LEDs could be written with the right colour.
- Write functions to make all the LEDs of one row a certain colour and check whether this function works correctly by enabling the LEDs one after another, going from coordinate (0, 0, z) to (7, 7, z).
Had to make an extra function in CubeControlData and LedCube to allow filling a row for example one LED at a time.
So the pattern for this row will be:
index (below) LED: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---|---|---|---|---|---|---|---|---|
1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
2 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
3 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
4 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
5 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
6 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
7 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
8 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
The function is called LedCube_updateUsingCopy
and copies the content of the write 'buffer' to the 'read' buffer. This way it is possible to add pixels without the previous set pixels are lost after the update or previous data is present after the update.
Wrote functions to print the configuration bits from their address. The LedCube's configuration bits is the configuration bits that are defined in LedCube's main.c.
The bootloader's configuration bits are compared before and after the changes. Also made some permanent changes in the configbits. Like Clock switching is now enabled.
Frequency is checked by periodically (by timer ISR) beeping the buzzer.
Bootloader's Configuration Bits (before changes):
CW1: Flash Configuration Word 1
Bit number | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Description | --- | --- | --- | --- | --- | --- | --- | --- | r | JTAGEN | GCP | GWRP | !DEBUG | r | ICS1 | ICS0 | FWDTEN | WINDIS | r | FWPSA | WDTPS3 | WDTPS2 | WDTPS1 | WDTPS0 |
Value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 1 |
CW2: Flash Configuration Word 2
Bit number | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Description | --- | --- | --- | --- | --- | --- | --- | --- | IESO | WUTSEL1 | WUTSEL0 | SOSCSEL1 | SOSCSEL0 | FNOSC2 | FNOSC1 | FNOSC0 | FCKSM1 | FCKSM0 | OSCIOFCN | IOL1WAY | r | I2C1SEL | POSCMD1 | POSCMD0 |
Value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |
Bootloader's Configuration Bits (after changes):
CW1: Flash Configuration Word 1
Bit number | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Description | --- | --- | --- | --- | --- | --- | --- | --- | r | JTAGEN | GCP | GWRP | !DEBUG | r | ICS1 | ICS0 | FWDTEN | WINDIS | r | FWPSA | WDTPS3 | WDTPS2 | WDTPS1 | WDTPS0 |
Value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
CW2: Flash Configuration Word 2
Bit number | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Description | ------- | ------- | ------- | ------- | ------- | ------- | ------- | --- | IESO | WUTSEL1 | WUTSEL0 | SOSCSEL1 | SOSCSEL0 | FNOSC2 | FNOSC1 | FNOSC0 | FCKSM1 | FCKSM0 | OSCIOFCN | IOL1WAY | r | I2C1SEL | POSCMD1 | POSCMD0 |
Value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |
LedCube's Configuration Bits:
CW1: Flash Configuration Word 1
Bit number | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Description | --- | --- | --- | --- | --- | --- | --- | --- | r | JTAGEN | GCP | GWRP | !DEBUG | r | ICS1 | ICS0 | FWDTEN | WINDIS | r | FWPSA | WDTPS3 | WDTPS2 | WDTPS1 | WDTPS0 |
Value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
CW2: Flash Configuration Word 2
Bit number | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Description | --- | --- | --- | --- | --- | --- | --- | --- | IESO | WUTSEL1 | WUTSEL0 | SOSCSEL1 | SOSCSEL0 | FNOSC2 | FNOSC1 | FNOSC0 | FCKSM1 | FCKSM0 | OSCIOFCN | IOL1WAY | r | I2C1SEL | POSCMD1 | POSCMD0 |
Value | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 |
Now wrote a nice function to output the configuration words. This outputs the results of the words in a very user friendly way. See the following example output.
Reading Flash Configuration Word 1...
Binary read value:
111111110011111101111111
Successfully verified the Flash Configuration Word 1 with address 0x00ABFE
JTAGEN: JTAG Port Enable bit
[JTAGEN_OFF] JTAG port is disabled
GCP: General Segment Program Memory Code Protection bit
[GCP_OFF] Code protection is disabled
GWRP: General Segment Code Flash Write Protection bit
[GWRP_OFF] Writes to program memory are allowed
!DEBUG: Background Debugger Enable bit
[BKBUG_OFF] Device resets into Operational mode
ICS<1:0>: Emulator Pin Placement Select bits
[ICS_PGx1] Emulator EMUC1/EMUD1 pins are shared with PGC1/PGD1
FWDTEN: Watchdog Timer Enable bit
[FWDTEN_OFF] Watchdog Timer is disabled
WINDIS: Windowed Watchdog Timer Disable bit
[WINDIS_ON] Standard Watchdog Timer is enabled
FWPSA: WDT Prescaler Ratio Select bit
[FWPSA_PR128] Prescaler ratio of 1:128
WDTPS<3:0>: Watchdog Timer Postscaler Select bits
[WDTPS_PS32768] 1:32768
Done Reading Flash Configuration Word 1.
Reading Flash Configuration Word 2...
Binary read value:
111111111111100101101101
Successfully verified the Flash Configuration Word 2 with address 0x00ABFC
IESO: Internal External Switchover bit
[IESO_ON] IESO mode (Two-Speed Start-up) is enabled
WUTSEL<1:0>: Voltage Regulator Standby Mode Wake-up Time Select bits
[WUTSEL_LEG] Default regulator start-up time is used
SOSCSEL<1:0>: Secondary Oscillator Power Mode Select bits
[SOSCSEL_SOSC] Default (High Drive Strength) mode
FNOSC<2:0>: Initial Oscillator Select bits
[FNOSC_FRCPLL] Fast RC Oscillator with Postscaler and PLL module (FRCPLL)
FCKSM<1:0>: Clock Switching and Fail-Safe Clock Monitor Configuration bits
[FCKSM_CSECMD] Clock switching is enabled, Fail-Safe Clock Monitor is disabled
OSCIOFCN: OSCO Pin Configuration bit:
OSCIOFCN has no effect on OSCO/CLKO/RA3
IOL1WAY: IOLOCK One-Way Set Enable bit
[IOL1WAY_OFF] The IOLOCK (OSCCON<6>) bit can be set and cleared as needed, provided the unlock sequence has been completed
I2C1SEL: I2C1 Pin Select bit
[I2C1SEL_PRI] Use default SCL1/SDA1 pins
POSCMD<1:0:> Primary Oscillator Configuration bits
[POSCMOD_XT] XT Oscillator mode is selected
Done Reading Flash Configuration Word 2.
Wrote very simple code for checking the right wire connection. It simply loops through the 8 rows enabling single colour on one row at every time.
uint32_t delay = 1000;
uint8_t i = 0;
for(i = 0; i < CUBEDATA_MAX_X_C; i++) {
LedCube_setPixel(i,0,0, LEDCUBE_MAX_INTENSITY, 0, 0);
LedCube_update();
Delay_ms(delay);
LedCube_resetData();
LedCube_setPixel(i,0,0, 0, LEDCUBE_MAX_INTENSITY, 0);
LedCube_update();
Delay_ms(delay);
LedCube_resetData();
LedCube_setPixel(i,0,0, 0, 0, LEDCUBE_MAX_INTENSITY);
LedCube_update();
Delay_ms(delay);
LedCube_resetData();
}
Tested code from fill.c and it worked as expected.