Commit 8ba94b9b authored by David Andruczyk's avatar David Andruczyk

Ported to work with SerialUI 2.x (testing with tag 2.1.6)

parent 8166c925
......@@ -5,3 +5,5 @@ Sweep_Notes
wheels_default.jsw
src
lib/*
.pioenvs
.piolibdeps
......@@ -47,7 +47,7 @@ extern volatile bool sweep_lock;
extern volatile uint8_t output_invert_mask; /* Don't invert anything */
extern volatile uint8_t sweep_direction;
extern volatile byte total_sweep_stages;
extern volatile uint8_t sweep_stage;
extern volatile int8_t sweep_stage;
extern volatile uint8_t prescaler_bits;
extern volatile uint8_t last_prescaler_bits;
extern volatile uint8_t mode;
......@@ -65,7 +65,7 @@ extern sweep_step *SweepSteps; /* Global pointer for the sweep steps */
wheels Wheels[MAX_WHEELS] = {
/* Pointer to friendly name string, pointer to edge array, RPM Scaler, Number of edges in the array */
{ dizzy_four_cylinder_friendly_name, dizzy_four_cylinder, 0.03333, 4 },
/* { dizzy_six_cylinder_friendly_name, dizzy_six_cylinder, 0.05, 6 },
{ dizzy_six_cylinder_friendly_name, dizzy_six_cylinder, 0.05, 6 },
{ dizzy_eight_cylinder_friendly_name, dizzy_eight_cylinder, 0.06667, 8 },
{ sixty_minus_two_friendly_name, sixty_minus_two, 1.0, 120 },
{ sixty_minus_two_with_cam_friendly_name, sixty_minus_two_with_cam, 1.0, 240 },
......@@ -105,7 +105,6 @@ wheels Wheels[MAX_WHEELS] = {
{ twenty_four_minus_one_with_cam_friendly_name, twenty_four_minus_one_with_cam, 0.4 , 96 },
{ four_g_sixty_three_with_cam_friendly_name, four_g_sixty_three_with_cam, 0.4, 720 },
{ seadoo_thirty_six_minus_two_friendly_name, seadoo_thirty_six_minus_two, 0.6, 72 },
*/
};
......@@ -154,12 +153,20 @@ ISR(TIMER2_COMPA_vect) {
// PORTD = (0 << 7);
return;
}
if (sweep_lock) // semaphore to protect around changes/critical sections
/* IF the sweep parameters are being changed, abort the ISR so we
* don't use half-set values and get things really screwed up
*/
if (sweep_lock)
{
// PORTD = (0 << 7);
return;
}
sweep_lock = true;
sweep_lock = true; /* Set semaphore */
/* Check flag to see if we need to reset the prescaler for the timer.
* if so, clear that flag, set another for the high speed ISR to check for
* and reprogram the timer when it next runs. Store the last prescaler bits
* for comparison against during sweep stage changes
*/
if (sweep_reset_prescaler)
{
sweep_reset_prescaler = false;
......@@ -170,24 +177,45 @@ ISR(TIMER2_COMPA_vect) {
/* Sweep code */
if (sweep_direction == ASCENDING)
{
oc_remainder += SweepSteps[sweep_stage].remainder_per_isr;
/* IF the total is over the threshold we increment the TCNT factor
* for each multiple it is over by
/* So we don't have to work in floating point (super expensive and slow)
* we work in a larger scale and keep the remainder per ISR around as
* an integer, when that overcomes the threshold we increment the
* fractional component and decrement the remainder by that same threshold
*/
oc_remainder += SweepSteps[sweep_stage].remainder_per_isr;
while (oc_remainder > FACTOR_THRESHOLD)
{
fraction++;
oc_remainder -= FACTOR_THRESHOLD;
}
/* new_OCR1A is the new Output Compare Register (1a) value, it
* determines how long it is between each tooth interrupt. The longer
* it is the LOWER the RPM of hte signal will be. NOTE: this value
* goes hand in hand with the prescaler, as that determines the divisor
* for the clock, so you need to take both of them into account
* tcnt_per_isr is the tooth count CHANGE per ISR (accelerating or
* decelerating depending on sweep direction). Since we're in the
* ascending side (RPM going up, OCR1A going down) we will be reducing
* new_OCR1A by tcnt_per_isr + whatever fractional amount until it's
* below the ending_ocr value, at that point this stage is completed
* and we increment the stage.
*/
if (new_OCR1A > SweepSteps[sweep_stage].ending_ocr)
{
new_OCR1A -= (SweepSteps[sweep_stage].tcnt_per_isr + fraction);
fraction = 0;
}
/* Stage endd, increament stage counter, reset remainder to 0 */
else /* END of the stage, find out where we are */
{
sweep_stage++;
oc_remainder = 0;
/* Check if there's a next stage by making sure we're not over the end,
* if so, then reset new_OCR1A to the beginning value from the
* structure, check if hte prescaler bits need to change, if they do
* we set a flag to do so on the next ISR iteration (1ms later)
*/
if (sweep_stage < total_sweep_stages)
{
/* Toggle when changing stages */
......@@ -197,6 +225,11 @@ ISR(TIMER2_COMPA_vect) {
if (SweepSteps[sweep_stage].prescaler_bits != last_prescaler_bits)
sweep_reset_prescaler = true;
}
/* End of sweep stages, reverse direction, decrement sweep_stage by one
* Set the direction flag to descending, Reset new_OCR1A to the end
* value (remember opposite direction!), Check prescaler bits and
* set flag to reset if necessary
*/
else /* END of line, time to reverse direction */
{
sweep_stage--; /*Bring back within limits */
......@@ -204,11 +237,15 @@ ISR(TIMER2_COMPA_vect) {
new_OCR1A = SweepSteps[sweep_stage].ending_ocr;
if (SweepSteps[sweep_stage].prescaler_bits != last_prescaler_bits)
sweep_reset_prescaler = true;
PORTD |= 1 << 7; /* Debugginga, ascending */
//PORTD |= 1 << 7; /* Debugging, ascending */
}
/* Reset fractionals or next round */
}
}
/* Descending RPM, which means new_OCR1A should be CLIMBING,
* increment the oc_remainder, check if it's over the threshold, if
* so increment the fraction and decrement the remainder by the fraction.
*/
else /* Descending */
{
oc_remainder += SweepSteps[sweep_stage].remainder_per_isr;
......@@ -217,21 +254,37 @@ ISR(TIMER2_COMPA_vect) {
fraction++;
oc_remainder -= FACTOR_THRESHOLD;
}
/* Check if new_OCR1A is less than the sweep stage threshold, if it
* still is, increase new_OCR1A by the tooth count change per ISR and the
* fractional component
*/
if (new_OCR1A < SweepSteps[sweep_stage].beginning_ocr)
{
new_OCR1A += (SweepSteps[sweep_stage].tcnt_per_isr + fraction);
fraction = 0;
}
/* new_OCR1A has exceeded the OCR threshold, decrement the sweep stage,
* reset the remainder to 0 an check to make sure sweep_stage hasn't gone
* below zero
*/
else /* End of stage */
{
sweep_stage--;
oc_remainder = 0;
/* Check that sweep_stage hasn't gone negative, if not, reset
* new_OCR1a to the starting value for this stage, check prescaler
* bits against last ones and set flag if needed
*/
if (sweep_stage >= 0)
{
new_OCR1A = SweepSteps[sweep_stage].ending_ocr;
if (SweepSteps[sweep_stage].prescaler_bits != last_prescaler_bits)
sweep_reset_prescaler = true;
}
/* Sweep stage went negative, bring it back to zero, flip the direction
* back to ASCENDING, reset new_OCR1A to starting value for this stage
* and check prescaler bits and set flag to update if needed
*/
else /*End of the line */
{
sweep_stage++; /*Bring back within limits */
......
......@@ -47,7 +47,7 @@ volatile bool sweep_lock = false;
volatile uint8_t output_invert_mask = 0x00; /* Don't invert anything */
volatile uint8_t sweep_direction = ASCENDING;
volatile byte total_sweep_stages = 0;
volatile uint8_t sweep_stage = 0;
volatile int8_t sweep_stage = 0;
volatile uint8_t prescaler_bits = 0;
volatile uint8_t last_prescaler_bits = 0;
volatile uint8_t mode = FIXED_RPM;
......
......@@ -28,7 +28,6 @@
#define TMP_RPM_SHIFT 4 /* x16, 0-16384 RPM via pot */
#define TMP_RPM_CAP 16384 /* MAX RPM via pot control */
#define FACTOR_THRESHOLD 1000000
#define MORE_LINEAR_SWEEP 1
//#define SUI_NO_INCLUDE_EXTRA_SAFETYCHECKS
#define LOG_2 0.30102999566
......
......@@ -28,9 +28,9 @@
extern SUI::SerialUI mySUI;
void loop() {
uint16_t tmp_rpm = 0;
extern volatile bool adc0_read_complete;
extern volatile uint16_t adc0;
//uint16_t tmp_rpm = 0;
//extern volatile bool adc0_read_complete;
//extern volatile uint16_t adc0;
/* Just handle the Serial UI, everything else is in
* interrupt handlers or callbacks from SerialUI.
*/
......
......@@ -46,7 +46,7 @@ extern uint16_t sweep_rate;
/* Volatile variables (USED in ISR's) */
extern volatile uint8_t selected_wheel;
extern volatile uint8_t sweep_direction;
extern volatile uint8_t sweep_stage;
extern volatile int8_t sweep_stage;
extern volatile bool normal;
extern volatile bool sweep_lock;
extern volatile bool sweep_reset_prescaler;
......@@ -90,9 +90,10 @@ void serial_setup()
/* Not implemented yet */
//advMenu->addCommand(pri_glitch_key,primary_glitch_cb,pri_glitch_help);
//advMenu->addCommand(sec_glitch_key,secondary_glitch_cb,sec_glitch_help);
// mySUI.trackState(RPM, &wanted_rpm);
mySUI.trackState(F("Fixed RPM Mode"), &fixed);
mySUI.trackState(F("Swept RPM Mode"), &swept);
//These use way more memory than I would have hoped for... :(
//mySUI.trackState(F("RPM"), &wanted_rpm);
//mySUI.trackState(F("Fixed RPM"), &fixed);
//mySUI.trackState(F("Swept RPM"), &swept);
}
/* Helper function to spit out amount of ram remainig */
......@@ -114,10 +115,12 @@ void toggle_invert_primary_cb()
extern uint8_t output_invert_mask;
output_invert_mask ^= 0x01; /* Flip crank invert mask bit */
mySUI.print(F("Primary Signal: "));
if (output_invert_mask & 0x01)
if (output_invert_mask & 0x01) {
print_inverted();
else
}
else {
print_normal();
}
}
void print_normal() {
......@@ -150,7 +153,7 @@ void show_info_cb()
mySUI.println(F("Currently selected Wheel pattern: "));
mySUI.print(selected_wheel+1);
mySUI.print(F(":"));
mySUI.println(Wheels[selected_wheel].decoder_name);
mySUI.println((const __FlashStringHelper *)Wheels[selected_wheel].decoder_name);
display_rpm_info();
}
......@@ -190,7 +193,7 @@ void display_new_wheel()
mySUI.println(F("New Wheel chosen: "));
mySUI.print(selected_wheel + 1);
mySUI.print(F(": "));
mySUI.println(Wheels[selected_wheel].decoder_name);
mySUI.println((const __FlashStringHelper *)Wheels[selected_wheel].decoder_name);
display_rpm_info();
}
......@@ -294,7 +297,7 @@ void list_wheels_cb()
{
mySUI.print(i+1);
mySUI.print(F(": "));
mySUI.println((Wheels[i].decoder_name));
mySUI.println((const __FlashStringHelper *)Wheels[i].decoder_name);
}
}
......@@ -376,19 +379,15 @@ void sweep_rpm_cb()
void compute_sweep_stages(uint16_t *tmp_low_rpm, uint16_t *tmp_high_rpm)
{
uint8_t j;
uint8_t total_stages;
uint16_t end_tcnt;
uint32_t low_rpm_tcnt;
uint32_t high_rpm_tcnt;
uint16_t this_step_low_rpm;
uint16_t this_step_high_rpm;
uint16_t divisor;
uint16_t steps;
uint32_t scaled_remainder;
uint16_t rpm_span_this_stage;
float per_isr_tcnt_change;
float rpm_per_isr;
/* Spin until unlocked, then lock */
while (sweep_lock)
......
......@@ -39,7 +39,7 @@ struct _sweep_step {
/* Tie things wheel related into one nicer structure ... */
typedef struct _wheels wheels;
struct _wheels {
const char *decoder_name PROGMEM;
const char* decoder_name PROGMEM;
const unsigned char *edge_states_ptr PROGMEM;
const float rpm_scaler;
const uint16_t wheel_max_edges;
......
......@@ -42,7 +42,6 @@
sweep_step *build_sweep_steps(uint32_t *low_rpm_tcnt, uint32_t *high_rpm_tcnt, uint8_t *total_stages)
{
sweep_step *steps;
uint8_t prescaler_bits;
uint8_t bitshift;
uint32_t tmp = *low_rpm_tcnt;
/* DEBUG
......
......@@ -65,46 +65,46 @@
*/
typedef enum {
DIZZY_FOUR_CYLINDER, /* 2 evenly spaced teeth */
// DIZZY_SIX_CYLINDER, /* 3 evenly spaced teeth */
// DIZZY_EIGHT_CYLINDER, /* 4 evenly spaced teeth */
// SIXTY_MINUS_TWO, /* 60-2 crank only */
// SIXTY_MINUS_TWO_WITH_CAM, /* 60-2 with 2nd trigger on cam */
// THIRTY_SIX_MINUS_ONE, /* 36-1 crank only */
// FOUR_MINUS_ONE_WITH_CAM, /* 4-1 crank + cam */
// EIGHT_MINUS_ONE, /* 8-1 crank only */
// SIX_MINUS_ONE_WITH_CAM,/* 6-1 crank + cam */
// TWELVE_MINUS_ONE_WITH_CAM, /* 12-1 crank + cam */
// FOURTY_MINUS_ONE, /* Ford V-10 40-1 crank only */
// DIZZY_FOUR_TRIGGER_RETURN, /* dizzy 4 cylinder signal, 40deg on 50 deg off */
// ODDFIRE_VR, /* Oddfire V-twin */
// OPTISPARK_LT1, /* Optispark 360 and 8 */
// TWELVE_MINUS_THREE, /* 12-3 */
// THIRTY_SIX_MINUS_TWO_TWO_TWO, /* 36-2-2-2 crank only */
// THIRTY_SIX_MINUS_TWO_TWO_TWO_WITH_CAM, /* 36-2-2-2 crank and cam */
// FOURTY_TWO_HUNDRED_WHEEL, /* 4200 wheel */
// THIRTY_SIX_MINUS_ONE_WITH_CAM_FE3, /* Mazda F3 36-1 crank and cam */
// SIX_G_SEVENTY_TWO_WITH_CAM, /* Mitsubishi DOHC CAS and TCDS 6G72 */
// BUELL_ODDFIRE_CAM, /* Buell 45 deg cam wheel */
// GM_LS1_CRANK_AND_CAM, /* GM LS1 24 tooth with cam */
// LOTUS_THIRTY_SIX_MINUS_ONE_ONE_ONE_ONE, /* Lotus crank wheel 36-1-1-1-1 */
// HONDA_RC51_WITH_CAM, /* Honda oddfire 90 deg V-twin */
// THIRTY_SIX_MINUS_ONE_WITH_SECOND_TRIGGER, /* From jimstim */
// THIRTY_SIX_MINUS_ONE_PLUS_ONE_WITH_CAM_NGC4, /* From jimstim 36-1+1 wheel #5 4 cyl chrysler? */
// WEBER_IAW_WITH_CAM, /* From jimstim IAW weber-marelli */
// FIAT_ONE_POINT_EIGHT_SIXTEEN_VALVE_WITH_CAM, /* Fiat 1.8 16V from jimstim */
// THREE_SIXTY_NISSAN_CAS, /*from jimstim 360 tooth cas with 6 slots */
// TWENTY_FOUR_MINUS_TWO_WITH_SECOND_TRIGGER, /* Mazda CAS 24-2 (two 12-1's end to end) inner ring single pulse outer ring */
// YAMAHA_EIGHT_TOOTH_WITH_CAM, /* 02-03 Yamaha R1, seank */
// GM_FOUR_TOOTH_WITH_CAM, /* GM 4 even crank with half moon cam */
// GM_SIX_TOOTH_WITH_CAM, /* GM 4 even crank with half moon cam */
// GM_EIGHT_TOOTH_WITH_CAM, /* GM 4 even crank with half moon cam */
// VOLVO_D12ACD_WITH_CAM, /* Volvo Diesel d12[acd] with cam (alex32 on forums.libreems.org */
// MAZDA_THIRTY_SIX_MINUS_TWO_TWO_TWO_WITH_SIX_TOOTH_CAM,
// SIXTY_MINUS_TWO_WITH_4X_CAM, /* GM 4X cam */
// GEN4_DODGE_SRT_V10_SIXTY_MINUS_TWO_WITH_CAM, /* Gen IV Dodge Viper V-10 */
// TWENTY_FOUR_MINUS_ONE_WITH_CAM, /* Hayabusa 24-1 with 1xcam during missing tooth */
// FOUR_G_SIXTY_THREE_WITH_CAM, /* Mitsubishi & Mazda 4x crank and 2x cam CAS 4G63 */
// SEADOO_THIRTY_SIX_MINUS_TWO, /* Standard SeaDoo 36-2 cranktrigger, 50% DC */
DIZZY_SIX_CYLINDER, /* 3 evenly spaced teeth */
DIZZY_EIGHT_CYLINDER, /* 4 evenly spaced teeth */
SIXTY_MINUS_TWO, /* 60-2 crank only */
SIXTY_MINUS_TWO_WITH_CAM, /* 60-2 with 2nd trigger on cam */
THIRTY_SIX_MINUS_ONE, /* 36-1 crank only */
FOUR_MINUS_ONE_WITH_CAM, /* 4-1 crank + cam */
EIGHT_MINUS_ONE, /* 8-1 crank only */
SIX_MINUS_ONE_WITH_CAM,/* 6-1 crank + cam */
TWELVE_MINUS_ONE_WITH_CAM, /* 12-1 crank + cam */
FOURTY_MINUS_ONE, /* Ford V-10 40-1 crank only */
DIZZY_FOUR_TRIGGER_RETURN, /* dizzy 4 cylinder signal, 40deg on 50 deg off */
ODDFIRE_VR, /* Oddfire V-twin */
OPTISPARK_LT1, /* Optispark 360 and 8 */
TWELVE_MINUS_THREE, /* 12-3 */
THIRTY_SIX_MINUS_TWO_TWO_TWO, /* 36-2-2-2 crank only */
THIRTY_SIX_MINUS_TWO_TWO_TWO_WITH_CAM, /* 36-2-2-2 crank and cam */
FOURTY_TWO_HUNDRED_WHEEL, /* 4200 wheel */
THIRTY_SIX_MINUS_ONE_WITH_CAM_FE3, /* Mazda F3 36-1 crank and cam */
SIX_G_SEVENTY_TWO_WITH_CAM, /* Mitsubishi DOHC CAS and TCDS 6G72 */
BUELL_ODDFIRE_CAM, /* Buell 45 deg cam wheel */
GM_LS1_CRANK_AND_CAM, /* GM LS1 24 tooth with cam */
LOTUS_THIRTY_SIX_MINUS_ONE_ONE_ONE_ONE, /* Lotus crank wheel 36-1-1-1-1 */
HONDA_RC51_WITH_CAM, /* Honda oddfire 90 deg V-twin */
THIRTY_SIX_MINUS_ONE_WITH_SECOND_TRIGGER, /* From jimstim */
THIRTY_SIX_MINUS_ONE_PLUS_ONE_WITH_CAM_NGC4, /* From jimstim 36-1+1 wheel #5 4 cyl chrysler? */
WEBER_IAW_WITH_CAM, /* From jimstim IAW weber-marelli */
FIAT_ONE_POINT_EIGHT_SIXTEEN_VALVE_WITH_CAM, /* Fiat 1.8 16V from jimstim */
THREE_SIXTY_NISSAN_CAS, /*from jimstim 360 tooth cas with 6 slots */
TWENTY_FOUR_MINUS_TWO_WITH_SECOND_TRIGGER, /* Mazda CAS 24-2 (two 12-1's end to end) inner ring single pulse outer ring */
YAMAHA_EIGHT_TOOTH_WITH_CAM, /* 02-03 Yamaha R1, seank */
GM_FOUR_TOOTH_WITH_CAM, /* GM 4 even crank with half moon cam */
GM_SIX_TOOTH_WITH_CAM, /* GM 4 even crank with half moon cam */
GM_EIGHT_TOOTH_WITH_CAM, /* GM 4 even crank with half moon cam */
VOLVO_D12ACD_WITH_CAM, /* Volvo Diesel d12[acd] with cam (alex32 on forums.libreems.org */
MAZDA_THIRTY_SIX_MINUS_TWO_TWO_TWO_WITH_SIX_TOOTH_CAM,
SIXTY_MINUS_TWO_WITH_4X_CAM, /* GM 4X cam */
GEN4_DODGE_SRT_V10_SIXTY_MINUS_TWO_WITH_CAM, /* Gen IV Dodge Viper V-10 */
TWENTY_FOUR_MINUS_ONE_WITH_CAM, /* Hayabusa 24-1 with 1xcam during missing tooth */
FOUR_G_SIXTY_THREE_WITH_CAM, /* Mitsubishi & Mazda 4x crank and 2x cam CAS 4G63 */
SEADOO_THIRTY_SIX_MINUS_TWO, /* Standard SeaDoo 36-2 cranktrigger, 50% DC */
MAX_WHEELS,
}WheelType;
......
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:uno]
platform = atmelavr
board = uno
framework = arduino
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment