• AVR Freaks

Helpful ReplyHot!Odd PWM Q?

Author
mpgmike
Super Member
  • Total Posts : 286
  • Reward points : 0
  • Joined: 2014/01/23 17:27:06
  • Location: NJ
  • Status: offline
2019/09/20 18:03:59 (permalink)
0

Odd PWM Q?

I'm working on a generator project (1.5 kW, 2.8 HP) to showcase a technology.  Part of the project calls for electronic fuel injection.  The throttle is controlled by a Futana S3016 servo.  Information for this piece is severely lacking.  Nevertheless, I got it working, but with a rather unique algorithm.  It seems standard PWM doesn't work.  The OFF time must be fixed (I tested 0.8 to 1.0 ms successfully) while the ON time varies from 0.6 (idle) to 2.3 ms (Wide open throttle).  For bench testing I'm using a PIC16F18313.  Ultimately the controller will use a dsPIC33EP256MU806.  Here is the code that's working:
 

void main(void) {
uint16_t Throttle;
uint8_t Pot;
int i;

InitMain();       //Sets SFRs for ADC, OSC, TRIS etc.
while(1) {
ADCON0bits.ADGO = 1;  //Get analog value of adjustment pot
while(ADCON0bits.ADGO == 1);
Pot = ADRESH;    //Read ADC-8 Value
Throttle = Pot + 190;  //ADD 190d
LATAbits.LATA2 = 0;  //Runs through 2N7000 MOSFET, so Throttle sees inverted signal; active low
for(i=0; i<Throttle; i++) {
__delay_us(1);      //Each run adds approximately 1 us to the active low signal
}
LATAbits.LATA2 = 1;   //Output goes low
__delay_us(800);    //Fixed OFF time
}
}

As the "ON" time varies, the frequency also varies.  Is there some cool trick in the dsPIC33E arsenal that covers this?

I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
#1
du00000001
Just Some Member
  • Total Posts : 3076
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: Odd PWM Q? 2019/09/20 18:29:39 (permalink) ☄ Helpfulby mpgmike 2019/09/21 07:59:22
4.67 (3)
Hi Mike,
 
assuming you've got a Futaba S3016: you never had a model-making servo before? No need for "experiments" - see
   https://en.wikipedia.org/wiki/Servo_(radio_control)   and   https://en.wikipedia.org/wiki/Servo_control   for some basic information!
 
No need for variable frequency PWM - implement a 50 Hz PWM!
Position coding does somewhat vary between models, but pulse widths of 1..2 ms up to 0.5 .. 2.5 ms pulse widths are somewhat common. (The exact range should be in the product documentation.) These servos have their own controller chip for closed-loop position control.
 
The "weird" control signal results from the time division multiplex scheme of the model RC - historically transmitting up to 6 or 8 channels in a serial scheme. (8 * 2.5 ms would give the 20 ms time frame.)

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#2
mpgmike
Super Member
  • Total Posts : 286
  • Reward points : 0
  • Joined: 2014/01/23 17:27:06
  • Location: NJ
  • Status: offline
Re: Odd PWM Q? 2019/09/21 08:01:29 (permalink)
0
No, I never worked with a servo before.  The documentation doesn't cover much of anything on the control side, just lists how fast it rotates, torque, and stuff like that.  Thank you for the links.  I'll go back to the bench & experiment some more.  I wanted to test everything before committing to the PCB.  At least now I have some guidance.

I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
#3
NorthGuy
Super Member
  • Total Posts : 5688
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: Odd PWM Q? 2019/09/22 08:36:15 (permalink)
0
Not that you need this, but you can change the PR register in the timer interrupt to produce variable-frequency PWM.
#4
mpgmike
Super Member
  • Total Posts : 286
  • Reward points : 0
  • Joined: 2014/01/23 17:27:06
  • Location: NJ
  • Status: offline
Re: Odd PWM Q? 2019/09/22 10:12:12 (permalink)
0
I have to boot a long-overdue project out the door in the next day or 3.  I will start testing on a dsPIC33EV256GM002 (28-dip I can breadboard) soon.  I had thought of the Timer/Interrupt approach.  I am also tapping the USB function in the dsPIC33EP, so I don't want too many interruptions that may interfere with USB.  May just have to "crank 'er up & see how she runs" with USB functional.

I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
#5
Jump to:
© 2019 APG vNext Commercial Version 4.5