diff --git a/peripherals/cc48x6/build.md b/peripherals/cc48x6/build.md new file mode 100644 index 0000000..91d6d0a --- /dev/null +++ b/peripherals/cc48x6/build.md @@ -0,0 +1,5 @@ +``` +sudo docker run --rm -ti -v /.../fiatlux/:/src alpine:latest +apk add make gcc-arm-none-eabi newlib-arm-none-eabi +make +``` diff --git a/peripherals/cc48x6/calc_lookup.ods b/peripherals/cc48x6/calc_lookup.ods new file mode 100644 index 0000000..5f0e655 Binary files /dev/null and b/peripherals/cc48x6/calc_lookup.ods differ diff --git a/peripherals/cc48x6/firmware/Src/main.c b/peripherals/cc48x6/firmware/Src/main.c index 782a9a4..3b17891 100644 --- a/peripherals/cc48x6/firmware/Src/main.c +++ b/peripherals/cc48x6/firmware/Src/main.c @@ -69,7 +69,12 @@ volatile bool dirty = true; //uint16_t mem[12] = {0xFFF, 0xFF, 0xFFF, 0xFF, 0xFFF, 0xFF, 0xFFF, 0xFF, 0xFFF, 0xFF, 0xFFF, 0xFF}; //uint16_t mem[12] = {0x300, 0x40, 0x300, 0x40, 0x300, 0x40, 0x300, 0x40, 0x300, 0x40, 0x300, 0x40}; //uint16_t mem[12] = {0xFFF, 0xFF, 0xFFF, 0xFF, 0xFFF, 0xFF, 0xFFF, 0xFF, 0xFFF, 0xFF, 0xFFF, 0xFF}; -uint16_t mem[12] = {0x400, 0xff, 0x400, 0xff, 0x400, 0xff, 0x400, 0xff, 0x400, 0xff, 0x400, 0xff}; +uint16_t mem[12] = {0x300, 0xff, 0x300, 0xff, 0x300, 0xff, 0x300, 0xff, 0x300, 0xff, 0x300, 0xff}; + + +uint16_t lookup_ana[256] = {0, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 755, 771, 787, 803, 819, 835, 851, 867, 883, 899, 915, 931, 947, 964, 980, 996, 1012, 1028, 1044, 1060, 1076, 1092, 1108, 1124, 1140, 1156, 1172, 1188, 1204, 1220, 1237, 1253, 1269, 1285, 1301, 1317, 1333, 1349, 1365, 1381, 1397, 1413, 1429, 1445, 1461, 1477, 1493, 1510, 1526, 1542, 1558, 1574, 1590, 1606, 1622, 1638, 1654, 1670, 1686, 1702, 1718, 1734, 1750, 1766, 1783, 1799, 1815, 1831, 1847, 1863, 1879, 1895, 1911, 1927, 1943, 1959, 1975, 1991, 2007, 2023, 2039, 2056, 2072, 2088, 2104, 2120, 2136, 2152, 2168, 2184, 2200, 2216, 2232, 2248, 2264, 2280, 2296, 2312, 2329, 2345, 2361, 2377, 2393, 2409, 2425, 2441, 2457, 2473, 2489, 2505, 2521, 2537, 2553, 2569, 2585, 2602, 2618, 2634, 2650, 2666, 2682, 2698, 2714, 2730, 2746, 2762, 2778, 2794, 2810, 2826, 2842, 2858, 2875, 2891, 2907, 2923, 2939, 2955, 2971, 2987, 3003, 3019, 3035, 3051, 3067, 3083, 3099, 3115, 3131, 3148, 3164, 3180, 3196, 3212, 3228, 3244, 3260, 3276, 3292, 3308, 3324, 3340, 3356, 3372, 3388, 3404, 3421, 3437, 3453, 3469, 3485, 3501, 3517, 3533, 3549, 3565, 3581, 3597, 3613, 3629, 3645, 3661, 3677, 3694, 3710, 3726, 3742, 3758, 3774, 3790, 3806, 3822, 3838, 3854, 3870, 3886, 3902, 3918, 3934, 3950, 3967, 3983, 3999, 4015, 4031, 4047, 4063, 4079, 4095}; + +uint16_t lookup_pwm[256] = {0, 6, 11, 17, 22, 28, 33, 39, 44, 50, 55, 61, 67, 72, 78, 83, 89, 94, 100, 105, 111, 116, 122, 128, 133, 139, 144, 150, 155, 161, 166, 172, 177, 183, 188, 194, 200, 205, 211, 216, 222, 227, 233, 238, 244, 249, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; uint16_t conf[8] = {version, 0, 0, 0, 0, 0, 0, 0}; @@ -251,22 +256,21 @@ int main(void) { } - //if(dirty) { - for (int i = 0; i < 6; ++i) { - setDAC(i, mem[i * 2]); + if(dirty) { + for (int i = 0; i < 6; ++i) { + setDAC(i, mem[i * 2]); + } + + TIM1->CCR1 = 0xFF & mem[1]; + TIM1->CCR2 = 0xFF & mem[3]; + TIM1->CCR3 = 0xFF & mem[5]; + TIM1->CCR4 = 0xFF & mem[7]; + TIM3->CCR1 = 0xFF & mem[9]; + TIM3->CCR2 = 0xFF & mem[11]; + + dirty = false; } - TIM1->CCR1 = 0xFF & mem[1]; - TIM1->CCR2 = 0xFF & mem[3]; - TIM1->CCR3 = 0xFF & mem[5]; - TIM1->CCR4 = 0xFF & mem[7]; - TIM3->CCR1 = 0xFF & mem[9]; - TIM3->CCR2 = 0xFF & mem[11]; - - dirty = false; - - //} - } /* USER CODE END 3 */ } @@ -283,12 +287,21 @@ void USART2_IRQHandler(void) if (v == 0) dirty = true; }else{ uint16_t idx = (uart_proto_state - 1) / 2; - if(uart_proto_state & 1) { - mem[idx] &= 0x00ff; - mem[idx] |= (v << 8) & 0xff00; - }else{ - mem[idx] &= 0xff00; - mem[idx] |= v & 0x00ff; + if (idx < sizeof(mem) / sizeof(mem[0])) + { + if(uart_proto_state & 1) { + mem[idx] &= 0x00ff; + mem[idx] |= (v << 8) & 0xff00; + }else{ + mem[idx] &= 0xff00; + mem[idx] |= v & 0x00ff; + } + } + if (uart_proto_state == 128) { + for(int i = 0; i < 6; i++) { + mem[i*2+0] = lookup_ana[v]; + mem[i*2+1] = lookup_pwm[v]; + } } uart_proto_state = 0; } diff --git a/peripherals/cc48x6/firmware/Src/tim.c b/peripherals/cc48x6/firmware/Src/tim.c index 4e674f1..9ef8dc0 100644 --- a/peripherals/cc48x6/firmware/Src/tim.c +++ b/peripherals/cc48x6/firmware/Src/tim.c @@ -43,7 +43,7 @@ void MX_TIM1_Init(void) /* USER CODE END TIM1_Init 1 */ htim1.Instance = TIM1; - htim1.Init.Prescaler = 0; + htim1.Init.Prescaler = 90; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; htim1.Init.Period = 65535; htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; @@ -114,7 +114,7 @@ void MX_TIM3_Init(void) /* USER CODE END TIM3_Init 1 */ htim3.Instance = TIM3; - htim3.Init.Prescaler = 0; + htim3.Init.Prescaler = 90; htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.Period = 65535; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; diff --git a/peripherals/cc48x6/test.py b/peripherals/cc48x6/test.py new file mode 100644 index 0000000..47b9b66 --- /dev/null +++ b/peripherals/cc48x6/test.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +import serial +import time +ser = serial.Serial("/dev/ttyUSB0", 115200) + +def setCh(ch, ana, pwm): + ser.write(bytearray([ch*4+1, ana >> 8, ch*4+2, ana & 0xff, ch*4+4, pwm, 0,0])) + +def setG(val): + ser.write(bytearray([128,val,0])) + +setCh(0,0,0) +setCh(1,0,0) +setCh(2,0,0) +setCh(3,0,0) +setCh(4,0,0) +setCh(5,0,0) + +if False: #for i in range(0, 4095, 5): + print(i) + setCh(0,i,255) + time.sleep(0.1) + +for i in range(255): + print(i) + setG(i) + time.sleep(0.5)