• unlocking pcb features

    Simon Trendel08/17/2019 at 10:35 0 comments

    The PCB has arrived and assembly by hand took less than an hour. It consists of a DRV8323HRTA mosfet driver from texas instruments. Six mosfets for controlling three phases and three TLI4970 current sensors from Infineon on each phase. The rest of the components is bulk capacity and connectors to the TinyFPGA and sensors.

    I build a small test bed keeping all components in place and labeling all cables for sanity reasons. I used a bldc motor from Maxon which has hall sensors integrated and an optical encoder measuring the motor axis rotation. The motor is fixed to the ground plane with a 3D-printed holder. The motor winch has a 4x1mm diametral magnet attached to it and an A1335 angle sensor from Allegro is used to measure the absolute winch rotation. For testing i used a MKR4000 vidor. This board features a samd microcontroller a cyclone10 fpga and even has a nina wifi module. One can code in quartus for the fpga and because the samd processor shares all its IOs with the fpga you can easily control the fpga via SPI. I use the arduino IDE for high level coding.

    The verilog code for controlling the bldc motor is surprisingly simple:

    assign bMKR_D[5:0] = PHASES;
    reg [5:0] PHASES;
    reg [9:0] pwm_delay;
    reg signed [31:0] pwm;
    
    always @(posedge wCLK24) begin: BLDC_COMMUTATION
        if( pwm>=0 && pwm_delay>(1023-pwm))begin
            if(bMKR_A[4] && ~bMKR_A[5] && bMKR_A[6]) begin
                PHASES <= 6'b100100;
            end 
            if(bMKR_A[4] && ~bMKR_A[5] && ~bMKR_A[6])begin
                PHASES <= 6'b100001;
            end 
            if(bMKR_A[4] && bMKR_A[5] && ~bMKR_A[6]) begin
                PHASES <= 6'b001001;
            end 
            if(~bMKR_A[4] && bMKR_A[5] && ~bMKR_A[6])begin
                PHASES <= 6'b011000; 
            end 
            if(~bMKR_A[4] && bMKR_A[5] && bMKR_A[6]) begin
                PHASES <= 6'b010010;
            end     
            if(~bMKR_A[4] && ~bMKR_A[5] && bMKR_A[6])begin
                PHASES <= 6'b000110;
            end 
        end else if ( pwm<0 && pwm_delay>(1023+pwm)) begin
            if(bMKR_A[4] && ~bMKR_A[5] && bMKR_A[6]) begin
                PHASES <= 6'b011000;
            end 
            if(bMKR_A[4] && ~bMKR_A[5] && ~bMKR_A[6])begin
                PHASES <= 6'b010010;
            end 
            if(bMKR_A[4] && bMKR_A[5] && ~bMKR_A[6]) begin
                PHASES <= 6'b000110;
            end 
            if(~bMKR_A[4] && bMKR_A[5] && ~bMKR_A[6])begin
                PHASES <= 6'b100100; 
            end 
            if(~bMKR_A[4] && bMKR_A[5] && bMKR_A[6]) begin
                PHASES <= 6'b100001;
            end     
            if(~bMKR_A[4] && ~bMKR_A[5] && bMKR_A[6])begin
                PHASES <= 6'b001001;
            end 
        end else begin
            PHASES <= 0;
        end
        pwm_delay <= pwm_delay+1;
    end

     The phases commute depending on the hall sensor input.

    Make sure to activate a weak pull up resistor in the pin planner in quartus:

    I used a poti connected to an adc pin of the vidor for setting the pwm value. There are three more sensors connected in this setup:

    - optical encoder

    - absolute angle sensor on the winch ( pcb / code ) connected to samd via i2c

    - temperature sensor ( MLX90640 ) connected to samd via i2c

    For the optical encoder I milled a simple pcb for connecting the differential signals to a chip that translates them to A/B signals. The encoder works on 5V so I put a level shifter before going to the fpga. Opencores has several quadrature decoder modules, I picked this one.


    Next steps are to validate the quadrature encoder readings using the A1335 angle sensor on the winch. I want to make 100% sure I'm not missing any ticks even on highest speed.