Balloon Collaboration
August 17, 2017, 08:01:42 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Hosting for barntek.net has been extended for another 3 years
 
   Home   Help Search gallery Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Parts are here...  (Read 4014 times)
Larry
Administrator
Hero Member
*****
Posts: 1167



View Profile
« on: September 19, 2009, 01:06:01 PM »

Well, all my goodies came in yesterday.  I installed the accelerometer on the SunTracker board and with a few tweaks to the program it worked as good as the photosensor.  But, that was not good enuff.  It still seemed that there were dead spots in the servo and that it had a hard time makeing small movements for fine adjustments.  It would just jump instead.  So, I started a test version of the program to focus strickly on the servo performance.

Quote
loop:
  Pwm_Change_Duty(90)
  delay_ms(1000)
  for CurPos=90 to 240
    Pwm_Change_Duty(CurPos)
    delay_ms(15)
  next CurPos
  delay_ms(1000)
  for CurPos=240 to 90 step -1
    Pwm_Change_Duty(CurPos)
    delay_ms(15)
  next CurPos
  delay_ms(1000)
goto loop

What I found was that in the first loop, the servo drives CCW and seems to do so very smoothly, just like I want.  However, in the second loop when it is driving CW, it is a little more jerky and doesn't return all the way to the starting point.  I don't know if it is the way the pic it talking to the servo or if it is the quality of the servo that is the problem.
Logged
Larry
Administrator
Hero Member
*****
Posts: 1167



View Profile
« Reply #1 on: September 20, 2009, 03:18:40 PM »

Ok, I have been playing around with this stuff and I have learned a few things.  First off, I learned that DaddyB DOES know what he is talking about. Cheesy  I used his Duty Cycle Calculator to work out exactly what values to use with the servo and, thru experimenting, have decided that the servo is ok.  When driven from a pot, it drives really smooth as long as I stay in the -45 to +45 degree range.

I also believe that my problem is with the acceleromter.  I think its output is not as smooth as I would like.

I added a delay to slow down the test program and it seemed to get jerkyer.  So, I thought if I were to speed it up, maybe it would smooth out.  I installed an external clock (20Mhz), and when I went to compile the program, found out that the minimum PWM freq is tied to the Osc Freq of the PIC.  At 20MHz, I cannot get to desired usec needed to drive the servo as designed, so that experiment is out the door.

However, I did learn thet if I drop the PIC freq to 4MHz, I can do my PWM_INIT(400) to give me full control of the servo.  (I was running 8MHz and the minimum PWM freq I could get was 500, which will not allow full 180 degree control of servo.
Logged
DaddyB
Administrator
Full Member
*****
Posts: 144



View Profile
« Reply #2 on: September 22, 2009, 04:22:29 AM »

You might wanna hold off on DaddyB knowing anything.  I have changed over to my accelerometer just to see what I could make it do. I mounted it on the SunTracker Platform. I know I have done this before but it took a while for it to start coming back.
 So the first thing was to try to read the voltage with the LCD.  I finally got it to reading the ADC but it only read correctly when it was 0g.  Either way I turned it, the voltage would decrease from about 2.5v.  What I finally arrived at was, I was using Byte to String instead of Word to String, so I was only reading part of the number. It is working very well now  Cheesy
So, Tomorrow, I will see if I can get it to control the servo, now that I know the numbers I am dealing with.
Logged
Larry
Administrator
Hero Member
*****
Posts: 1167



View Profile
« Reply #3 on: September 22, 2009, 09:11:41 PM »

hehe  happens to me all the time, but I usually don't mention it to people Grin

I still think my accelerometer in only accurate rotating in one direction.  When I rotate it clockwise, it drive the servo smoothly, but when I rotate it counter-clockwise, it hesitates and jumps.  I guess it could still be in my code, but I am leaning strongly toward to accelerometer.
Logged
DaddyB
Administrator
Full Member
*****
Posts: 144



View Profile
« Reply #4 on: September 23, 2009, 01:30:04 AM »

You might try hooking up your LCD and see if the ADC numbers act differently.  That might show you that the accelerometer is bad.  To prove mine wasn't bad I installed it back into the zig circuit and it worked ok there.  I knew then that is was my software.

BTW, if you don't mind, I would like to see your software again.  I can't seem to figure how to make it work the servo based on the reading from the ADC.  One day, when we have a lotza time and we are looking each other in the eye, maybe you can give me a crash course on this kind of control.

Also, I was thinking about the DC motors you were using.  From what I was reading, you can use an "H" bridge circuit to control the motors.  It uses PWM and when you are at 50% the motor is rigidly held in place.  Almost like a servo.  I haven't read much about it but there is a lot of info on the net about the 'bridge'.

Logged
Larry
Administrator
Hero Member
*****
Posts: 1167



View Profile
« Reply #5 on: September 23, 2009, 03:24:36 AM »

This is my code that I am running right now.  I have code for reading the accelerometer rem'd out (GREEN) and it is reading from the trim pot (RED).  If you rem out the code for the trim pot un un-rem the code for the accel, it will position based off the accel.

Try not to pay any attention to all the extra variables dim'd because I am not using them.

Quote
program Test

dim v1 as Integer         'Shadow Sensor  (Feedback Input)
dim v2 as Integer         'Reference Sensor
dim Kerr as Integer       'Proportional Error = Command Input - Feedback Input
dim Ierr as Integer       'Integral Error = Previous Integral Error + Proportional Error
dim Derr as integer       'Derivitive Err = Proportional Error - Previous Proportional Error
dim Pout as Float       'Proportional Calc Output
dim Iout as Float       'Integral Calc Output
dim Dout as Float       'Derivitive Calc Output
dim PrevKerr as Integer   'Previous Proportional Error
dim PrevIerr as integer   'Previous Integral Error
dim PIDout as Float     'PID Calc Output
dim DuCy as integer       'Duty Cycle for Servo
dim CurPos as integer     'Current Servo Position
dim PrevPos as integer    'Previous Servo Position
dim ComLin as integer     'Command Line (where you want it to lock)


main:
  OSCCON = %01100000
  ANSEL = %11111111
  TRISA=%11111111
  TRISB=%00000000
  TXSTA = %00100100
  RCSTA = %10010000
  ADCON0=%11000001
  ADCON1 = %01000000
  portb=%00000
  Pwm_Init(400)
  Pwm_Start
  CurPos=0             'Set Initial Current Position at Full East
  Pwm_Change_Duty(153)    'Drive Tracker to Full East
  delay_ms(2000)          'Give it time to get there

loop:
' Read Accel
  'v1=adc_read(2)
  'PIDout=v1*355/1000
  'DuCy=PIDout-157
 

' Read Trim Pot
  v2=adc_read(3)
  PIDout=v2*111/1000
  DuCy=PIDout-57
 

  if DuCy>92 then
    DuCy=92
  end if
  if DuCy<-92 then
    DuCy=-92
  end if
  Pwm_Change_Duty(DuCy+153)

  'delay_ms(20)

goto loop

end.
Logged
DaddyB
Administrator
Full Member
*****
Posts: 144



View Profile
« Reply #6 on: September 23, 2009, 04:40:21 AM »

Gottit!  T'anks.  Cheesy
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!