Having trouble adding a new object to an existing program and run it in a new cog
I am very new at prop programming. I have created a program the will read the Parallax "5 position switch" and display the switch positions on a 2 X 16 Parallax LCD.(5PositionSwitch_LCD.spin) I ultimately want to control a servo with the switch.I found a Servo control object in the OBEX library called"Single Servo Spin". I have tried to incorporated it into my existing program but am not having luck. The program will compile and load into RAM but the LCD never initializes and no response from the switch or the servo.
If someone could look at my programs and give me a hint it would be greatly appreciated.Starting the Single Servo Spin in a new cog has got me confused and I suspect that is where the problem lies.
thanks
MikeS
If someone could look at my programs and give me a hint it would be greatly appreciated.Starting the Single Servo Spin in a new cog has got me confused and I suspect that is where the problem lies.
thanks
MikeS
Comments
VAR long servoBuff[10] long servoPos long servoPin long cog CON _clkmode = xtal1 + pll16x ' System clock ? 80 MHz _xinfreq = 5_000_000 ' Using 5 MHz external crystal oscillator ' Servo signal to this I/O pin-change if needed PUB Start(servo_Pin) servoPin := servo_pin cog := cognew(Servo, @servoBuff) + 1 PUB ServoChange(servo_Pos) servoPos := 400 + 18 * servo_Pos ' scale servo between .4 to 2.2 milliseconds PUB Servo | tInc,tHa, tc, t ctra[30..26] := %00100 ' Configure Counter A to NCO ctra[8..0] := servoPin frqa := 1 ' add 1 to PHSA every clock cycle dira[servoPin]~~ ' Set up cycle and high times tInc := clkfreq/1_000_000 ' clock cycles in 1 microsecond servoPos := 1500 ' 1500 microseconds = 90 degree position to start t := cnt ' Mark counter time repeat ' Repeat PWM signal tHa := tInc * servoPos ' update the pulse on time in clock cycles tC := tInc * 20_000 + tHa ' update the required interval in clock cycles phsa := -tHa ' Set up the pulse t += tC ' Calculate next cycle repeat waitcnt(t) ' Wait for next cycle
So I'd suggest increasing the stack (e.g. stack[32], you can always make it smaller later). And before you start the motor cog, give position a meaningful value.
Thank you for you suggestions. I will increase the stack and initialize the position to a value within the range given in the single servo spin program.
Thanks,
Mike
cognew(empty, @stack{0}) PRI empty repeat
does the LCD still refuse to initialise? Also, could you do another test and keep the motor in the cognew but do something simple afterwards, like blinking an LED? For clarity, could you also attach your current code (preferably archived)?I "think" I may have found the problem. I noticed that if I did not plug the servo motor into the board that the LCD would go ahead and initialize. I increased the size of the power supply from 9.0v - 300ma to 9.0v - 500ma and the program appears to run now. There seems to still be a timing issue between the LCD displaying the switch position (doesn't always display) and the movement of the servo, but the servo is now moving in concert with the switch..
I appreciate your reply and help, it encouraged me to pursue a solution to the problem
.
Thanks,
MikeS