Servo Issue

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Servo Issue

Postby JLeith » Thu Jan 24, 2019 12:39 am

Hello all
Need some wisdom ASAP. I have a working Flowcode project but it will not load into my PIC16F1938

I have about 12 hrs from Jun 23 3:29 PST

My gradson was going to us the Servo to dispense Candy like a vending machine.

The design looked simple and works in flowcode perfect. Press the button and the Servo advance to 125 and zero.

I keep getting a error :
-A Vdd setpoint exceeds maximum for this device of 3.6V

I took a program design that had a pot to advance the servo.

I changed the Pot for solid value. Changed the Chip and the Oscillator to internal

I have attached the program and the picture

The VCC is 4.5V DC from Battery

I have no idea where the setting is for the VDD

Please give me a quick answer I spent 16hrs last night and no luck.

I did confirm the chip is working because I loaded another program into the pic that was not using a Servo design and it worked 100%

John
Attachments
Error36.png
Error36.png (14.03 KiB) Viewed 2354 times
Evan Servo Jan 23.fcfx
(13.03 KiB) Downloaded 29 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8377
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Servo Issue

Postby medelec35 » Thu Jan 24, 2019 6:56 am

Hi John
If you look at the screen shot of the pickit settings, it's showing the device as 16LF1938 (low voltage version) instead of 16F1938.
Check and change your target device.
These users thanked the author medelec35 for the post (total 2):
Benj (Thu Jan 24, 2019 1:48 pm) • JLeith (Fri Jan 25, 2019 6:18 pm)
Rating: 10.53%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Sun Jan 27, 2019 1:28 am

Thank you Martin
I must have looked at the PIC 7 times and only confirmed the 1638

Martin Back in the day you indicted I should use a Led as a flashing indicator ?

I have this in my design and it doesn't work as I think it should

I have a loop In Main for RA2 and it won't light in the breadboard ?

I have another LED in the 'Candy Macro" for B5 and it should only come on when I press a button on a interrupt on B1

Odd when I step thru the flowcode and trigger B5 Led I appear to trigger the interrupt B1

I set the Interrupt on B1 by selecting the pin.

I have a drawing
And Flowcode

John
Attachments
Candy PIC layout.png
Candy PIC layout.png (189 KiB) Viewed 2304 times
Evan Servo Jan 26.fcfx
(17.57 KiB) Downloaded 30 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8377
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Servo Issue

Postby medelec35 » Sun Jan 27, 2019 1:49 am

Hi John,
Not a problem
The osccon registor within a c code block sets the internal osc speed.
You have got that C code block disabled.
You are showing nothing connected to MCLR pin, yet that is enabled within configuration settings.
If you have not got anything connected to MCLR pin, then it must be disabled.

