BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Sun Apr 22, 2018 2:59 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: AtomPro 28 PWM Output to Motor Controller
PostPosted: Tue Oct 15, 2013 3:17 am 
Offline
Guru

Joined: Sat Oct 23, 2010 5:12 am
Posts: 60
I am trying to adapt the Atom Pro 28 (on Lynxmotion Bot Board II) I used with RoboClaw motoro control to control a new airplane brushless motor with ESC (electric motor speed control). The ESC (CastleCreations Phoenix Ice2 HV 60 Amp, 12kHz PWM switching) needs zero throttle before it will arm so I was trying the following code to test. The ESC isn't reacting at all. At this point, I don't know if is the code or what or if another forum is appropriate (ie Lynxmotion). I have a multimeter and was trying to see if I could detect a signal (either voltage changes or the PWM switching rate frequency). Any help or direction is greatly appreciated.

I am not using HPWM command believing I needed all the HPWM pins for a connected PS2 controller which I will ultimately use to throttle the PWM signal (ie vary duty cycle).

I would be so happy to program the AtomPro 28 to send a command that would have the brushless motor run at all. I am at a loss if the code is the issue or something I don't know.


duty var byte
duty = 0
pwm p9,1333,0,1333
pause 5000
duty=400

main
pwm p9, 1333,duty,1333
serout S_OUT,i57600,[dec4 duty\4, 13]
goto main


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Tue Oct 15, 2013 3:37 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
I am a bit rusty here and have not done much with the PWM code, but will try to give a few things to try to see if it helps.

1) Make sure that the pin is configured for output. Maybe PWM command does this, but I would add a line or lines in the init code like:
OUTPUT P9
If that did not help. Also add: (note case of characters is ignored)
LOW P9


2) Would consider using the Hardware PWM instead of the software PWM

3) Not sure of the Period/Pulse settings you have here. I think you said that the pulses need to be in the 12KH range. So each pulse is:
1/12000 seconds. And the inputs to PWM is in half microseconds. So I think that is (1/12000)*2000000 = 166.666666 or 167 Could be wrong.

4) Again with the Software PWM, code it is all done in a hard coded loop. My guess into the usage here is each of the commands:
like: pwm p9, 1333, duty, 1333 will take:
(1333*1333)/2000000= 0.8884445 seconds then there will be a lull in pulses generated while your serout command is processed and then it will generate pulses again for a little under a second... So again suggest HPWM as it gives you continuous pulses and it does hang your program while doing so.

Good Luck
Kurt


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Mon Oct 21, 2013 12:54 am 
Offline
Guru

Joined: Sat Oct 23, 2010 5:12 am
Posts: 60
Unfortunately the LOW and OUTPUT commands didn't work with that code.

Some updates:
Now only using HPWM code.
I purchased basic R/C controller (transmitter/receiver) and successfully controlled the ESC (Electronic Speed Control). It was necessary to show zero throttle before the ESC would arm. I can't seem to mimic that with a HPWM signal.

What Period code should I use considering AtomPro28 is 16 MHz (16000 cycles/1 millisecond?) and ESC is (12 kHz)?

The following is Terminal result from the following code after connecting the R/C receiver to P0.
Code:
temp var word

main
   adin16 p0,temp
   temp = temp>>4 ;temp will hold a 12bit decimated A/D conversion
   serout s_out,i9600,["Conversion = ",dec temp,13]
goto main


Conversion = 926
Conversion = 6
Conversion = 6
Conversion = 6
Conversion = 7
Conversion = 6
Conversion = 7
Conversion = 6
Conversion = 6
Conversion = 6
Conversion = 6
Conversion = 7
Conversion = 7
Conversion = 7
Conversion = 6
Conversion = 10
Conversion = 7
Conversion = 6
Conversion = 6
Conversion = 6
Conversion = 7
Conversion = 6
Conversion = 6
Conversion = 7
Conversion = 6
Conversion = 6
Conversion = 8
Conversion = 7
Conversion = 6
Conversion = 6
Conversion = 7
Conversion = 6
Conversion = 7
Conversion = 7
Conversion = 6
Conversion = 1045
Conversion = 7
Conversion = 6
Conversion = 7
Conversion = 6
Conversion = 7
Conversion = 7
Conversion = 7
Conversion = 7
Conversion = 6
Conversion = 6
Conversion = 6
Conversion = 7
Conversion = 6
Conversion = 7
Conversion = 7
Conversion = 7
Conversion = 6
Conversion = 6
Conversion = 6
Conversion = 6
Conversion = 7
Conversion = 6
Conversion = 6
Conversion = 7
Conversion = 6
Conversion = 6
Conversion = 6
Conversion = 6
Conversion = 6
Conversion = 7
Conversion = 7
Conversion = 6
Conversion = 6
Conversion = 7
Conversion = 1125

Sorry for the length, but I didn't include any pauses. The next output is form HPWM (P10) straight to P0 using ADIN16 command.

NOW....Here is the output when I send the HPWM signal (P10) to the ADIN16 input (P0)

temp var word

Code:
main
   hpwm p10,167,0
   adin16 p0,temp
   temp = temp>>4 ;temp will hold a 12bit decimated A/D conversion
   serout s_out,i9600,["Conversion = ",dec temp,13]
goto main



Conversion = 0
Conversion = 0
Conversion = 0
Conversion = 0
Conversion = 0
Conversion = 0
Conversion = 0
Conversion = 0
Conversion = 0
Conversion = 0

The result is no response from the ESC and consequently the brushless motor.

Not sure what it is, but the R/C controller works fine after zero throttle, while I struggle with the code to replicate the R/C controller.

I may post this to Lynxmotion forum if anyone suggests it is more appropriate. I don't know if it is MC or BotBoardII or other.

Essentially, I am trying to mimic R/C transmitter/receiver with AtomPro 28 on BBII.


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Wed Oct 23, 2013 4:23 am 
Offline
Guru

Joined: Sat Oct 23, 2010 5:12 am
Posts: 60
Update:
The following code gives me control over the motor....finally. I would be interested if someone can explain the variable settings to me; especially why the arming command (send 0% throttle) seems to be full throttle if I use the command again after 'main'.

Also, is there a way to make this better? The motor turns, but I notice small irregularities.

I confirmed the following with the ESC (Electronic Speed Controller) manufacturer
Arms itself after 'zero' throttle
1 ms = Zero Throttle
2 ms = Full Throttle

Code:
hpwm p10,32000,16000  ;  why does this successfully arm the ESC (ie 0% Throttle), but if I used it again after main it goes to 100% throttle.
pause 3000
   
main
hpwm p10,20000,16000   ;25% throttle(?)
goto main


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Wed Oct 23, 2013 6:04 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
Can you post more information on what the ESC really wants as a input signal? Your code is changing the period(eg the frequency) not the duty( which I would have expected to be what changed) so apparently we don't understand what your esc really wants or you are just very lucky it is doing anything at all with that code.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Wed Oct 23, 2013 6:40 pm 
Offline
Guru

Joined: Sat Oct 23, 2010 5:12 am
Posts: 60
The ESC is a Castle Creations (CC) ICE2 HV 60 amp

They mentioned the PWM frequency is 12kHZ
There was also mention of a 50Hz carrier signal (huh?)

Beyond that they said the ESC is looking for
1 ms pulse for zero throttle
2 ms pulse for full

Again, the ESC takes a signal from and R/C receiver. I read in the voltage using the ADIN16 (previous post) in case that provides some insight.

I will followup with CC to get more info.

I definitely have some form of control over motor, by varying the period between 16000 and 32000; keeping duty variable at 16000.

I even tried a pulsout and freqout but not with the result of using this latest hpwm code.
Any advantage to trying PWM to test?


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Wed Oct 23, 2013 11:53 pm 
Offline
Guru

Joined: Sat Oct 23, 2010 5:12 am
Posts: 60
Update: Not much more than previous on the ESC. They did confirm that the 12kHZ PWM frequency is between the ESC and the motor, so it would not seem to be a factor between the MC and the ESC.


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Sun Oct 27, 2013 2:44 am 
Offline
Guru

Joined: Sat Oct 23, 2010 5:12 am
Posts: 60
Update: I had no luck with understanding how to make the HPWM code work. So I focused on PULSOUT command and have good control over the ESC-to-brushless motor.

Again, the ESC manufacturer says the ESC is looking for...
1 ms pulse = zero throttle (also necessary before ESC will arm itself)
2 ms pulse = full throttle
50 Hz Carrier Frequency (I still don't know how this translates into code)
PWM

Since the ESC needs zero throttle to arm itself, I used a REPEAT command before the main code. It works, but let me know if there is a more efficient way. I am going to play around with moving the 'arming' command into the main code.

Code:
index var word

   Index = 0
   Repeat
   index = index + 1
   pulsout p11,2000
   Until index > 100 ;run until index is greater than 100

main

   pulsout p11,2250 ; The range is 2000-4000 (1 ms to 2 ms) and 2250 is the first value that made the motor turn.
   
goto main


My next test will be to introduce a potentiometer.


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Sun Oct 27, 2013 5:26 pm 
Offline
Guru

Joined: Sat Oct 23, 2010 5:12 am
Posts: 60
another update after introducing potentiometer:

I assume that the ESC works because it is seeing a pulse when it is looking for one (50 HZ) even thought the pulse train is at a higher frequency. Is this correct?

If there is still hope to mimic this with a PWM or HPWM, I would appreciate any insight and feedback.

Code:
index var word
temp var word
throttle_perct var word
throttle var word

   ; arming command -> send zero throttle (1 ms = 2000 0.5us)
   Index = 0
   Repeat
   index = index + 1
   pulsout p11,2000
   Until index > 100 ;run until index is greater than 100
      
main

   ; read potentiometer on pin
   adin16 p3,temp
   temp = temp>>4
;   serout s_out,i9600,["Conversion = ",dec temp,13]

   ; throttle outpout
   throttle_perct = temp*100/4092
   throttle=2000+(2000*throttle_perct/100)
   serout s_out,i57600,["Throttle = ",dec throttle,13]
   pulsout p11,throttle
         
goto main


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Mon Oct 28, 2013 3:28 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Sorry,

As I am rusty on BAPs and have not used the pulseout command for much, without sitting down and pulling out a BAP28, and hook it up, it is hard to double check to see what pulses are actually generated.

So rethinking about your stuff, you say that it works with an RC receiver, which generates pulses for servos, I would be more inclined to use the HSERVO subsystem.

To initialize the system to a simple 1500us pulses, which is the center of the RC type signals, you would simply do:
hservo[p11\0]

The 0 in the above is for the pulse width, which is not zero, but 1500us. The values for this are expressed in clock cycles of the CPU as a delta from 1500us. Valid range for BAP28 to give 0us to 3000us pulses is +-24000.

There is more information up on the Lynxmotion forums on the use of the HServo command, including this thread:
http://www.lynxmotion.net/viewtopic.php?f=4&t=3224

Kurt


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Wed Oct 30, 2013 4:09 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
Just to follow up a bit on the previous posting. Using HServo the code might look something like:
Code:
index var word
temp var word
prevthrottle var word
throttle var word
   output p11            ; set 11 to output
   low p11               ; make sure it has a low level
   sleep 1000            ; make sure it stays that way for at least one second.
   prevthrottle = 0      ; our current throttle   
   hservo [p11\0]         ; start the servo with 1500us pulses
   ; sleep 1000         ; could not tell if you needed no pulse for 1 seccond or some specific pulse for 1 second?     
main

   ; read potentiometer on pin
   adin16 p3,temp
   temp = temp>>4         ; range of 0-4095
   
   ; assume we want our pulses in the range 750-2250 center at 1500us
   ; With Bap28 gives you an Hservo range of about +-12000
   throttle = ((temp-2048)*12000)/2048   ; simple mapping function...
   if throttle <> prevthrottle then
      prevthrottle = throttle
      hservo [p11\throttle]
   endif
         
goto main

Warning, did not try running this. Also not sure of what you have connected up to adin. Does it give you a complete range of 0-5v or not. Not sure of valid range of pulses... But hopefully helps some.

Kurt


Top
 Profile  
 
 Post subject: Re: AtomPro 28 PWM Output to Motor Controller
PostPosted: Tue Nov 05, 2013 8:21 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
Just to clarify what they meant by a 50hz carrier. They meant that a new 1ms to 2ms pulse should be sent every 20ms. This is a standard servo pulse.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO