Jump to content
jayjay23

Firmware

Recommended Posts

lizardmech    647

Might it be the hall sensors? Not sure if they will work at higher RPM. There's probably some latency difference on either the halls or current sense that increases at higher RPM.

Share this post


Link to post
Share on other sites
5 minutes ago, KingQueenWong said:

This controller's 3 phase all connect a inductor in series.

Thanks!! I also did read about that option. Still I am looking to see if is possible to improve the issue with firmware only, and I think so. This motor have low inductance but the current seems to be possible to be read and limited... just need to find a way to sync ADC read of current signal with PWM signal, as the current increases and should be read a bit after PWM fires (when the voltage kicks at the motor/coils terminals.
The EUC motor, with higher inductance, I just read the the middle of PWM and seems to be enough. On this motor I need to read it much earlier.
And EUC motor without load never reach max current while this small EBike motor reaches and can be destroyed. I planned to use this EBike motor and a test to make an EUC with a bicycle wheel -- I saw a video of a Russian guy using this motor, for a balance skate. This motor needs to be hacked to loose the freewheel but after that should work. I think Firewheel EUCs also use this kind of geared motors.

Edited by electric_vehicle_lover

Share this post


Link to post
Share on other sites
1 hour ago, KingQueenWong said:

STM8's TIM1 TRGO event can trigger ADC conversion.

Thanks @KingQueenWong -- very good to have you with me for firmware!!

I think I will do it!! I was thinking in using TIMER1 -> TIMER5 -> ADC, where TIMER5 would make a timer so I could read at some specific point in time but turns out this STM8S105 do not have TIMER5, the only way seems to do it manually: TIMER1 interrupt start TIMER2, TIMER2 interrupt starts ADC. Let's see the best I can get...

And now that motor is running with sinewave/SVM I can see the phase B current wave form that should be a sinewave and should be in sync with hall sensor signal, this way we get the best efficiency possible -- it is the objective of FOC. We can see the oscilloscope, blue line is phase B current signal and yellow line is one hall sensor signal and as we can see they are in sync.. if not, produced voltage with the PWM signal that we generate/control should be advanced in time in a way to keep this current in sync with the hall sensor (rotor position):

New_File29-big.jpg

 

Edited by electric_vehicle_lover
  • Upvote 1

Share this post


Link to post
Share on other sites

I implemented TIM1(TIM1_TRGOSOURCE_OC3REF) trigger ADC conversion throttle value.:D:D:D

void adc_init (void)
{
  //init GPIO for the used ADC pins
  GPIO_Init(THROTTLE__PORT,THROTTLE__PIN,GPIO_MODE_IN_FL_NO_IT);

  //de-Init ADC peripheral
  ADC1_DeInit();

  //init ADC2 peripheral
  ADC1_Init(ADC1_CONVERSIONMODE_SINGLE,ADC1_CHANNEL_4,ADC1_PRESSEL_FCPU_D2,ADC1_EXTTRIG_TIM,ENABLE,ADC1_ALIGN_RIGHT,
     ADC1_SCHMITTTRIG_CHANNEL9,DISABLE);
 
  ADC1_ITConfig(ADC1_IT_EOCIE,ENABLE);
}

void pwm_init (void)
{
// TIM1 Peripheral Configuration
  TIM1_DeInit();

  TIM1_TimeBaseInit(0, // TIM1_Prescaler = 0
       TIM1_COUNTERMODE_UP,
       (1024 - 1), // clock = 16MHz; counter period = 1024; PWM freq = 16MHz / 1024 = 15.625kHz
       0); // TIM1_RepetitionCounter = 0

  TIM1_OC1Init(TIM1_OCMODE_PWM1,
        TIM1_OUTPUTSTATE_ENABLE,
        TIM1_OUTPUTNSTATE_DISABLE,
        0, // initial duty_cycle value
        TIM1_OCPOLARITY_HIGH,
        TIM1_OCNPOLARITY_LOW,
        TIM1_OCIDLESTATE_RESET,
        TIM1_OCNIDLESTATE_SET);

  TIM1_OC2Init(TIM1_OCMODE_PWM1,
        TIM1_OUTPUTSTATE_ENABLE,
        TIM1_OUTPUTNSTATE_DISABLE,
        0, // initial duty_cycle value
        TIM1_OCPOLARITY_HIGH,
        TIM1_OCNPOLARITY_LOW,
        TIM1_OCIDLESTATE_RESET,
        TIM1_OCNIDLESTATE_SET);

  TIM1_OC3Init(TIM1_OCMODE_PWM1,
        TIM1_OUTPUTSTATE_ENABLE,
        TIM1_OUTPUTNSTATE_DISABLE,
        0, // initial duty_cycle value
        TIM1_OCPOLARITY_HIGH,
        TIM1_OCNPOLARITY_LOW,
        TIM1_OCIDLESTATE_RESET,
        TIM1_OCNIDLESTATE_SET);

  // break, dead time and lock configuration
  TIM1_BDTRConfig(TIM1_OSSISTATE_DISABLE,
    TIM1_LOCKLEVEL_OFF,
    // hardware nees a dead time of 1us
    16, // DTG = 0; dead time in 62.5 ns steps; 1us/62.5ns = 16
    TIM1_BREAK_DISABLE,
    TIM1_BREAKPOLARITY_HIGH,
    TIM1_AUTOMATICOUTPUT_ENABLE);


  TIM1_SelectOutputTrigger(TIM1_TRGOSOURCE_OC3REF);

  TIM1_Cmd(ENABLE); // TIM1 counter enable
  TIM1_CtrlPWMOutputs(ENABLE); // main Output Enable
}

uint16_t Conversion_Value;
INTERRUPT_HANDLER(ADC1_IRQHandler, 22)
{
 if(ADC1_GetFlagStatus(ADC1_FLAG_EOC)!= RESET)
 {
   Conversion_Value = ADC1_GetConversionValue();
  
   GPIO_WriteReverse(GPIOA,GPIO_PIN_1);
  
   ADC1_ClearITPendingBit(ADC1_IT_EOC);
 }
}

while (1)
{
  //static uint16_t adc_value;
  //adc_value = adc_read_throttle ();
  //adc_value = map (adc_value, ADC_THROTTLE_MIN_VALUE, ADC_THROTTLE_MAX_VALUE, 0, 1023);
  //pwm_value = adc_value;
 
  printf("%d\n\r",Conversion_Value);
 
  Delay(100000);
 
  //pwm_set_duty_cycle_channel1 (pwm_value);
  //pwm_set_duty_cycle_channel2 (pwm_value);
  //pwm_set_duty_cycle_channel3 (pwm_value);
}

1.jpg.000cda15545001e34a64ae25d5b12afd.jpg

IMG_4313.thumb.JPG.8499444b3eded72e7054331bfe023621.JPG

 

 

  • Upvote 1

Share this post


Link to post
Share on other sites
1 hour ago, KingQueenWong said:

I implemented TIM1(TIM1_TRGOSOURCE_OC3REF) trigger ADC conversion throttle value.:D:D:D

Thanks.

The thing is that TIM1 trigger happen at middle of low portion of the PWM (and when it is 50% duty_cycle, this even changes when duty_cycle changes). And as we can see, the need to read current about 14us after PWM rise to high value. On the screenshot we can see that we could read 2 times every PWM cycle but I think one is enough (we don't have much processing time).

I am able now to: PWM trigger Timer2; Timer2 trigger starts ADC reading; ADC interrupt reads motor current value. But I have some small issues like: find how to calc the Timer2 count value based on PWM value, to achieve the correct time value to read the current pulse. I did push my current code so you can follow it.

New_File30-big.jpg

Share this post


Link to post
Share on other sites
lizardmech    647
18 hours ago, electric_vehicle_lover said:

And now that motor is running with sinewave/SVM I can see the phase B current wave form that should be a sinewave and should be in sync with hall sensor signal, this way we get the best efficiency possible -- it is the objective of FOC. We can see the oscilloscope, blue line is phase B current signal and yellow line is one hall sensor signal and as we can see they are in sync.. if not, produced voltage with the PWM signal that we generate/control should be advanced in time in a way to keep this current in sync with the hall sensor (rotor position):

These things aren't FOC you're confusing yourself. If you aren't calculating the flux in the airgap it's not FOC.

  • Upvote 2

Share this post


Link to post
Share on other sites
esaj    5,297
On 6/7/2017 at 2:13 PM, electric_vehicle_lover said:

I think Firewheel EUCs also use this kind of geared motors.

The Firewheel's motor's not geared, I don't have pictures, but Vee opened it at one point. Rockwheel GR16's (and was there a smaller model called GR12?) had geared motors, not to be mixed with the new Rockwheel GT16, as well as the early Gotway MTens or maybe it was M8's (first gen).

  • Upvote 2

Share this post


Link to post
Share on other sites

I got the current limiting working but half (1 every 2 PWM pulses). The results are clear, motor max current limited and less noise. Seems clear that should be implement fully the current limit. I had to lower the PWM frequency to half, now is at 8kHz -- seems to work ok. Processing power very limited.

@KingQueenWong you can look at the code...., is it on github.

 

12 hours ago, electric_vehicle_lover said:

Thanks.

The thing is that TIM1 trigger happen at middle of low portion of the PWM (and when it is 50% duty_cycle, this even changes when duty_cycle changes). And as we can see, the need to read current about 14us after PWM rise to high value. On the screenshot we can see that we could read 2 times every PWM cycle but I think one is enough (we don't have much processing time).

I am able now to: PWM trigger Timer2; Timer2 trigger starts ADC reading; ADC interrupt reads motor current value. But I have some small issues like: find how to calc the Timer2 count value based on PWM value, to achieve the correct time value to read the current pulse. I did push my current code so you can follow it.

New_File30-big.jpg

 

Share this post


Link to post
Share on other sites
OliverH    817
19 hours ago, esaj said:

The Firewheel's motor's not geared, I don't have pictures, but Vee opened it at one point. Rockwheel GR16's (and was there a smaller model called GR12?) had geared motors, not to be mixed with the new Rockwheel GT16, as well as the early Gotway MTens or maybe it was M8's (first gen).

It's not geared.

Share this post


Link to post
Share on other sites
8 minutes ago, OliverH said:

It's not geared.

Ok, got it. The thing is that EBike motors are small and cheap - although we can find gear and no gear motors (no gear are more expensive, big and heavier, just like EUC motors). Also batteries and motor controllers can be reused to EUC application. I am afraid market will go low for EUC so I am looking more to EBike technology and see if can be reused for EUC application.

  • Upvote 1

Share this post


Link to post
Share on other sites
10 hours ago, KingQueenWong said:

I buy a board which cost $29 from https://s.2.taobao.com/list/  :D

@KingQueenWong that board is good, for the price and for what is capable. Unfortunately, is very hard for a westerns to buy it and also seems there happens to be a few versions which will make difficult to support with firmware and knowledge. I would prefer to have a stable version on a english shop that anyone could buy the board.

  • Upvote 1

Share this post


Link to post
Share on other sites

Here is an EUC using a EBike motor and rim/wheel -- the same I would like to do, to have much more freedom on the motor supplier, motor controller, battery AND MOTOR SPEED!! @MattJ look at this EUC.

On 08/06/2017 at 5:34 AM, codersarepeople said:

I saw this really interesting interview with the founder of Grin Technologies, and thought it would really be interesting to people here.

Interestingly, at about 45 minutes, he points to an EUC he made and claims he made it at about the same time as Shane Chen. He also talks at length from about 10-35 minutes about some really interesting aspects of batteries. In another great video of his, he shows off his pedal-assist regular unicycle, which is really cool.

Screenshot_from_2017-06-09_23-51-17.png

 

Edited by electric_vehicle_lover
  • Upvote 1

Share this post


Link to post
Share on other sites

@electric_vehicle_lover

I found a chinese guy who release the generic EUC firmware that be annotated in Chinese!

The guy said that the firmware can work well!

I think the code is good for your EUC banlance control!

I review the code,it don't run foc,just square wave.

:D:P:)

1.thumb.jpg.6d517b599cf3e2274c130af811ba1091.jpg

 

ZKTF_STM32_BALCAR_V5.rar

Edited by KingQueenWong
  • Upvote 3

Share this post


Link to post
Share on other sites
lizardmech    647
1 hour ago, KingQueenWong said:

@electric_vehicle_lover

I found a chinese guy who release the generic EUC firmware that be annotated in Chinese!

The guy said that the firmware can work well!

I think the code is good for your EUC banlance control!

I review the code,it don't run foc,just square wave.

:D:P:)

 

ZKTF_STM32_BALCAR_V5.rar

Any idea which board and euc he was using it with?

Share this post


Link to post
Share on other sites
lizardmech    647

Did he write it or just get access to generic EUC firmware? Pretty useful, shows they use software kalman filter combined with a complimentary filter.

Share this post


Link to post
Share on other sites
8 hours ago, KingQueenWong said:

@electric_vehicle_lover

I found a chinese guy who release the generic EUC firmware that be annotated in Chinese!

The guy said that the firmware can work well!

I think the code is good for your EUC banlance control!

I review the code,it don't run foc,just square wave.

THANKS!! You are our spearhead :-) :-)

