-updated readme, -modified F0-F31 handling, - implemented pwm for F0-F31
This commit is contained in:
1 parent
4f5283521d
commit
a6fa9ef249
7 files changed
+224
-169
No files matched your search
@@ -47,8 +47,8 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
|
||||
0b00000000, //CV_29 - Decoder Configuration
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
0b00000000, //CV_30 -
|
||||
0b00000000, //CV_31 -
|
||||
0b00000000, //CV_32 -
|
||||
0b00010000, //CV_31 - Extended CV Pointer Bits 8-15
|
||||
0b00000000, //CV_32 - Extended CV Pointer Bits 0-7
|
||||
0b00000000, //CV_33 -
|
||||
0b00000000, //CV_34 -
|
||||
0b00000000, //CV_35 -
|
||||
@@ -63,7 +63,7 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
|
||||
0b00000000, //CV_44 -
|
||||
0b00000000, //CV_45 -
|
||||
0b00000000, //CV_46 -
|
||||
0b00000000, //CV_47 -
|
||||
0b00000001, //CV_47 - Additional Motor-PWM Clock Divider.
|
||||
// PID - Configuration //////////////////////////////////////////////////////////////////////////////////////////////
|
||||
0b00000101, //CV_48 - PID Control Sampling Time t_s in ms ≙ Duration of 1 PID-Cycle //
|
||||
0b01110011, //CV_49 - PID Control P_Factor ≙ CV_49/256 i.e. Default = 115 -> 0.4492 //
|
||||
@@ -140,66 +140,76 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
|
||||
0b00000000, //CV_109 -
|
||||
0b00000000, //CV_110 -
|
||||
0b00000000, //CV_111 -
|
||||
0b00000000, //CV_112 -
|
||||
0b00000000, //CV_113 -
|
||||
0b00000000, //CV_114 -
|
||||
0b00000000, //CV_115 -
|
||||
0b00000000, //CV_116 -
|
||||
0b00000000, //CV_117 -
|
||||
0b00000000, //CV_118 -
|
||||
0b00000000, //CV_119 -
|
||||
0b00000000, //CV_120 -
|
||||
0b00000000, //CV_121 -
|
||||
0b00000000, //CV_122 -
|
||||
0b00000000, //CV_123 -
|
||||
0b00000000, //CV_124 -
|
||||
0b00000000, //CV_125 -
|
||||
0b00000000, //CV_126 -
|
||||
0b00000000, //CV_127 -
|
||||
0b00000000, //CV_128 -
|
||||
0b00000000, //CV_129 -
|
||||
0b00000000, //CV_130 -
|
||||
0b00000000, //CV_131 -
|
||||
0b00000000, //CV_132 -
|
||||
0b00000000, //CV_133 -
|
||||
0b00000000, //CV_134 -
|
||||
0b00000000, //CV_135 -
|
||||
0b00000000, //CV_136 -
|
||||
0b00000000, //CV_137 -
|
||||
0b00000000, //CV_138 -
|
||||
0b00000000, //CV_139 -
|
||||
0b00000000, //CV_140 -
|
||||
0b00000000, //CV_141 -
|
||||
0b00000000, //CV_142 -
|
||||
0b00000000, //CV_143 -
|
||||
0b00000000, //CV_144 -
|
||||
0b00000000, //CV_145 -
|
||||
0b00000000, //CV_146 -
|
||||
0b00000000, //CV_147 -
|
||||
0b00000000, //CV_148 -
|
||||
0b00000000, //CV_149 -
|
||||
0b00000000, //CV_150 -
|
||||
0b00000000, //CV_151 -
|
||||
0b00000000, //CV_152 -
|
||||
0b00000000, //CV_153 -
|
||||
0b00000000, //CV_154 -
|
||||
0b00000000, //CV_155 -
|
||||
0b00000000, //CV_156 -
|
||||
0b00000000, //CV_157 -
|
||||
0b00000000, //CV_158 -
|
||||
0b00000000, //CV_159 -
|
||||
0b00000000, //CV_160 -
|
||||
0b00000000, //CV_161 -
|
||||
0b00000000, //CV_162 -
|
||||
0b00000000, //CV_163 -
|
||||
0b00000000, //CV_164 -
|
||||
0b00000000, //CV_165 -
|
||||
0b00000000, //CV_166 -
|
||||
0b00000000, //CV_167 -
|
||||
0b00000000, //CV_168 -
|
||||
0b00000000, //CV_169 -
|
||||
0b00000000, //CV_170 -
|
||||
0b00000000, //CV_171 -
|
||||
///// PWM - Configuration //////////////////////////////////////////////////////////////////////////////////////////////
|
||||
0b00000000, //CV_112 - GPIO 0-7 enable PWM
|
||||
0b00000100, //CV_113 - GPIO 8-15 enable PWM
|
||||
0b00000000, //CV_114 - GPIO 16-23 enable PWM
|
||||
0b00000000, //CV_115 - GPIO 24-31 enable PWM
|
||||
//Slice 0
|
||||
0b00000000, //CV_116 - Wrap Bits 0-7
|
||||
0b00000000, //CV_117 - Wrap Bits 8-15
|
||||
0b00000001, //CV_118 - Clock Divider
|
||||
0b00000000, //CV_119 - Channel A Level Bits 0-7
|
||||
0b00000000, //CV_120 - Channel A Level Bits 8-15
|
||||
0b00000000, //CV_121 - Channel B Level Bits 0-7
|
||||
0b00000000, //CV_122 - Channel B Level Bits 8-15
|
||||
//Slice 1
|
||||
0b00000000, //CV_123 - Wrap Bits 0-7
|
||||
0b00000000, //CV_124 - Wrap Bits 8-15
|
||||
0b00000001, //CV_125 - Clock Divider
|
||||
0b00000000, //CV_126 - Channel A Level Bits 0-7
|
||||
0b00000000, //CV_127 - Channel A Level Bits 8-15
|
||||
0b00000000, //CV_128 - Channel B Level Bits 0-7
|
||||
0b00000000, //CV_129 - Channel B Level Bits 8-15
|
||||
//Slice 2
|
||||
0b00000000, //CV_130 - Wrap Bits 0-7
|
||||
0b00000000, //CV_131 - Wrap Bits 8-15
|
||||
0b00000001, //CV_132 - Clock Divider
|
||||
0b00000000, //CV_133 - Channel A Level Bits 0-7
|
||||
0b00000000, //CV_134 - Channel A Level Bits 8-15
|
||||
0b00000000, //CV_135 - Channel B Level Bits 0-7
|
||||
0b00000000, //CV_136 - Channel B Level Bits 8-15
|
||||
//Slice 3
|
||||
0b00000000, //CV_137 - Wrap Bits 0-7
|
||||
0b00000000, //CV_138 - Wrap Bits 8-15
|
||||
0b00000001, //CV_139 - Clock Divider
|
||||
0b00000000, //CV_140 - Channel A Level Bits 0-7
|
||||
0b00000000, //CV_141 - Channel A Level Bits 8-15
|
||||
0b00000000, //CV_142 - Channel B Level Bits 0-7
|
||||
0b00000000, //CV_143 - Channel B Level Bits 8-15
|
||||
//Slice 4
|
||||
0b00000000, //CV_144 - Wrap Bits 0-7
|
||||
0b00000000, //CV_145 - Wrap Bits 8-15
|
||||
0b00000001, //CV_146 - Clock Divider
|
||||
0b00000000, //CV_147 - Channel A Level Bits 0-7
|
||||
0b00000000, //CV_148 - Channel A Level Bits 8-15
|
||||
0b00000000, //CV_149 - Channel B Level Bits 0-7
|
||||
0b00000000, //CV_150 - Channel B Level Bits 8-15
|
||||
//Slice 5
|
||||
0b11111111, //CV_151 - Wrap Bits 0-7
|
||||
0b11111111, //CV_152 - Wrap Bits 8-15
|
||||
0b00000001, //CV_153 - Clock Divider
|
||||
0b11111111, //CV_154 - Channel A Level Bits 0-7
|
||||
0b01111111, //CV_155 - Channel A Level Bits 8-15
|
||||
0b00000000, //CV_156 - Channel B Level Bits 0-7
|
||||
0b00000000, //CV_157 - Channel B Level Bits 8-15
|
||||
//Slice 6
|
||||
0b00000000, //CV_158 - Wrap Bits 0-7
|
||||
0b00000000, //CV_159 - Wrap Bits 8-15
|
||||
0b00000001, //CV_160 - Clock Divider
|
||||
0b00000000, //CV_161 - Channel A Level Bits 0-7
|
||||
0b00000000, //CV_162 - Channel A Level Bits 8-15
|
||||
0b00000000, //CV_163 - Channel B Level Bits 0-7
|
||||
0b00000000, //CV_164 - Channel B Level Bits 8-15
|
||||
//Slice 7
|
||||
0b00000000, //CV_165 - Wrap Bits 0-7
|
||||
0b00000000, //CV_166 - Wrap Bits 8-15
|
||||
0b00000001, //CV_167 - Clock Divider
|
||||
0b00000000, //CV_168 - Channel A Level Bits 0-7
|
||||
0b00000000, //CV_169 - Channel A Level Bits 8-15
|
||||
0b00000000, //CV_170 - Channel B Level Bits 0-7
|
||||
0b00000000, //CV_171 - Channel B Level Bits 8-15
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
0b00000000, //CV_172 -
|
||||
0b00000000, //CV_173 -
|
||||
0b00000000, //CV_174 -
|
||||
@@ -291,22 +301,22 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
|
||||
// X X X X - X X X X -- X X X X - X X X X -- X X X X - X X X X -- X X X X - X X X X
|
||||
//F0 forward
|
||||
0b00000000, //byte 0 - CV_257
|
||||
0b00001110, //byte 1 - CV_258
|
||||
0b00000000, //byte 1 - CV_258
|
||||
0b00000000, //byte 2 - CV_259
|
||||
0b00000000, //byte 3 - CV_260
|
||||
//F0 reverse
|
||||
0b00000000, //byte 0 - CV_261
|
||||
0b00001110, //byte 1 - CV_262
|
||||
0b00000000, //byte 1 - CV_262
|
||||
0b00000000, //byte 2 - CV_263
|
||||
0b00000000, //byte 3 - CV_264
|
||||
//F1 forward
|
||||
0b00000000, //byte 0 - CV_265
|
||||
0b00000100, //byte 1 - CV_266
|
||||
0b00000000, //byte 1 - CV_266
|
||||
0b00000000, //byte 2 - CV_267
|
||||
0b00000000, //byte 3 - CV_268
|
||||
//F1 reverse
|
||||
0b00000000, //byte 0 - CV_269
|
||||
0b00000010, //byte 1 - CV_270
|
||||
0b00000000, //byte 1 - CV_270
|
||||
0b00000000, //byte 2 - CV_271
|
||||
0b00000000, //byte 3 - CV_272
|
||||
//F2 forward
|
||||
@@ -325,68 +335,68 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
|
||||
0b00000000, //byte 2 - CV_283
|
||||
0b00000000, //byte 3 - CV_284
|
||||
//F3 reverse
|
||||
0b00001000, //byte 0 - CV_285
|
||||
0b00000000, //byte 0 - CV_285
|
||||
0b00000000, //byte 1 - CV_286
|
||||
0b00000000, //byte 2 - CV_287
|
||||
0b00000000, //byte 3 - CV_288
|
||||
//F4 forward
|
||||
0b00010000, //byte 0 - CV_289
|
||||
0b00000000, //byte 0 - CV_289
|
||||
0b00000000, //byte 1 - CV_290
|
||||
0b00000000, //byte 2 - CV_291
|
||||
0b00000000, //byte 3 - CV_292
|
||||
//F4 reverse
|
||||
0b00010000, //byte 0 - CV_293
|
||||
0b00000000, //byte 0 - CV_293
|
||||
0b00000000, //byte 1 - CV_294
|
||||
0b00000000, //byte 2 - CV_295
|
||||
0b00000000, //byte 3 - CV_296
|
||||
//F5 forward
|
||||
0b00100000, //byte 0 - CV_297
|
||||
0b00000000, //byte 0 - CV_297
|
||||
0b00000000, //byte 1 - CV_298
|
||||
0b00000000, //byte 2 - CV_299
|
||||
0b00000000, //byte 3 - CV_300
|
||||
//F5 reverse
|
||||
0b00100000, //byte 0 - CV_301
|
||||
0b00000000, //byte 0 - CV_301
|
||||
0b00000000, //byte 1 - CV_302
|
||||
0b00000000, //byte 2 - CV_303
|
||||
0b00000000, //byte 3 - CV_304
|
||||
//F6 forward
|
||||
0b01000000, //byte 0 - CV_305
|
||||
0b00000000, //byte 0 - CV_305
|
||||
0b00000000, //byte 1 - CV_306
|
||||
0b00000000, //byte 2 - CV_307
|
||||
0b00000000, //byte 3 - CV_308
|
||||
//F6 reverse
|
||||
0b01000000, //byte 0 - CV_309
|
||||
0b00000000, //byte 0 - CV_309
|
||||
0b00000000, //byte 1 - CV_310
|
||||
0b00000000, //byte 2 - CV_311
|
||||
0b00000000, //byte 3 - CV_312
|
||||
//F7 forward
|
||||
0b10000000, //byte 0 - CV_313
|
||||
0b00000000, //byte 0 - CV_313
|
||||
0b00000000, //byte 1 - CV_314
|
||||
0b00000000, //byte 2 - CV_315
|
||||
0b00000000, //byte 3 - CV_316
|
||||
//F7 reverse
|
||||
0b10000000, //byte 0 - CV_317
|
||||
0b00000000, //byte 0 - CV_317
|
||||
0b00000000, //byte 1 - CV_318
|
||||
0b00000000, //byte 2 - CV_319
|
||||
0b00000000, //byte 3 - CV_320
|
||||
//F8 forward
|
||||
0b00000000, //byte 0 - CV_321
|
||||
0b00000001, //byte 1 - CV_322
|
||||
0b00000000, //byte 1 - CV_322
|
||||
0b00000000, //byte 2 - CV_323
|
||||
0b00000000, //byte 3 - CV_324
|
||||
//F8 reverse
|
||||
0b00000000, //byte 0 - CV_325
|
||||
0b00000001, //byte 1 - CV_326
|
||||
0b00000000, //byte 1 - CV_326
|
||||
0b00000000, //byte 2 - CV_327
|
||||
0b00000000, //byte 3 - CV_328
|
||||
//F9 forward
|
||||
0b00000000, //byte 0 - CV_329
|
||||
0b00000010, //byte 1 - CV_330
|
||||
0b00000000, //byte 1 - CV_330
|
||||
0b00000000, //byte 2 - CV_331
|
||||
0b00000000, //byte 3 - CV_332
|
||||
//F9 reverse
|
||||
0b00000000, //byte 0 - CV_333
|
||||
0b00000010, //byte 1 - CV_334
|
||||
0b00000000, //byte 1 - CV_334
|
||||
0b00000000, //byte 2 - CV_335
|
||||
0b00000000, //byte 3 - CV_336
|
||||
//F10 forward
|
||||
@@ -401,63 +411,63 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
|
||||
0b00000000, //byte 3 - CV_344
|
||||
//F11 forward
|
||||
0b00000000, //byte 0 - CV_345
|
||||
0b00001000, //byte 1 - CV_346
|
||||
0b00000000, //byte 1 - CV_346
|
||||
0b00000000, //byte 2 - CV_347
|
||||
0b00000000, //byte 3 - CV_348
|
||||
//F11 reverse
|
||||
0b00000000, //byte 0 - CV_349
|
||||
0b00001000, //byte 1 - CV_350
|
||||
0b00000000, //byte 1 - CV_350
|
||||
0b00000000, //byte 2 - CV_351
|
||||
0b00000000, //byte 3 - CV_352
|
||||
//F12 forward
|
||||
0b00000000, //byte 0 - CV_353
|
||||
0b00010000, //byte 1 - CV_354
|
||||
0b00000000, //byte 1 - CV_354
|
||||
0b00000000, //byte 2 - CV_355
|
||||
0b00000000, //byte 3 - CV_356
|
||||
//F12 reverse
|
||||
0b00000000, //byte 0 - CV_357
|
||||
0b00010000, //byte 1 - CV_358
|
||||
0b00000000, //byte 1 - CV_358
|
||||
0b00000000, //byte 2 - CV_359
|
||||
0b00000000, //byte 3 - CV_360
|
||||
//F13 forward
|
||||
0b00000000, //byte 0 - CV_361
|
||||
0b00100000, //byte 1 - CV_362
|
||||
0b00000000, //byte 1 - CV_362
|
||||
0b00000000, //byte 2 - CV_363
|
||||
0b00000000, //byte 3 - CV_364
|
||||
//F13 reverse
|
||||
0b00000000, //byte 0 - CV_365
|
||||
0b00100000, //byte 1 - CV_366
|
||||
0b00000000, //byte 1 - CV_366
|
||||
0b00000000, //byte 2 - CV_367
|
||||
0b00000000, //byte 3 - CV_368
|
||||
//F14 forward
|
||||
0b00000000, //byte 0 - CV_369
|
||||
0b01000000, //byte 1 - CV_370
|
||||
0b00000000, //byte 1 - CV_370
|
||||
0b00000000, //byte 2 - CV_371
|
||||
0b00000000, //byte 3 - CV_372
|
||||
//F14 reverse
|
||||
0b00000000, //byte 0 - CV_373
|
||||
0b01000000, //byte 1 - CV_374
|
||||
0b00000000, //byte 1 - CV_374
|
||||
0b00000000, //byte 2 - CV_375
|
||||
0b00000000, //byte 3 - CV_376
|
||||
//F15 forward
|
||||
0b00000000, //byte 0 - CV_377
|
||||
0b10000000, //byte 1 - CV_378
|
||||
0b00000000, //byte 1 - CV_378
|
||||
0b00000000, //byte 2 - CV_379
|
||||
0b00000000, //byte 3 - CV_380
|
||||
//F15 reverse
|
||||
0b00000000, //byte 0 - CV_381
|
||||
0b10000000, //byte 1 - CV_382
|
||||
0b00000000, //byte 1 - CV_382
|
||||
0b00000000, //byte 2 - CV_383
|
||||
0b00000000, //byte 3 - CV_384
|
||||
//F16 forward
|
||||
0b00000000, //byte 0 - CV_385
|
||||
0b00000000, //byte 1 - CV_386
|
||||
0b00000001, //byte 2 - CV_387
|
||||
0b00000000, //byte 2 - CV_387
|
||||
0b00000000, //byte 3 - CV_388
|
||||
//F16 reverse
|
||||
0b00000000, //byte 0 - CV_389
|
||||
0b00000000, //byte 1 - CV_390
|
||||
0b00000001, //byte 2 - CV_391
|
||||
0b00000000, //byte 2 - CV_391
|
||||
0b00000000, //byte 3 - CV_392
|
||||
//F17 forward
|
||||
0b00000000, //byte 0 - CV_393
|
||||
@@ -570,13 +580,13 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
|
||||
0b00000000, //byte 2 - CV_479
|
||||
0b00000000, //byte 3 - CV_480
|
||||
//F28 forward
|
||||
0b11111100, //byte 0 - CV_481
|
||||
0b00001111, //byte 1 - CV_482
|
||||
0b00000000, //byte 0 - CV_481
|
||||
0b00000000, //byte 1 - CV_482
|
||||
0b00000000, //byte 2 - CV_483
|
||||
0b00000000, //byte 3 - CV_484
|
||||
//F28 reverse
|
||||
0b11111100, //byte 0 - CV_485
|
||||
0b00001111, //byte 1 - CV_486
|
||||
0b00000000, //byte 0 - CV_485
|
||||
0b00000000, //byte 1 - CV_486
|
||||
0b00000000, //byte 2 - CV_487
|
||||
0b00000000, //byte 3 - CV_488
|
||||
//F29 forward
|
||||
|
||||
@@ -12,6 +12,7 @@ Features
|
||||
- 6 GPIO for lighter loads or custom applications
|
||||
- Programmable on programming track
|
||||
- CV Function Mapping
|
||||
- Board size of 25x20 mm
|
||||
|
||||
Getting Started
|
||||
------------
|
||||
@@ -29,11 +30,12 @@ License
|
||||
Further details about the project can be found here: [RP2040-Decoder Wiki](https://github.com/GabrielKoppenstein/pico-decoder/wiki)
|
||||
|
||||
Note: The decoder is still in early development, there might (will) be bugs as its not tested that much yet.
|
||||
So suggestions on how to improve things and bug reports are always much appreciated.
|
||||
The wiki is also work in progress and will be updated to be as comprehensive as possible.
|
||||
|
||||
------------
|
||||
<p float="left">
|
||||
<img src="/docs/png/RP2040-Decoder-Rev_0_2_front.png" alt="PCB Front Side Image" title="Front" width="500"/>
|
||||
<img src="/docs/png/RP2040-Decoder-Rev_0_2_back.png" alt="PCB Back Side Image" title="Back" width="500"/>
|
||||
<img src="/docs/png/RP2040-Decoder-Rev_0_2_front.png" alt="PCB Front Side Image" title="Front" width="400"/>
|
||||
<img src="/docs/png/RP2040-Decoder-Rev_0_2_back.png" alt="PCB Back Side Image" title="Back" width="400"/>
|
||||
</p>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
bool target_direction = true; //Forward = true - Reverse = false
|
||||
uint target_speed_step = 128; //128 = Stop (Forward Direction)
|
||||
const uint8_t *CV_ARRAY_FLASH = (const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET);
|
||||
bool active_functions[SIZE_ACTIVE_FUNCTIONS] = {false};
|
||||
uint64_t last_bits = 0;
|
||||
bool reset_package_flag = false;
|
||||
absolute_time_t falling_edge_time,rising_edge_time;
|
||||
@@ -150,27 +149,50 @@ void program_mode(uint8_t number_of_bytes, const uint8_t byte_array[]){
|
||||
multicore_launch_core1(core1_entry);
|
||||
}
|
||||
}
|
||||
void set_outputs() {
|
||||
uint32_t GPIO_to_be_set = 0;
|
||||
uint32_t get_32bit_CV (uint16_t CV_start_index){
|
||||
uint8_t byte_0 = CV_ARRAY_FLASH[CV_start_index];
|
||||
uint8_t byte_1 = CV_ARRAY_FLASH[CV_start_index+1];
|
||||
uint8_t byte_2 = CV_ARRAY_FLASH[CV_start_index+2];
|
||||
uint8_t byte_3 = CV_ARRAY_FLASH[CV_start_index+3];
|
||||
return (byte_0) + (byte_1<<8) + (byte_2<<16) + (byte_3<<24);
|
||||
}
|
||||
uint16_t get_16bit_CV (uint16_t CV_start_index){
|
||||
uint8_t byte_0 = CV_ARRAY_FLASH[CV_start_index];
|
||||
uint8_t byte_1 = CV_ARRAY_FLASH[CV_start_index+1];
|
||||
return (byte_0) + (byte_1<<8);
|
||||
}
|
||||
void set_outputs(uint32_t active_functions) {
|
||||
uint32_t slice_mask = 0;
|
||||
uint32_t outputs_to_enable = 0;
|
||||
uint32_t outputs_to_enable_PWM = get_32bit_CV(111);
|
||||
for (uint8_t i = 0; i < 32; i++) {
|
||||
if (active_functions[i]) {
|
||||
uint8_t func_cv_0 = CV_ARRAY_FLASH[260 + i * 8 - 4 * target_direction];
|
||||
uint8_t func_cv_1 = CV_ARRAY_FLASH[261 + i * 8 - 4 * target_direction];
|
||||
uint8_t func_cv_2 = CV_ARRAY_FLASH[262 + i * 8 - 4 * target_direction];
|
||||
uint8_t func_cv_3 = CV_ARRAY_FLASH[263 + i * 8 - 4 * target_direction];
|
||||
uint32_t func_cv = (func_cv_0) + (func_cv_1 << 8) + (func_cv_2 << 16) + (func_cv_3 << 24);
|
||||
GPIO_to_be_set |= func_cv;
|
||||
if ( (active_functions>>i) & 1 ){
|
||||
outputs_to_enable |= get_32bit_CV(i * 8 + 260 - 4 * target_direction);
|
||||
}
|
||||
}
|
||||
GPIO_to_be_set &= ALLOWED_GPIO_MASK;
|
||||
gpio_put_masked(ALLOWED_GPIO_MASK,GPIO_to_be_set);
|
||||
}
|
||||
void update_active_functions(uint8_t function_number, uint8_t input_byte, uint8_t count) {
|
||||
uint8_t mask = 0b00000001;
|
||||
for (uint8_t i = 0; i < count; i++) {
|
||||
active_functions[i + function_number] = (input_byte & mask) == 0 ? 0 : 1;
|
||||
mask = mask << 1;
|
||||
outputs_to_enable &= GPIO_ALLOWED; // Prevent illegal GPIO
|
||||
outputs_to_enable_PWM &= outputs_to_enable; // Outputs with PWM to be enabled
|
||||
outputs_to_enable &= ~outputs_to_enable_PWM; // Outputs without PWM to be enabled
|
||||
gpio_put_masked(GPIO_ALLOWED, outputs_to_enable);
|
||||
uint32_t temp_mask = 1;
|
||||
for (uint8_t i = 0; i < 32; ++i) {
|
||||
if(temp_mask & outputs_to_enable_PWM){
|
||||
uint32_t slice_num = pwm_gpio_to_slice_num(i);
|
||||
slice_mask |= (1<<slice_num);
|
||||
}
|
||||
temp_mask<<=1;
|
||||
}
|
||||
pwm_set_mask_enabled(slice_mask);
|
||||
}
|
||||
void update_active_functions(uint32_t function_byte, uint8_t clr_bit_ind) {
|
||||
static uint32_t active_functions;
|
||||
static uint32_t prev_active_func;
|
||||
function_byte &= ~(clr_bit_arr[clr_bit_ind]);
|
||||
active_functions &= clr_bit_arr[clr_bit_ind];
|
||||
active_functions |= function_byte;
|
||||
uint32_t changes = active_functions ^ prev_active_func;
|
||||
if(changes)set_outputs(active_functions);
|
||||
prev_active_func = active_functions;
|
||||
}
|
||||
bool error_detection(int8_t number_of_bytes, const uint8_t byte_array[]) {
|
||||
//Bitwise XOR for all Bytes -> Successful result is: "0000 0000"
|
||||
@@ -217,19 +239,14 @@ void instruction_evaluation(uint8_t number_of_bytes,const uint8_t byte_array[])
|
||||
// start of transmission -> ... -> command_byte_n -> ... -> command_byte_0 -> ... -> end of transmission
|
||||
if (is_long_address(number_of_bytes,byte_array)) {
|
||||
command_byte_start_index = number_of_bytes - 3;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
command_byte_start_index = number_of_bytes - 2;
|
||||
}
|
||||
command_byte_n = byte_array[command_byte_start_index];
|
||||
//0011-1111 (128 Speed Step Control) - 2 Byte length
|
||||
if (command_byte_n == 0b00111111){
|
||||
target_speed_step = byte_array[command_byte_start_index - 1];
|
||||
//Check for offset setup
|
||||
uint sum = (CV_ARRAY_FLASH[53]) + (CV_ARRAY_FLASH[54]) + (CV_ARRAY_FLASH[55]) + (CV_ARRAY_FLASH[56]);
|
||||
if( !sum && target_speed_step != 128 && target_speed_step) {
|
||||
uint8_t arr[4] = {125,7,6,124};
|
||||
program_mode(4,arr);
|
||||
}
|
||||
if(target_speed_step>127) {
|
||||
target_direction = true; //Forward
|
||||
}
|
||||
@@ -239,48 +256,42 @@ void instruction_evaluation(uint8_t number_of_bytes,const uint8_t byte_array[])
|
||||
}
|
||||
// 10XX-XXXX (Function Group Instruction)
|
||||
else if (command_byte_n >> 6 == 0b00000010){
|
||||
if (command_byte_n >> 5 == 0b00000100) // Functions F0-F4
|
||||
{
|
||||
update_active_functions(0, command_byte_n >> 4, 1); //F0
|
||||
update_active_functions(1, command_byte_n, 4); //F1-F4
|
||||
} else {
|
||||
switch (command_byte_n >> 4) {
|
||||
case 0b00001011: // F5-F8
|
||||
update_active_functions(5, command_byte_n, 4);
|
||||
break;
|
||||
case 0b00001010: // F9-F12
|
||||
update_active_functions(9, command_byte_n, 4);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (command_byte_n >> 4) {
|
||||
case 0b00001011: // F5-F8
|
||||
update_active_functions((command_byte_n << 5),1);
|
||||
break;
|
||||
case 0b00001010: // F9-F12
|
||||
update_active_functions((command_byte_n << 9),2);
|
||||
break;
|
||||
default: // F0-F4
|
||||
update_active_functions(((command_byte_n << 1) + (command_byte_n >> 4)),0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Feature Expansion Instruction 110X-XXXX
|
||||
else if (command_byte_n >> 5 == 0b00000110)
|
||||
{
|
||||
else if (command_byte_n >> 5 == 0b00000110) {
|
||||
switch (command_byte_n) {
|
||||
case 0b11011110: // F13-F20
|
||||
update_active_functions(13, byte_array[command_byte_start_index - 1], 8);
|
||||
update_active_functions((byte_array[command_byte_start_index - 1] << 13),3);
|
||||
break;
|
||||
case 0b11011111: // F21-F28
|
||||
update_active_functions(21, byte_array[command_byte_start_index - 1], 8);
|
||||
update_active_functions((byte_array[command_byte_start_index - 1] << 21),4);
|
||||
break;
|
||||
case 0b11011000: // F29-F31
|
||||
update_active_functions(29, byte_array[command_byte_start_index - 1], 3);
|
||||
update_active_functions((byte_array[command_byte_start_index - 1] << 29),5);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
set_outputs();
|
||||
}
|
||||
bool reset_package_check(uint8_t number_of_bytes,const uint8_t byte_array[]){
|
||||
if (byte_array[number_of_bytes-1] == 0b00000000 && byte_array[number_of_bytes-2] == 0b00000000){
|
||||
target_speed_step = 1;
|
||||
//update_active_functions(0,0,37);
|
||||
return true;
|
||||
}else {
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -321,10 +332,10 @@ void evaluation(){
|
||||
reset_package_flag = false;
|
||||
instruction_evaluation(number_of_bytes,byte_array);
|
||||
}
|
||||
else if (reset_package_flag){
|
||||
else if (reset_package_flag) {
|
||||
program_mode(number_of_bytes,byte_array);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
reset_package_flag = reset_package_check(number_of_bytes,byte_array);
|
||||
}
|
||||
}
|
||||
@@ -338,21 +349,45 @@ void track_signal_rise(unsigned int gpio, long unsigned int events) {
|
||||
void track_signal_fall(unsigned int gpio, long unsigned int events) {
|
||||
falling_edge_time = get_absolute_time();
|
||||
int64_t time_logical_high = absolute_time_diff_us(rising_edge_time,falling_edge_time);
|
||||
if(time_logical_high > 87){
|
||||
if(time_logical_high > 87) {
|
||||
writeLastBit(0);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
writeLastBit(1);
|
||||
}
|
||||
evaluation();
|
||||
gpio_set_irq_enabled_with_callback(DCC_INPUT_PIN, GPIO_IRQ_EDGE_FALL, false, &track_signal_fall);
|
||||
gpio_set_irq_enabled_with_callback(DCC_INPUT_PIN, GPIO_IRQ_EDGE_RISE, true, &track_signal_rise);
|
||||
}
|
||||
void init_outputs(){
|
||||
gpio_init_mask(GPIO_ALLOWED);
|
||||
gpio_set_dir_out_masked(GPIO_ALLOWED);
|
||||
uint32_t Outputs_with_PWM_enabled = get_32bit_CV(111);
|
||||
uint32_t slice, channel;
|
||||
uint16_t wrap, level;
|
||||
for (uint8_t i = 0; i < 32; ++i) {
|
||||
if ( (Outputs_with_PWM_enabled>>i) & 1 ){
|
||||
slice = pwm_gpio_to_slice_num(i);
|
||||
channel = pwm_gpio_to_channel(i); //0 for A, 1 for B ?
|
||||
wrap = get_16bit_CV(115 + slice*7);
|
||||
level = get_16bit_CV(118 + 7*slice+ 2*channel);
|
||||
gpio_set_function(i,GPIO_FUNC_PWM);
|
||||
pwm_set_wrap(slice,wrap);
|
||||
pwm_set_gpio_level(i,level);
|
||||
pwm_set_clkdiv_int_frac(slice,CV_ARRAY_FLASH[117+7*slice],0);
|
||||
}
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
printf("core0 init...\n");
|
||||
//gpio_init_mask(ALLOWED_GPIO_MASK);
|
||||
//gpio_set_dir_out_masked(ALLOWED_GPIO_MASK);
|
||||
init_outputs();
|
||||
//Check for offset setup
|
||||
uint sum = (CV_ARRAY_FLASH[53]) + (CV_ARRAY_FLASH[54]) + (CV_ARRAY_FLASH[55]) + (CV_ARRAY_FLASH[56]);
|
||||
if( !sum && target_speed_step != 128 && target_speed_step) {
|
||||
uint8_t arr[4] = {125,7,6,124};
|
||||
program_mode(4,arr);
|
||||
}
|
||||
multicore_launch_core1(core1_entry);
|
||||
gpio_init(DCC_INPUT_PIN);
|
||||
gpio_set_dir(DCC_INPUT_PIN, GPIO_IN);
|
||||
|
||||
@@ -10,17 +10,20 @@
|
||||
#include "pico/float.h"
|
||||
#define SIZE_BYTE_ARRAY 5
|
||||
#define SIZE_ACTIVE_FUNCTIONS 32
|
||||
#define DCC_INPUT_PIN 4
|
||||
//Default
|
||||
//#define ALLOWED_GPIO_MASK 0b00000000000000000000111111111100 //prevents setting GPIO's that are not allowed (ADC, PWM, ...)
|
||||
//Custom
|
||||
#define ALLOWED_GPIO_MASK 0b00000000000000000000001111111100 //prevents setting GPIO's that are not allowed (ADC, PWM, ...)
|
||||
#define PACKAGE_3_BYTES 0b11111111110000000000000000000000000001
|
||||
#define PACKAGE_MASK_3_BYTES 0b11111111111000000001000000001000000001
|
||||
#define PACKAGE_4_BYTES 0b11111111110000000000000000000000000000000000001
|
||||
#define PACKAGE_MASK_4_BYTES 0b11111111111000000001000000001000000001000000001
|
||||
#define PACKAGE_5_BYTES 0b11111111110000000000000000000000000000000000000000000001
|
||||
#define PACKAGE_MASK_5_BYTES 0b11111111111000000001000000001000000001000000001000000001
|
||||
const uint32_t clr_bit_arr[6] = {
|
||||
0b11111111111111111111111111100000, // Clear Bits 0-4 (F0-F4)
|
||||
0b11111111111111111111111000011111, // Clear Bits 5-8 (F5-F8)
|
||||
0b11111111111111111110000111111111, // Clear Bits 9-12 (F9-F12)
|
||||
0b11111111111000000001111111111111, // Clear Bits 13-20 (F13-F20)
|
||||
0b11100000000111111111111111111111, // Clear Bits 21-28 (F21-F28)
|
||||
0b00011111111111111111111111111111, // Clear Bits 29-31 (F29-F31)
|
||||
};
|
||||
int8_t check_for_package();
|
||||
void writeLastBit(bool bit) ;
|
||||
void bits_to_byte_array(int8_t number_of_bytes,uint8_t byte_array[]) ;
|
||||
@@ -30,8 +33,8 @@ void verify_cv_byte(uint16_t cv_address, uint8_t cv_data);
|
||||
void write_cv_byte(uint16_t cv_index, uint8_t cv_data);
|
||||
bool reset_package_check(uint8_t number_of_bytes,const uint8_t byte_array[]);
|
||||
void program_mode(uint8_t number_of_bytes, const uint8_t byte_array[]);
|
||||
void set_outputs() ;
|
||||
void update_active_functions(uint8_t function_number, uint8_t input_byte, uint8_t count) ;
|
||||
void set_outputs(uint32_t active_functions);
|
||||
void update_active_functions(uint32_t byte, uint8_t clr_bit_ind) ;
|
||||
bool error_detection(int8_t number_of_bytes, const uint8_t byte_array[]) ;
|
||||
bool is_long_address(uint8_t number_of_bytes, const uint8_t byte_array[]) ;
|
||||
bool address_evaluation(uint8_t number_of_bytes,const uint8_t byte_array[]) ;
|
||||
|
||||
@@ -149,8 +149,8 @@ bool pid_control(struct repeating_timer *t){
|
||||
if (pid.output < 0 || !latest_target) pid.output = 0;
|
||||
else if (pid.output > pid.max_output) pid.output = pid.max_output;
|
||||
adjust_pwm_level(pid.output);
|
||||
printf("o: %d\n",pid.output);
|
||||
printf("e: %d\n",pid.e);
|
||||
//printf("o: %d\n",pid.output);
|
||||
//printf("e: %d\n",pid.e);
|
||||
adc_fifo_drain();
|
||||
pid.direction_prev = target_direction;
|
||||
pid.e_prev = pid.e;
|
||||
@@ -172,10 +172,11 @@ void init_pid(){
|
||||
pid.direction_prev = target_direction;
|
||||
pid.max_output = _125M/(CV_ARRAY_FLASH[8]*100+10000);
|
||||
}
|
||||
void init_pwm(uint8_t gpio) {
|
||||
uint16_t wrap_counter = _125M/(CV_ARRAY_FLASH[8]*100+10000);
|
||||
void init_motor_pwm(uint8_t gpio) {
|
||||
uint16_t wrap_counter = _125M/(CV_ARRAY_FLASH[8]*100+10000); // 125MHz / f_pwm
|
||||
init_offsets(wrap_counter);
|
||||
uint32_t slice_num = pwm_gpio_to_slice_num(gpio);
|
||||
pwm_set_clkdiv_int_frac(slice_num,CV_ARRAY_FLASH[46],0);
|
||||
pwm_set_wrap(slice_num, wrap_counter);
|
||||
pwm_set_gpio_level(gpio,0);
|
||||
pwm_set_enabled(slice_num, true);
|
||||
@@ -189,8 +190,8 @@ void core1_entry() {
|
||||
adc_gpio_init(FWD_V_EMF_ADC_PIN);
|
||||
adc_gpio_init(REV_V_EMF_ADC_PIN);
|
||||
adc_fifo_setup(true,false,0,false,false);
|
||||
init_pwm(MOTOR_FWD_PIN);
|
||||
init_pwm(MOTOR_REV_PIN);
|
||||
init_motor_pwm(MOTOR_FWD_PIN);
|
||||
init_motor_pwm(MOTOR_REV_PIN);
|
||||
}
|
||||
init_pid();
|
||||
alarm_pool_add_repeating_timer_ms(alarm_pool_create(0,1),
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
#pragma once
|
||||
#include "shared.h"
|
||||
#define FWD_V_EMF_ADC_PIN 26
|
||||
#define REV_V_EMF_ADC_PIN 27
|
||||
uint16_t calc_end_target();
|
||||
bool speed_helper();
|
||||
void adjust_pwm_level(uint16_t level);
|
||||
@@ -15,4 +13,4 @@ void init_offsets(uint16_t lvl_max);
|
||||
uint32_t offset();
|
||||
bool pid_control(struct repeating_timer *t);
|
||||
void init_pid();
|
||||
void init_pwm(uint8_t gpio);
|
||||
void init_motor_pwm(uint8_t gpio);
|
||||
@@ -16,8 +16,14 @@
|
||||
#include "hardware/irq.h"
|
||||
#define _125M 125000000
|
||||
#define ADC_OFFSET 13
|
||||
#define MOTOR_FWD_PIN 22
|
||||
#define MOTOR_REV_PIN 23
|
||||
#define DCC_INPUT_PIN 4u
|
||||
#define MOTOR_FWD_PIN 22u
|
||||
#define MOTOR_REV_PIN 23u
|
||||
#define FWD_V_EMF_ADC_PIN 26u
|
||||
#define REV_V_EMF_ADC_PIN 27u
|
||||
#define GPIO_USED 0b00001100110000000011111000011111u
|
||||
#define GPIO_ILLEGAL (DCC_INPUT_PIN | MOTOR_FWD_PIN | MOTOR_REV_PIN | FWD_V_EMF_ADC_PIN | REV_V_EMF_ADC_PIN)
|
||||
#define GPIO_ALLOWED GPIO_USED & ~GPIO_ILLEGAL //GPIO mask to prevent setting illegal GPIOs (ADC, Motor, DCC Input Pin)
|
||||
#define FLASH_TARGET_OFFSET (PICO_FLASH_SIZE_BYTES-FLASH_SECTOR_SIZE) //This Offset should be far enough away from program data
|
||||
extern repeating_timer_t pid_control_timer;
|
||||
extern repeating_timer_t speed_helper_timer;
|
||||
|
||||
Reference in new issue
Block a user