Balloon Collaboration

Projects => Accelerometer Project => Topic started by: Larry on September 19, 2009, 01:06:01 PM

Title: Parts are here...
Post by: Larry 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.

  for CurPos=90 to 240
  next CurPos
  for CurPos=240 to 90 step -1
  next CurPos
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.

Title: Re: Parts are here...
Post by: Larry 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. :D  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.

Title: Re: Parts are here...
Post by: DaddyB 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  :D
So, Tomorrow, I will see if I can get it to control the servo, now that I know the numbers I am dealing with.

Title: Re: Parts are here...
Post by: Larry on September 22, 2009, 09:11:41 PM
hehe  happens to me all the time, but I usually don't mention it to people ;D

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.

Title: Re: Parts are here...
Post by: DaddyB 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'.

Title: Re: Parts are here...
Post by: Larry 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.

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)

  OSCCON = %01100000
  ANSEL = %11111111
  TXSTA = %00100100
  RCSTA = %10010000
  ADCON1 = %01000000
  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

' Read Accel
' Read Trim Pot
  if DuCy>92 then
  end if
  if DuCy<-92 then
  end if


goto loop


Title: Re: Parts are here...
Post by: DaddyB on September 23, 2009, 04:40:21 AM
Gottit!  T'anks.  :D