16F1827 Read 1/2 pulse

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

16F1827 Read 1/2 pulse

Post by Bobw »

I am using a Hall sensor to read gear position. there are 6 off and 6 on pulses per revolution.
Using P_Count =3 per degree of movement I under shoot on a 360 rotation.
Using P_Count =4 per degree of movement I over shoot on a 360 rotation.
I either need to be able to count a 1/2 pulse, or move where I am incrementing the Degrees of rotation in my program.
Everything else works fantastic.
Suggestions are welcome.

Bob
RotorComp168.fcf
(32.34 KiB) Downloaded 350 times

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by Jan Lichtenbelt »

Dear Bob,

I have just a small remark
Ant_Pos = Pos_High +Pos_Low
is not correct. This should be:
Ant_Pos = Pos_High <<8
Ant_Pos = Ant_Pos+Pos_Low

Instead of:
Ant_Pos = Ant_Pos*-1
Ant_Pos = -Ant_Pos

Succes

Jan

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by Bobw »

Jan,

I may not have written it to proper way, but it works. That is just the part that stores the antenna position in EEPROM for future recall after a power down.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by medelec35 »

Hi Bob,
Try attached flowchart.
It should hopefully be set up to read 1/2 pulses.
I have not adjusted the P_Count = 3 value.
Have left left that for you to experiment with.

Martin
Attachments
RotorComp168_Modified.fcf
(28.94 KiB) Downloaded 326 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by medelec35 »

Bob,

Just had a thought (that's a rare event for me :P ) :lol:

What would happen to your hardware if a sensor or connection to sensors fail?
Since motor will be continuously turning and left unnoticed
Could premature failure or over heating or damage occur?

Whether it can or can't, it will be straight forward to have a non sensor detection time-out of your choice.
If Motor is called for and sensor does not detect movement in say 2 seconds, then power to motor can be removed, Direction LED or LCD (or both could could flash)

Also if your interested, I could change your flowchart so motor detection is using port B interrupts, so your program can do other things whist in motor turning routine.

If you could let me know if you would like one both or no changes, then I can take necessary action.

Did the flowchart I posted work for you?

Martin.
Martin

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by Bobw »

Martin,

I wish I had thought about writing the counting routine that way. Gave me much better accuracy than before. I still have about a 5 degree over shoot, but only when traveling >200 degrees. I can live with it. I have thought about a RUN AWAY or NO MOVEMENT routine to the program. Just been a bit busy to add it in. Been fighting with the IR sensor that gives me the HOME position. Trying to find the best spot and size for the reflective tape. A roller plunger switch would be better but very expensive or too big to fit. I was using a paddle switch for the UP/DOWN but found a rotary switch with spring load to center that I like better. Just waiting for it to arrive. Found some rub-on letters to stencil the front panel with, will post some pictures when I get it done. And I thought the hardware portion of this was going to be hard!!

Bob

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by medelec35 »

I can add the no movement and overrun for you to try. No movement is the easiest, where as overrun would require use of portB interrupt.
As for overshoot should be fairly simple. just work out how much overshoots by, and should be able to use a calculation or look up table to exit loop prior to overshoot.
Look forward to seeing those pictures.
Glad the modified flowchart is working better for you.
Thanks for letting us know.

Martin.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by medelec35 »

I have added motor/sensor error for you.
Currently I have set it for 3 seconds.
Where you see Seconds = 3
It's the difference between this and Seconds > 3 that determine the LED flashing duration. E.g. >3 is same as =4 or greater. 4-3 = 1 so LED is flashing every one second.
One thing I have noticed:
You have osccon = 0x7a; = 16MHz
Your Flowchart target clock speed was set for 19.6MHZ
This may cause some characters to be incorrectly displayed randomly?
I have corrected this so timer0 can time the seconds with more accuracy.
I am surprised LCD was working correctly.
Hope you like the improvement of the motor/sensor error.
Attachments
RotorComp168_Modified2.fcf
(32.62 KiB) Downloaded 325 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by medelec35 »

Bobw wrote:I still have about a 5 degree over shoot, but only when traveling >200 degrees. I can live with it.
I have taken care (well believe I have :P) of the over shoot for you.
This time you will need to set your own value of (Ant_Pos - Go_To) >1
and all P_Count = connected to it.
Hopefully its more like to final version you imagined it would be like prior to starting the project.
Attachments
RotorComp168_Modified3.fcf
(33.89 KiB) Downloaded 322 times
Martin

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by Bobw »

I am trying to run the chip at 32MHz.
I have the following added to the beginning of my C code:

osccon = 0x70;
osctune = 0x40; <--- not sure if I need this.

Went to the chip configuration and ENABLED the PLL.
Went to project options and set the clock speed for 32000000.

Pointing accuracy is better than some of the commercial models. Got my Home sensor working.
Decided NOT to use an ERROR routine for several reasons.
1) Get a very audible click when the relay for the motor turns on.
2) The display by design jumps to the left soon as the first pulse is registered.
3) I have signal strength read out on my radio.
These 3 thing will let you know real quick if the rotor is actually no turning, or fails to stop when it should.
If this were a commercial project then yes I would add something..
Will post what I hope is a final version soon as I get the clock running full speed.