Where interrupts are concerned you have to have a little as possible in them.
For example set a flag or increment a variable.
Having the same component and delays within interrupt call macros as you do for non interrupt macros causes corruption.
Remove all you can from within the interrupt!
These users thanked the author medelec35 for the post:
JLeith (Tue Jan 29, 2019 6:01 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Tue Jan 29, 2019 6:01 pm

Hello Martin

Thank you for the info.

On the MCLR I have a 10K resistor connected to +5 for the PICkit 2 access. So the MCLR is held to logic 1

For the C code I forgot to enable while I was frustrating finding out why my leds would activate as in the flowcode

Where interrupts are concerned you have to have a little as possible in them.
For example set a flag or increment a variable.


Martin are you indicating on the "little as possible" for interupts that If I use (B0) as my button trigger I can't use pins (B1-B7) for any action ?

In the "flag or increment a variable" is this meaning I should set a variable in the interrupt ?

Off to see what I can uncover. Back soon

John

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8377
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Servo Issue

Postby medelec35 » Tue Jan 29, 2019 9:58 pm

JLeith wrote:Martin are you indicating on the "little as possible" for interupts that If I use (B0) as my button trigger I can't use pins (B1-B7) for any action ?

Yes you can but within the interrupt set a variable depending on what button is pressed.
You can have inputs which won't cause any issues to set a value to a variable.
Then within main, you can process the variable and even use a call macro.
JLeith wrote:n the "flag or increment a variable" is this meaning I should set a variable in the interrupt ?

Yes by far the best way.
Never use a call macro within an interrupt.
These users thanked the author medelec35 for the post:
JLeith (Thu Jan 31, 2019 8:17 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Thu Jan 31, 2019 8:31 pm

Hi Martin
I changed the Interrupt to DISP=1 so when the Button on B1 triggers the action should work ?

In flowcode it works.

In Breadboard it does not work ???

I have my digital scope on Trigger action on B1 and it does not activate. Only activates when I press B1.

Well in the breadboard My LCD says it registers DISP=1 even when I have the variable set to DISP=0 and I have set the value DISP=0 to ensure the Decision loop should only Loop Why DISP=0.

Putting LCD messages to see where the flow is going I see the loop does go into DISP=0.

For some reason I can't see the breadboard LCD Says it reads DISP=2 and only why I can see that if it thinks the trigger B1 tripped

Can you see anyway in the flowcode that I missed as to why the Breadboard thinks DISP=2.

Can I put my scope some where to trace the breadboard action.

I have attached the current Flowcode Design.

I can't also get my A1 to flash when it enters the Loop in Flowcode it flashes but not in the breadboard it comes on but not on/off.

John
John
Attachments
Evan Servo Jan 31.fcfx
(22.09 KiB) Downloaded 34 times

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Thu Jan 31, 2019 8:39 pm

Martin a further note

If I connect the servo it pulse a couple of times and then the LCD flashes like the Servo is killing the power source

John

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Thu Jan 31, 2019 8:49 pm

Here is where I see the Value of DISP=2

Picture
Attachments
DISP2.png
DISP2.png (11.75 KiB) Viewed 2218 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8377
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Servo Issue

Postby medelec35 » Thu Jan 31, 2019 9:59 pm

Hi John,
Have you done a one second flash test to see if everything is set up correctly?
If so will be surprised if delays are correct as you still got osccon statement commented out.
If the delays are way out then the 1 - 2 ms required for servo will be wrong causing access current and servo to burn out.
That could be why you are seeing the chip resetting?
Have you scoped the servo pulse to see if 1 - 2mA every 20ms?
Also, when pulse is detected then the DISP is set to 2.
The Candy macro is called, then there is a loop within, which is only activated when DISP =1 which is never, so the loop will not be accessed.
However as you reset DISP to 0 within the loop, even if loop was changed to while DISP = 2 or the interrupt wsa changed so DISP = 1 then the loop being there is a complete waste of time.
I have removed goto points as you can use a loop instead.
Much better programming practice.
Not sure why you have seconds variable counting down as its not being used on the display etc.
I have linked the servo controller to the servo motor so the motor will now move within simulation.

Give the attached flowchart a try, but first set up the one second flash test.




.
Attachments
Evan Servo Jan 31 V2a.fcfx
(21.68 KiB) Downloaded 26 times
These users thanked the author medelec35 for the post:
JLeith (Thu Jan 31, 2019 11:49 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Fri Feb 01, 2019 12:29 am

Thank you Martin

I follow the double loop for the flashing of the led.

I didn't know about the Button bounce protection. I use to use the Button properties

I cleaned up my LCD messages.

Have you done a one second flash test to see if everything is set up correctly?

? Not sure how to do a "one second flash test" ?

I have printed off your design for future projects.

Some of my patch work was trying to see where my code was going sideways.

I added the Servo back in and it moves but around but the code won't run. (Picture - Servo Loop)

Put the scope on the B1 pin without the servo connected ( Picture 125 or 0)

Looks like the servo is bouncing from 125 to 0 when it is connected. The servo is Model: HXT900

Maybe I should go back to using RS232 communication to the Servo or should it work as I have it designed.

John
Attachments
125 or 0.png
125 or 0.png (7.84 KiB) Viewed 2205 times
Servo Loop.png
Servo Loop.png (13.71 KiB) Viewed 2205 times

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Fri Feb 01, 2019 12:31 am

Here is the cleaned up flowcode

John
Attachments
Evan Servo Jan 31 V1b.fcfx
(21.19 KiB) Downloaded 18 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8377
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Servo Issue

Postby medelec35 » Fri Feb 01, 2019 12:34 am

All working?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Fri Feb 01, 2019 12:38 am

Hi Martin
The A1 pulse works and the Button activates

The servo not so much.

Its like the servo dosen't have a home position and jumps back a forward ?

John

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8377
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Servo Issue

Postby medelec35 » Fri Feb 01, 2019 8:49 am

JLeith wrote:I didn't know about the Button bounce protection. I use to use the Button properties

That is only when you use The switch component macros i.e. ReadState, WaitUntilHigh & WaitUntilLow.
As they are not used within interrupt, then debouncing will be required.
JLeith wrote:? Not sure how to do a "one second flash test" ?

Just follow the link embedded in the question asking you about one second flash test.
Is the server not acting like it is in the simulation?
Waveforms for the servo look correct so not sure what you are stating the issue is.
Can you explain in detail what is happening with hardware and how it's different to simulation?
These users thanked the author medelec35 for the post:
JLeith (Fri Feb 01, 2019 9:23 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Fri Feb 01, 2019 9:27 pm

Hi Martin

Missed the link to second flash test, Printed it off for future knowledge

For the Servo I will retest. Do you know of a test for the servo by it self.

I will send a video of the action

John

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8377
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Servo Issue

Postby medelec35 » Fri Feb 01, 2019 9:58 pm

Don't forget to let me know what your expecting the servo to do V what it actually does.
The only test I can think of is either using a pot to control servo or just set variable controling servo to 0, 127, 255 to check for fully clockwise, center and counter clockwise.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Fri Feb 01, 2019 10:06 pm

I put the action Enable Servo in a separate macro and it flips back and forth

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Fri Feb 01, 2019 10:40 pm

Try two more Servo and they do the same action

Here is the current Flowcode.
Attachments
Evan Servo Jan 31 V1b.fcfx
(21.41 KiB) Downloaded 11 times

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Fri Feb 01, 2019 11:02 pm

Hi Martin
I noticed once the Servo is going back a forth the PIC stops running the script. The Button is ignored and I have to reload the flowcode.

I even copied the Flowcode Single Motor that uses the pot to determine the action of the servo.

Just set the "IN: value to 125 or 0 and it still runs back and forth

Here is the flowcode with Macro Servo1
Attachments
Evan Servo Jan 31 V1b.fcfx
(22.8 KiB) Downloaded 16 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8377
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2384 times
Been thanked: 3415 times
Contact:

Re: Servo Issue

Postby medelec35 » Sat Feb 02, 2019 11:30 am

Sounds to me like a hardware issue.
Could be the power supply not up to the job. The way to find out is scope the servo signal line with servo disconnected.
If it's steady at say 1.5ms every 20ms then is not software. With servo connected and playing up, scope power supply line.
You may have to set up to capture on less 4.5v.
If power supply is dipping then it's power supply not man enough or faulty servo. If power supply is steady then probably a servo fault. What power supply have you got and can't you try with a much better one?
What about decoupling and smoothing caps across the power pins of MCU?
Don't for inside a servo is a DC motor .
When it first starts from the stalled condition, the will be a much higher starting current for a brief period of time.
The power supply has to handle that without output voltage dipping.
These users thanked the author medelec35 for the post:
JLeith (Sat Feb 02, 2019 5:41 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Sat Feb 02, 2019 5:40 pm

Hi Martin
I have tried 3 Servo and they all do the same action.

The drawing on post ( Thu Jan 31, 2019 3:29 pm ) is with the Servo disconnected.

I used a Trigger on my digital scope ( UTD2052CEX) now I can't get the trigger to stop and go to live. More work on the scope.

The power supply is one I have used on all my projects. From the Scope image it looks like a steady 4.5v output.

From the scope image it looks under 2ms. and 0 degree is under 2ms

In flowcode I don't see how we determine the 2ms on/off it looks like in flowcode i send 125 and then go back to the code.

Would we not have to have the B0 port PWM for 2ms. Maybe the signal is not long enough for the Servo.

Off to see what is happening to my scope.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Sat Feb 02, 2019 6:47 pm

Hi Martin

It looks like the PWM is sending a pulse value on/off when I monitor the PWM without the Servo.

PWM.png
PWM.png (4.18 KiB) Viewed 2146 times


That must be what the Servo is seeing.

Is there a way in PWM only to send and stop ?

John

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Sat Feb 02, 2019 7:07 pm

Hi Martin

For some reason the PWM keeps the Signal going out and the servo is trying to follow the beat.

Defiantly PWM is not working the same in Flowcode as in the PIC design.

I noticed when I restart the program the PWM is at logic 0 level and once I ask the PWM to send out a 125 or 90 or 25 is sends it out but doesn't stop sending.

Is there a another timer we could try and send out a value with time of 2ms ?

John

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: Servo Issue

Postby JLeith » Sat Feb 02, 2019 7:17 pm

Hi Martin

Just noticed a servo question in the forum from Benj

This Forum message is in Flowcode 7 is this maybe the same issue in Flowcode 6 ?

Post by Benj » Wed Apr 25, 2018 9:54 am
Hello Enrique,

The Servo component requires 2 PWM channels to allow the Servo output to be generated. The 16F819 only has one PWM channel


.......................
John