Skip to content

Commit

Permalink
fixed spurious ADC readings
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh S committed Jan 11, 2013
1 parent 43610f0 commit b64cc18
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 105 deletions.
44 changes: 22 additions & 22 deletions auto_adc_updater.v
Expand Up @@ -115,28 +115,28 @@ module auto_adc_updater(
adc_timeout <= adc_timeout + 16'h0001;
adc_go_r <= 0;
if (adc_valid) begin

case (adc_chan_r[6:2])
5'd0: adc_0_in_r <= adc_in;
5'd1: adc_1_in_r <= adc_in;
5'd2: adc_2_in_r <= adc_in;
5'd3: adc_3_in_r <= adc_in;
5'd4: adc_4_in_r <= adc_in;
5'd5: adc_5_in_r <= adc_in;
5'd6: adc_6_in_r <= adc_in;
5'd7: adc_7_in_r <= adc_in;
5'd8: if (bemf_sensing) adc_8_in_r <= adc_in;
5'd9: if (bemf_sensing) adc_9_in_r <= adc_in;
5'd10: if (bemf_sensing) adc_10_in_r <= adc_in;
5'd11: if (bemf_sensing) adc_11_in_r <= adc_in;
5'd12: if (bemf_sensing) adc_12_in_r <= adc_in;
5'd13: if (bemf_sensing) adc_13_in_r <= adc_in;
5'd14: if (bemf_sensing) adc_14_in_r <= adc_in;
5'd15: if (bemf_sensing) adc_15_in_r <= adc_in;
5'd16: adc_16_in_r <= adc_in;
default:;
endcase

if (adc_chan_r[1:0] == 2'b11) begin
case (adc_chan_r[6:2])
5'd0: adc_0_in_r <= adc_in;
5'd1: adc_1_in_r <= adc_in;
5'd2: adc_2_in_r <= adc_in;
5'd3: adc_3_in_r <= adc_in;
5'd4: adc_4_in_r <= adc_in;
5'd5: adc_5_in_r <= adc_in;
5'd6: adc_6_in_r <= adc_in;
5'd7: adc_7_in_r <= adc_in;
5'd8: if (bemf_sensing) adc_8_in_r <= adc_in;
5'd9: if (bemf_sensing) adc_9_in_r <= adc_in;
5'd10: if (bemf_sensing) adc_10_in_r <= adc_in;
5'd11: if (bemf_sensing) adc_11_in_r <= adc_in;
5'd12: if (bemf_sensing) adc_12_in_r <= adc_in;
5'd13: if (bemf_sensing) adc_13_in_r <= adc_in;
5'd14: if (bemf_sensing) adc_14_in_r <= adc_in;
5'd15: if (bemf_sensing) adc_15_in_r <= adc_in;
5'd16: adc_16_in_r <= adc_in;
default:;
endcase
end
// back to start state
auto_adc_state <= 2'b00;

Expand Down
Binary file modified kovan.bit
Binary file not shown.
44 changes: 40 additions & 4 deletions kovan.v
Expand Up @@ -28,7 +28,9 @@
////////////////////////////////////////////////

`timescale 1 ns / 1 ps




module kovan (

input wire INPUT_SW0,
Expand Down Expand Up @@ -99,6 +101,26 @@ module kovan (

input wire OSC_CLK // 26 mhz clock from CPU
);



parameter SERVO_PWM0_HIGH_DEFAULT = 16'd0;
parameter SERVO_PWM1_HIGH_DEFAULT = 16'd0;
parameter SERVO_PWM2_HIGH_DEFAULT = 16'd0;
parameter SERVO_PWM3_HIGH_DEFAULT = 16'd0;
parameter DIG_OUT_VAL_DEFAULT = 8'd0;
parameter DIG_PU_DEFAULT = 8'd0;
parameter DIG_OE_DEFAULT = 8'd0;
parameter ANA_PU_DEFAULT = 8'hFF;
parameter MOT_DUTY0_DEFAULT = 12'd0;
parameter MOT_DUTY1_DEFAULT = 12'd0;
parameter MOT_DUTY2_DEFAULT = 12'd0;
parameter MOT_DUTY3_DEFAULT = 12'd0;
parameter MOT_DRIVE_CODE_DEFAULT = 8'd0;
parameter MOT_ALLSTOP_DEFAULT = 5'd0;
parameter MOT_BEMF_CLEAR_DEFAULT = 4'd0;



///////// clock buffers
wire clk26;
Expand Down Expand Up @@ -628,9 +650,23 @@ module kovan (
.out_valid(bemf_out_valid)
);

spi pxa_spi (

// Clocks
spi #(
.SERVO_PWM0_HIGH_START(SERVO_PWM0_HIGH_DEFAULT),
.SERVO_PWM1_HIGH_START(SERVO_PWM1_HIGH_DEFAULT),
.SERVO_PWM2_HIGH_START(SERVO_PWM2_HIGH_DEFAULT),
.SERVO_PWM3_HIGH_START(SERVO_PWM3_HIGH_DEFAULT),
.DIG_OUT_VAL_START(DIG_OUT_VAL_DEFAULT),
.DIG_PU_START(DIG_PU_DEFAULT),
.DIG_OE_START(DIG_OE_DEFAULT),
.ANA_PU_START(ANA_PU_DEFAULT),
.MOT_DUTY0_START(MOT_DUTY0_DEFAULT),
.MOT_DUTY1_START(MOT_DUTY1_DEFAULT),
.MOT_DUTY2_START(MOT_DUTY2_DEFAULT),
.MOT_DUTY3_START(MOT_DUTY3_DEFAULT),
.MOT_DRIVE_CODE_START(MOT_DRIVE_CODE_DEFAULT),
.MOT_ALLSTOP_START(MOT_ALLSTOP_DEFAULT),
.MOT_BEMF_CLEAR_START(MOT_BEMF_CLEAR_DEFAULT)
) pxa_spi ( // Clocks
.SYS_CLK(clk208M),
.SPI_CLK(FPGA_SCLK),

Expand Down
220 changes: 141 additions & 79 deletions spi.v
@@ -1,88 +1,150 @@
`timescale 1ns / 1ps



module spi(
input SYS_CLK,
input SPI_CLK,
input SSEL,
input MOSI,
output MISO,
//input [1039:0] SPI_REG,
//output [1039:384] COMMAND_REG
//r0 //JS
input [7:0] dig_in_val,
input [9:0] adc_0_in,
input [9:0] adc_1_in,
input [9:0] adc_2_in,
input [9:0] adc_3_in,
input [9:0] adc_4_in,
input [9:0] adc_5_in,
input [9:0] adc_6_in,
input [9:0] adc_7_in,
input [9:0] adc_8_in,
input [9:0] adc_9_in,
input [9:0] adc_10_in,
input [9:0] adc_11_in,
input [9:0] adc_12_in,
input [9:0] adc_13_in,
input [9:0] adc_14_in,
input [9:0] adc_15_in,
input [9:0] adc_16_in,
input [0:0] charge_acp_in,
input [31:0] bemf_0,
input [31:0] bemf_1,
input [31:0] bemf_2,
input [31:0] bemf_3,
input [15:0] servo_pwm0_high,
input [15:0] servo_pwm1_high,
input [15:0] servo_pwm2_high,
input [15:0] servo_pwm3_high,
input [7:0] dig_out_val,
input [7:0] dig_pu,
input [7:0] dig_oe,
input [7:0] ana_pu,
input [11:0] mot_duty0,
input [11:0] mot_duty1,
input [11:0] mot_duty2,
input [11:0] mot_duty3,
//input [0:0] dig_sample,
//input [0:0] dig_update,
input [7:0] mot_drive_code,
input [4:0] mot_allstop,
input [0:0] side_button,
/*
input [15:0] pid_p_goal_0,
input [15:0] pid_p_goal_1,
input [15:0] pid_p_goal_2,
input [15:0] pid_p_goal_3,
input [3:0] pid_at_goal,
*/
output reg [15:0] servo_pwm0_high_new,
output reg [15:0] servo_pwm1_high_new,
output reg [15:0] servo_pwm2_high_new,
output reg [15:0] servo_pwm3_high_new,
output reg [7:0] dig_out_val_new,
output reg [7:0] dig_pu_new,
output reg [7:0] dig_oe_new,
output reg [7:0] ana_pu_new = 8'hFF,
output reg [11:0] mot_duty0_new,
output reg [11:0] mot_duty1_new,
output reg [11:0] mot_duty2_new,
output reg [11:0] mot_duty3_new,
//output reg [0:0] dig_sample_new,
//output reg [0:0] dig_update_new,
output reg [7:0] mot_drive_code_new,
output reg [4:0] mot_allstop_new,
output reg [3:0] mot_bemf_clear_new
/*
output reg [15:0] pid_p_goal_0_new,
output reg [15:0] pid_p_goal_1_new,
output reg [15:0] pid_p_goal_2_new,
output reg [15:0] pid_p_goal_3_new
*/
);
SYS_CLK,
SPI_CLK,
SSEL,
MOSI,
MISO,
dig_in_val,
adc_0_in,
adc_1_in,
adc_2_in,
adc_3_in,
adc_4_in,
adc_5_in,
adc_6_in,
adc_7_in,
adc_8_in,
adc_9_in,
adc_10_in,
adc_11_in,
adc_12_in,
adc_13_in,
adc_14_in,
adc_15_in,
adc_16_in,
charge_acp_in,
bemf_0,
bemf_1,
bemf_2,
bemf_3,
servo_pwm0_high,
servo_pwm1_high,
servo_pwm2_high,
servo_pwm3_high,
dig_out_val,
dig_pu,
dig_oe,
ana_pu,
mot_duty0,
mot_duty1,
mot_duty2,
mot_duty3,
mot_drive_code,
mot_allstop,
side_button,

servo_pwm0_high_new,
servo_pwm1_high_new,
servo_pwm2_high_new,
servo_pwm3_high_new,
dig_out_val_new,
dig_pu_new,
dig_oe_new,
ana_pu_new,
mot_duty0_new,
mot_duty1_new,
mot_duty2_new,
mot_duty3_new,
mot_drive_code_new,
mot_allstop_new,
mot_bemf_clear_new
);


// NOTE: Do not change these here
// change the *_DEFAULT parameters in kovan.v
parameter SERVO_PWM0_HIGH_START = 16'd0;
parameter SERVO_PWM1_HIGH_START = 16'd0;
parameter SERVO_PWM2_HIGH_START = 16'd0;
parameter SERVO_PWM3_HIGH_START = 16'd0;
parameter DIG_OUT_VAL_START = 8'd0;
parameter DIG_PU_START = 8'd0;
parameter DIG_OE_START = 8'd0;
parameter ANA_PU_START = 8'h0;
parameter MOT_DUTY0_START = 12'd0;
parameter MOT_DUTY1_START = 12'd0;
parameter MOT_DUTY2_START = 12'd0;
parameter MOT_DUTY3_START = 12'd0;
parameter MOT_DRIVE_CODE_START = 8'd0;
parameter MOT_ALLSTOP_START = 5'd0;
parameter MOT_BEMF_CLEAR_START = 4'd0;

input SYS_CLK;
input SPI_CLK;
input SSEL;
input MOSI;
output MISO;

input [7:0] dig_in_val;
input [9:0] adc_0_in;
input [9:0] adc_1_in;
input [9:0] adc_2_in;
input [9:0] adc_3_in;
input [9:0] adc_4_in;
input [9:0] adc_5_in;
input [9:0] adc_6_in;
input [9:0] adc_7_in;
input [9:0] adc_8_in;
input [9:0] adc_9_in;
input [9:0] adc_10_in;
input [9:0] adc_11_in;
input [9:0] adc_12_in;
input [9:0] adc_13_in;
input [9:0] adc_14_in;
input [9:0] adc_15_in;
input [9:0] adc_16_in;
input [0:0] charge_acp_in;
input [31:0] bemf_0;
input [31:0] bemf_1;
input [31:0] bemf_2;
input [31:0] bemf_3;
input [15:0] servo_pwm0_high;
input [15:0] servo_pwm1_high;
input [15:0] servo_pwm2_high;
input [15:0] servo_pwm3_high;
input [7:0] dig_out_val;
input [7:0] dig_pu;
input [7:0] dig_oe;
input [7:0] ana_pu;
input [11:0] mot_duty0;
input [11:0] mot_duty1;
input [11:0] mot_duty2;
input [11:0] mot_duty3;
input [7:0] mot_drive_code;
input [4:0] mot_allstop;
input [0:0] side_button;


output reg [15:0] servo_pwm0_high_new = SERVO_PWM0_HIGH_START;
output reg [15:0] servo_pwm1_high_new = SERVO_PWM1_HIGH_START;
output reg [15:0] servo_pwm2_high_new = SERVO_PWM2_HIGH_START;
output reg [15:0] servo_pwm3_high_new = SERVO_PWM3_HIGH_START;
output reg [7:0] dig_out_val_new = DIG_OUT_VAL_START;
output reg [7:0] dig_pu_new = DIG_PU_START;
output reg [7:0] dig_oe_new = DIG_OE_START;
output reg [7:0] ana_pu_new = ANA_PU_START;
output reg [11:0] mot_duty0_new = MOT_DUTY0_START;
output reg [11:0] mot_duty1_new = MOT_DUTY1_START;
output reg [11:0] mot_duty2_new = MOT_DUTY2_START;
output reg [11:0] mot_duty3_new = MOT_DUTY3_START;
output reg [7:0] mot_drive_code_new = MOT_DRIVE_CODE_START;
output reg [4:0] mot_allstop_new = MOT_ALLSTOP_START;
output reg [3:0] mot_bemf_clear_new = MOT_BEMF_CLEAR_START;



reg [2:0] SCKr; // SPI Clock
Expand Down

0 comments on commit b64cc18

Please sign in to comment.