PS: Martin thank you for all your help getting this thing going.

Bob

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by medelec35 »

Bobw wrote:I am trying to run the chip at 32MHz.
I have the following added to the beginning of my C code:

osccon = 0x70;
osctune = 0x40; <--- not sure if I need this.

Went to the chip configuration and ENABLED the PLL.
Went to project options and set the clock speed for 32000000.
Not sure why you have used osctune = 0x40;
The default is 0 = factory calibrated setting.
I believe you only use osctune for fine tuning of osc. E.g if drifting due to VDD or temperature changes.
So you can leave it out.
Settings look correct for 32MHz int osc.

Did you use the overshoot routine to improve the accuracy, or did you leave that part out as well since accuracy improved with reading 1/2 pulse routine?
Bobw wrote:PS: Martin thank you for all your help getting this thing going.
No problem. Just glad I could actually help.

Martin
Martin

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by Bobw »

Martin,
And all others following this......
This is what I would call the final version.
Running at 32 Mhz Really corrected accuracy issues
EEPROM Read/Write is working. (had to paste in the C code for EEPROM to work)
IR Zero/Home position sensor is working. (Not wired to the PIC)
Positioning is +- 1/2 degree (as good if not better than the commercial units)
New spring to center switch arrived and installed, like it much better than the paddle switch I was using, much softer movement.
Still have to finish the lettering but here ya go.

Bob
Yes the back light is RGB but manually controlled.
RotorComp181.fcf
(29.19 KiB) Downloaded 292 times
Controller181G.JPG
Red backlight
(244.39 KiB) Downloaded 1733 times

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: 16F1827 Read 1/2 pulse

Post by Jan Lichtenbelt »

Hi All,

Just today I started for the first time to use the 16F1827 microcontroller. And of coarse I choose this one, because there is a possibility to use the internal clock of 32 Mhz.

To use the 32 Mhz, you have to set the osccon register to 8 Mhz AND you should enable 4X PLL (see section 5.2.2.6 of the datasheet http://ww1.microchip.com/downloads/en/D ... 41391D.pdf).
This can be done all at once in the osccon register (see chapter 5.6):
Bit 7 SPLLEN must be 1
Bit 6-3 must be 1110, the IRCF internal oscillator Frecency select bit must be set to 8 MHz
Bit 2 always 0
bit 1-0 must be 00, SCS system clock select. With 00 Clock will be determined by FOSC<2:0>,
FOSC gets 4 by SPLLEN set to 1 (bit 7). This results in a frequency of 8 x 4 = 32 Mhz

The following C-code is necessary for the 32 Mhz internal clock of 16F1827:

osccon= 0xF0;


Kind regards

Jan Lichtenbelt

Remark: I'm afraid that the 'usual setting' of osccon=0x07 is completely wrong for this microcontroller 16F1827 with 32 Mhz internal oscillator.

Post Reply