INNO-MAKER / usb2can

89 stars 44 forks source link

How to modify the baudrate by the C++(Visual Studio) #13

Open b93611026 opened 1 year ago

b93611026 commented 1 year ago

Hi:

I saw the code below in C++(Visual Studio ), and I cant figure out how set other baudrate ( i.e. 1MHz or 250KHz ) Please help me to solve this problem, thx a lot.

/// 20K bittming.prop_seg = 6; bittming.phase_seg1 = 7; bittming.phase_seg2 = 2; bittming.sjw = 1; bittming.brp = 150;

Best Regards Chaim

AlekseyMamontov commented 1 year ago

Looks like they stopped supporting their product( Unfortunately, as I understand it, we won’t wait for an answer. It looks like this is a clone of https://github.com/roboterclubaachen/usb2can https://github.com/candle-usb/candleLight_fw or something similar.

С# private UsbCan.innomaker_device_bittming GetBittming(int index) { UsbCan.innomaker_device_bittming bittming;

        switch (index)
        {
            case 0: // 20K
                bittming.prop_seg = 6;
                bittming.phase_seg1 = 7;
                bittming.phase_seg2 = 2;
                bittming.sjw = 1;
                bittming.brp = 150;
                break;
            case 1: // 33.33K
                bittming.prop_seg = 3;
                bittming.phase_seg1 = 3;
                bittming.phase_seg2 = 1;
                bittming.sjw = 1;
                bittming.brp = 180;
                break;
            case 2: // 40K
                bittming.prop_seg = 6;
                bittming.phase_seg1 = 7;
                bittming.phase_seg2 = 2;
                bittming.sjw = 1;
                bittming.brp = 75;
                break;
            case 3: // 50K
                bittming.prop_seg = 6;
                bittming.phase_seg1 = 7;
                bittming.phase_seg2 = 2;
                bittming.sjw = 1;
                bittming.brp = 60;
                break;
            case 4: // 66.66K
                bittming.prop_seg = 3;
                bittming.phase_seg1 = 3;
                bittming.phase_seg2 = 1;
                bittming.sjw = 1;
                bittming.brp = 90;
                break;
            case 5: // 80K
                bittming.prop_seg = 3;
                bittming.phase_seg1 = 3;
                bittming.phase_seg2 = 1;
                bittming.sjw = 1;
                bittming.brp = 75;
                break;
            case 6: // 83.33K
                bittming.prop_seg = 3;
                bittming.phase_seg1 = 3;
                bittming.phase_seg2 = 1;
                bittming.sjw = 1;
                bittming.brp = 72;
                break;

            case 7: // 100K
                bittming.prop_seg = 6;
                bittming.phase_seg1 = 7;
                bittming.phase_seg2 = 2;
                bittming.sjw = 1;
                bittming.brp = 30;
                break;
            case 8: // 125K
                bittming.prop_seg = 6;
                bittming.phase_seg1 = 7;
                bittming.phase_seg2 = 2;
                bittming.sjw = 1;
                bittming.brp = 24;
                break;
            case 9: // 200K
                bittming.prop_seg = 6;
                bittming.phase_seg1 = 7;
                bittming.phase_seg2 = 2;
                bittming.sjw = 1;
                bittming.brp = 15;
                break;
            case 10: // 250K
                bittming.prop_seg = 6;
                bittming.phase_seg1 = 7;
                bittming.phase_seg2 = 2;
                bittming.sjw = 1;
                bittming.brp = 12;
                break;
            case 11: // 400K
                bittming.prop_seg = 3;
                bittming.phase_seg1 = 3;
                bittming.phase_seg2 = 1;
                bittming.sjw = 1;
                bittming.brp = 15;
                break;
            case 12: // 500K
                bittming.prop_seg = 6;
                bittming.phase_seg1 = 7;
                bittming.phase_seg2 = 2;
                bittming.sjw = 1;
                bittming.brp = 6;
                break;
            case 13: // 666K
                bittming.prop_seg = 3;
                bittming.phase_seg1 = 3;
                bittming.phase_seg2 = 2;
                bittming.sjw = 1;
                bittming.brp = 8;
                break;
            case 14: /// 800K
                bittming.prop_seg = 7;
                bittming.phase_seg1 = 8;
                bittming.phase_seg2 = 4;
                bittming.sjw = 1;
                bittming.brp = 3;
                break;
            case 15: /// 1000K
                bittming.prop_seg = 5;
                bittming.phase_seg1 = 6;
                bittming.phase_seg2 = 4;
                bittming.sjw = 1;
                bittming.brp = 3;
                break;
            default: /// 1000K
                bittming.prop_seg = 5;
                bittming.phase_seg1 = 6;
                bittming.phase_seg2 = 4;
                bittming.sjw = 1;
                bittming.brp = 3;
                break;
        }
        return bittming;
    }