I still have GEN1 boards with me, maybe I can try the firmware or at least look at hardware and see if it makes sense...

The code is not extensive... would you please be able to translate all the comments?? -- would be a good investment, and if this firmware is for Gen1 EUCs, that would be perfect at least for historic reasons!!!!

Edited by electric_vehicle_lover

Share this post


Link to post
Share on other sites
32 minutes ago, electric_vehicle_lover said:

THANKS!! You are our spearhead :-) :-)

I still have GEN1 boards with me, maybe I can try the firmware or at least look at hardware and see if it makes sense...

The code is not extensive... would you please be able to translate all the comments?? -- would be a good investment, and if this firmware is for Gen1 EUCs, that would be perfect at least for historic reasons!!!!

I have not GEN1 board,so now i can not find the difference between the firmware and the GEN1 board.But it seem that this firmware is designed for GEN1 board(Maybe i need to buy a GEN1 board to confirm my guess).I may will spend the next days to translate all the comments in English.Everyone just need more patience to my hard work.:D

Edited by KingQueenWong
  • Upvote 1

Share this post


Link to post
Share on other sites
19 minutes ago, KingQueenWong said:

I have not GEN1 board,so now i can not find the difference between the firmware and the GEN1 board.But it seem that this firmware is designed for GEN1 board(Maybe i need to buy a GEN1 board to confirm my guess).I may will spend the next days to translate all the comments in English.Everyone just need more patience to my hard work.:D

Don't wast time and money about GEN1 -- it is just like the S06S EBike motor controller that you just draw. The big different is that it does not do FOC: it just have powers resistors motor current sensor (no phase current sensors) and the mosfet drivers are with transistors just like S06S controller. Also do not have bluetooth module.

- https://github.com/EGG-electric-unicycle/documentation/wiki/Generic_Controller
- https://github.com/EGG-electric-unicycle/documentation/wiki/MicroWorks-18km-h-controller-board
- https://github.com/EGG-electric-unicycle/documentation/wiki/Generic-EUC---GD32F130-microcontroller
- https://github.com/EGG-electric-unicycle/electronics-gen1_boards/tree/master/generic_electric_unicycle

If was a translation from Portuguese to English, would take me only 2 hours using google translator ;-) -- but the comments aren't translated by google, just a few variable names were translated.

@KingQueenWong I would like to ask you what are the main motivations to work on this project and also for the firmware of EBike.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×