You are here

Does the code right

8 posts / 0 new
Last post
jennyxcy2008
Offline
Last seen: 5 years 11 months ago
Joined: 2018-12-17 04:33
Posts: 5
Does the code right

 I have tow question,Need to consult

1:switch (comm_step) {
      case 1: curr_samp_volt = (1 << 0) || (1 << 2); break; 
      case 2: curr_samp_volt = (1 << 1) || (1 << 2); break;
      case 3: curr_samp_volt = (1 << 1) || (1 << 2); break;
      case 4: curr_samp_volt = (1 << 0) || (1 << 1); break;
      case 5: curr_samp_volt = (1 << 0) || (1 << 1); break;
      case 6: curr_samp_volt = (1 << 0) || (1 << 2); break;

The code above, "||" should be "|" right?

2:

 filter_add_sample((float*)amp_fir_samples, amp,
    AMP_FIR_TAPS_BITS, (uint32_t*)&amp_fir_index);

void filter_add_sample(float *buffer, float sample, int bits, uint32_t *offset) {
 uint32_t cnt_mask = 0xFFFFFFFF >> (32 - bits);
 buffer[*offset] = sample;
 *offset += 1;
 *offset &= cnt_mask;
}

In the above function, the variable amp_fir_index will keep increasing, which may exceed the maximum limit

of the array amp_fir_samples, because I did not find the variable amp_fir_index reset in the whole program,

am I correct?

 

TechAUmNu
Offline
Last seen: 3 months 1 week ago
Joined: 2017-09-22 01:27
Posts: 575

1. Yes that looks like it should be | not ||.

2. It adds a sample to the buffer then moves the offset forward 1, then masks the number. So it will actually loop round.

jennyxcy2008
Offline
Last seen: 5 years 11 months ago
Joined: 2018-12-17 04:33
Posts: 5

uint32_t cnt_mask = 0xFFFFFFFF >> (32 - bits);

actually cnt_mask=0x1ffffff

 *offset += 1;

 *offset &= cnt_mask;

if offset =0x200 0000  then 0ffset&0x1ff ffff=0

but  buffer amp_fir_samples max offset value is 128 ( static volatile float amp_fir_samples[AMP_FIR_LEN];),

so when offset >127,It adds a sample  to buffer,should be not right?

Do you understand?

 

jennyxcy2008
Offline
Last seen: 5 years 11 months ago
Joined: 2018-12-17 04:33
Posts: 5

 I think  cnt_mask=0xFF>>1,thus offset loop round

Am I right?

TechAUmNu
Offline
Last seen: 3 months 1 week ago
Joined: 2017-09-22 01:27
Posts: 575

I think you have misread the function.

void filter_add_sample(float *buffer, float sample, int bits, uint32_t *offset) {
    uint32_t cnt_mask = 0xFFFFFFFF >> (32 - bits);
    buffer[*offset] = sample;
    *offset += 1;
    *offset &= cnt_mask;
}


In your example it is called with the 'bits' variable set to 7. So you will get:

uint32_t cnt_mask = 0xFFFFFFFF >> (32 - 7);

which makes cnt_mask = 127

 

 

jennyxcy2008
Offline
Last seen: 5 years 11 months ago
Joined: 2018-12-17 04:33
Posts: 5

I'm sorry, I misread it,

Thank you a lots

TechAUmNu
Offline
Last seen: 3 months 1 week ago
Joined: 2017-09-22 01:27
Posts: 575

No problem, happy to help!

jennyxcy2008
Offline
Last seen: 5 years 11 months ago
Joined: 2018-12-17 04:33
Posts: 5

Hello!

Do you  have the details document for the VESC software? , because to be honest, no document, the software looks very hard, a lot of places all look not to understand, that only a small part of the document is good too, I want to promote for this project there is a big help, because in China, 90% of people now just research how to use the software, but they don't understand the software architecture and principle, has been a shot in the dark, so many motors do not mached good, promotion is very slow, hope to get your help