-
Notifications
You must be signed in to change notification settings - Fork 10
Add logic tree for conditional voltage setting based on freq request #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: overclock
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,52 @@ | ||
| set(overclocks 0;1) | ||
|
|
||
| foreach (overclock IN LISTS overclocks) | ||
| # Compute firmware name | ||
| set(firmware_name prawnblaster) | ||
| if(PICO_PLATFORM MATCHES "^rp2350") | ||
| set(firmware_name "${firmware_name}_rp2350") | ||
| else() | ||
| set(firmware_name "${firmware_name}_${PICO_PLATFORM}") | ||
| endif() | ||
| if(overclock) | ||
| set(firmware_name "${firmware_name}_overclock") | ||
| endif() | ||
|
|
||
| add_executable(${firmware_name} prawnblaster.cpp fast_serial.c) | ||
|
|
||
| pico_generate_pio_header(${firmware_name} ${CMAKE_CURRENT_LIST_DIR}/pseudoclock.pio) | ||
|
|
||
| # Pass in number of instructions to firmware as a compiler definition | ||
| set(num_instructions 30000) | ||
| if(PICO_PLATFORM MATCHES "^rp2350") | ||
| set(num_instructions 60000) | ||
| endif() | ||
| target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_NUM_INSTRUCTIONS=${num_instructions}") | ||
|
|
||
| # Pass in board type to firmware as a compiler definition. Note that PICO_BOARD is passed in by the SDK, but it's passed in a string which isn't valid and so I can't use it... | ||
| # This is also, to some extent, a duplicate of the above PRAWNBLASTER_NUM_INSTRUCTIONS but I think it makes sense to keep these seperate. | ||
| if (PICO_BOARD STREQUAL "pico") | ||
| target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_PICO_BOARD=1") | ||
| elseif (PICO_BOARD STREQUAL "pico2") | ||
| target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_PICO_BOARD=2") | ||
| else () | ||
| message(FATAL_ERROR "Unsupported PICO_BOARD") | ||
| endif() | ||
|
|
||
|
|
||
| # Pass in overclock state to firmware as a compiler definition | ||
| if(overclock) | ||
| target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_OVERCLOCK=1") | ||
| endif() | ||
|
|
||
| # Pull in our pico_stdlib which aggregates commonly used features | ||
| target_link_libraries(${firmware_name} pico_stdlib hardware_pio pico_multicore pico_unique_id hardware_clocks hardware_dma hardware_vreg tinyusb_device tinyusb_board) | ||
| target_include_directories(${firmware_name} PRIVATE .) | ||
|
|
||
| # create map/bin/hex/uf2 file etc. | ||
| pico_add_extra_outputs(${firmware_name}) | ||
|
|
||
| endforeach() | ||
| # Compute firmware name | ||
| set(firmware_name prawnblaster) | ||
| if(PICO_PLATFORM MATCHES "^rp2350") | ||
| set(firmware_name "${firmware_name}_rp2350") | ||
| else() | ||
| set(firmware_name "${firmware_name}_${PICO_PLATFORM}") | ||
| endif() | ||
| # if(overclock) | ||
| # set(firmware_name "${firmware_name}_overclock") | ||
| # endif() | ||
|
|
||
| add_executable(${firmware_name} prawnblaster.cpp fast_serial.c) | ||
|
|
||
| pico_generate_pio_header(${firmware_name} ${CMAKE_CURRENT_LIST_DIR}/pseudoclock.pio) | ||
|
|
||
| # Pass in number of instructions to firmware as a compiler definition | ||
| set(num_instructions 30000) | ||
|
|
||
| # Pass in freq limits to firmware in MHz | ||
| set(normal_freq_limit 133) | ||
| set(overclock_freq_limit 200) | ||
|
|
||
| if(PICO_PLATFORM MATCHES "^rp2350") | ||
| set(num_instructions 60000) | ||
| set(normal_freq_limit 150) | ||
| endif() | ||
| target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_NUM_INSTRUCTIONS=${num_instructions}") | ||
| target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_NORMAL_FREQ_LIMIT=${normal_freq_limit}") | ||
| target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_OVERCLOCK_FREQ_LIMIT=${overclock_freq_limit}") | ||
|
|
||
| # Pass in board type to firmware as a compiler definition. Note that PICO_BOARD is passed in by the SDK, but it's passed in a string which isn't valid and so I can't use it... | ||
| # This is also, to some extent, a duplicate of the above PRAWNBLASTER_NUM_INSTRUCTIONS but I think it makes sense to keep these seperate. | ||
| if (PICO_BOARD STREQUAL "pico") | ||
| target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_PICO_BOARD=1") | ||
| elseif (PICO_BOARD STREQUAL "pico2") | ||
| target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_PICO_BOARD=2") | ||
| else () | ||
| message(FATAL_ERROR "Unsupported PICO_BOARD") | ||
| endif() | ||
|
|
||
|
|
||
| # Pass in overclock state to firmware as a compiler definition | ||
| if(overclock) | ||
| target_compile_definitions(${firmware_name} PUBLIC "PRAWNBLASTER_OVERCLOCK=1") | ||
| endif() | ||
|
|
||
| # Pull in our pico_stdlib which aggregates commonly used features | ||
| target_link_libraries(${firmware_name} pico_stdlib hardware_pio pico_multicore pico_unique_id hardware_clocks hardware_dma hardware_vreg tinyusb_device tinyusb_board) | ||
| target_include_directories(${firmware_name} PRIVATE .) | ||
|
|
||
| # create map/bin/hex/uf2 file etc. | ||
| pico_add_extra_outputs(${firmware_name}) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,10 @@ const char VERSION[16] = "1.2.0-overclock"; | |
|
|
||
| int DEBUG; | ||
|
|
||
| // Freq limits in MHz | ||
| constexpr unsigned int normal_freq_limit = PRAWNBLASTER_NORMAL_FREQ_LIMIT; | ||
| constexpr unsigned int overclock_freq_limit = PRAWNBLASTER_OVERCLOCK_FREQ_LIMIT; | ||
|
|
||
| // Can't seem to have this be used to define array size even though it's a constant | ||
| constexpr unsigned int max_instructions = PRAWNBLASTER_NUM_INSTRUCTIONS; | ||
| constexpr unsigned int instruction_array_size = 2 * max_instructions + 8; | ||
|
|
@@ -1038,13 +1042,17 @@ void loop() | |
| } | ||
| else | ||
| { | ||
| if (freq >= 150 * MHZ) | ||
| if (freq > overclock_freq_limit * MHZ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a small concern about this logic tree. If we go from an overclock state to a normal state, the Vreg will be set down before the frequency change, potentially leading to instability. We should test that hypothesis thoroughly to see if it is a problem before actually changing code though. |
||
| { | ||
| vreg_set_voltage(VREG_VOLTAGE_1_30); | ||
| } | ||
| if (freq < 150 * MHZ) | ||
| { | ||
| vreg_set_voltage(VREG_VOLTAGE_1_10); | ||
| fast_serial_printf("WARNING: Requested freq > normal bounds, setting voltage = 1.3 V\n"); | ||
| vreg_set_voltage(VREG_VOLTAGE_1_30); | ||
| } | ||
| else if (freq > normal_freq_limit * MHZ && freq <= overclock_freq_limit * MHZ) | ||
| { | ||
| vreg_set_voltage(VREG_VOLTAGE_1_20); | ||
| } | ||
| else { | ||
| vreg_set_voltage(VREG_VOLTAGE_1_10); | ||
| } | ||
| if (DEBUG) | ||
| { | ||
|
|
@@ -1057,21 +1065,6 @@ void loop() | |
| else | ||
| { | ||
|
|
||
| #ifndef PRAWNBLASTER_OVERCLOCK | ||
| # if PRAWNBLASTER_PICO_BOARD == 1 | ||
| if (freq > 200 * MHZ) | ||
| # elif PRAWNBLASTER_PICO_BOARD == 2 | ||
| if (freq > 150 * MHZ) | ||
| # else | ||
| # error "Unsupported PICO_BOARD" | ||
| # endif // PICO_BOARD | ||
| // Do validation checking on values provided | ||
| { | ||
| fast_serial_printf("Invalid clock frequency specified\r\n"); | ||
| return; | ||
| } | ||
| #endif //PRAWNBLASTER_OVERCLOCK | ||
|
|
||
| // Set new clock frequency | ||
| if (src == 0) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.