Timer on PIC16F1847

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

Moderator: Benj

Post Reply
jack26
Posts: 23
Joined: Sun Oct 09, 2011 4:38 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Timer on PIC16F1847

Post by jack26 »

Could do with some guidance, I am trying to use the timer on a PIC16F1847 but having no luck.

Attached is the modified code which was from an example posted on the forum a while back but for a different processor. Checked the timer settings on the data sheet and as far as I can see I have set the correct values for the 1847.

The compiler would only accept == for assignment of values or gave error 1 so wondered if thats where my issue might be using an incorrect syntax?

When program is flashed to the pic (on pickit 3 dev board) port B0, B2, and B4 are active. RA0 clear does not function neither does the count on RA3.

Operating system is Flowcode 6 on Windows XP.
Attachments
PIC16F1847.fcfx
counter
(4.31 KiB) Downloaded 90 times

jack26
Posts: 23
Joined: Sun Oct 09, 2011 4:38 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Timer on PIC16F1847

Post by jack26 »

Also checked the pic.c file for the 16F1847, attached in case I had the incorrect description for TMR0 etc but seemed ok?
Attachments
Flowcode boostC location.JPG
Flowcode boostC location.JPG (126.54 KiB) Viewed 8182 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 666
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: Timer on PIC16F1847

Post by chipfryer27 »

Hi

From your chart I see you are running on an external oscillator/crystal. I also see you have PLL enable too. However your speed is configured as 4MHz which defines all timer related functions within FC, so that suggests your external crystal is 1MHz. Seems a little low especially as you could run at up to 32MHz just using it's internal oscillator.

What is it you are trying to do?

From your chart you seem to want to set various bits in the Options Register but you are using a comparison (==), which won't set any bits, it will just return True / False depending on comparison.

This link will help explain use.

https://www.webfulcreations.com/differe ... ble-equal/

Hope this helps.

Regards

EDIT
Later editions of FC using a different format but the following examples show differing ways to set/clear bits in a register. This is from memory so hopefully it's correct :)

C-code:

set_bit(option_reg,7);
set_bit(option_reg,WPUB);
clear_bit(option_reg,7);

option_reg=option_reg & 0x7f (where 0x7f is a mask)

jack26
Posts: 23
Joined: Sun Oct 09, 2011 4:38 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Timer on PIC16F1847

Post by jack26 »

Thanks for infomation and can see now result of using == which in my case is pointless.

This piece of code is the last part that I need to complete the controller I have built to replace the powered step on a Ford Transit mk8 minibus. The minibus is a camper conversion I have been working on/off over last couple of years(wifes idea to keep me busy after stroke!).

My design allows manual selection/use of the powered step rather than the auto deloy when stopped and door open etc and its anoying issue of switching the engine off if it thought the step was deployed when it was not.

Ford do not use limit switches to detect the fully open or closed. From inspection of their design they use a hall effect sensor feedback that clocks at about 150Hz so quite slow. I assume that the pulses are counted and so this determines if the step has moved from one postion to the other. Quite crude in my view and probably a reason quite a few commercial opertaors of this mnibus have complained about the 'step deployed' message popping up and the ignition being cut when in fact the step was stowed. In addtion to this 'feature' a 'Tempfet' is used in the motor circuit which I assume they are using to disable the motor if it is driven for too long into a stalled state (temperature rise on the FET).

So my hardware design also uses a tempfet but also a current sensor to detect motor stalled and all of this with the PIC works fine so far. Last part is to monitor the hall effect sensor and that should complete my code/design.

Sorry about long explanation but you did ask!

I have tried afew different combinations as you suggest but still no luck yet. Do you know where I could find the C code format that Flowcode 6 uses and where I might find examples? The books I have just do Flowcode examples but with no C Code.

Thanks,

John

chipfryer27
Valued Contributor
Valued Contributor
Posts: 666
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: Timer on PIC16F1847

Post by chipfryer27 »

Hi

Sounds like a very interesting project indeed. I hope you keep us all informed as it is the sort of thing many of us like to read about.

FCv6 uses "BoostC" (if I'm not mistaken) and you can find out more here

http://www.sourceboost.com/Products/Boo ... rview.html

You should be able to find a manual or the like by searching. I might have one somewhere but would need to look.

I'm not really too familiar with vehicle electronics but funnily enough my friend is converting a Mercedes van into a camper, and I'm getting roped into helping, though I'm pretty sure letting him use the evil lab has a lot to do with that.... my mistake there :)

I see why you would like the manual option to control and also to monitor travel / temperature. I assume you can at present manually deploy from fully closed to fully open (and vice-versa)? Can you monitor the Hall Effect with a scope during deployment? That would give an idea of what is happening inside.

Regards

jack26
Posts: 23
Joined: Sun Oct 09, 2011 4:38 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Timer on PIC16F1847

Post by jack26 »

Unfortunatly the Ford controller does not allow manual driving of the step so it was analysed whilst in auto depoly/retract as per the attachments. Following this it was removed and the body control files for the minibus changed to remove the powered step feature. Because the OEM controller was CAN bus it would have flagged an error on the vehicles management sytems and shut down the ignition system.

Using the Ford controller as a basis I have now designed and built my own but using a PIC micro, this is the one I have been using for the manual testing.

I have had a look through the Boost C manual (version 7 pdf in Boost c for flowcode 6) but despite trying various combinations still no luck.

It looks like I will have to use the interupt on RB0 which does work but not what I wanted.
Attachments
IMG_1924.JPG
IMG_1924.JPG (121.58 KiB) Viewed 8154 times
IMG_1890.JPG
IMG_1890.JPG (127.43 KiB) Viewed 8154 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 666
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: Timer on PIC16F1847

Post by chipfryer27 »

Hi

Looks like we both have the same BoostC manual.

So if I understand correctly, the step doesn't have any limit switches at all, presumably relying on pulse counts, which at 150Hz would equate to the motor/gear running at 9000 RPM?

Using Flowcode you could create an interrupt on INT0 (pin), an Interrupt on Change (typically selectable pins on Port B) or create a Custom Interrupt. These options should allow you to capture the pulses from the sensor. No real need to get involved with "C" unless you go for the "Custom" option. Many examples of this in the forum / WiKi.

When deploying, perhaps then enable the Interrupt, disabling when open/closed? I don't think I'd be too happy just counting pulses though. Is there no way to include any manual limit switches?

Regards

jack26
Posts: 23
Joined: Sun Oct 09, 2011 4:38 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Timer on PIC16F1847

Post by jack26 »

Yes my hardware design (pic attached) has incorporated the facility for both open and closed limit switches. Its unlikly the motor will be running at 9000 RPM probably closer to around 200-400 odd due to the load and being high torque. The hall effect feedback would be from a shaft encoder of some sort, possibly 200 or 360 pulse rev etc.

The issue though is in automotive applications (used to work as electronics design engineer in automotive) we used to have serious reliablity with external switches of any type so assume this was the reason Ford going the route of using encoder feedback alsong with cost and perhaps 'turn key' solution from their supplier for the step.

They also used current sensing though as I mentioned earlier so that would be fine to detect stall/overload. Again my design uses the same approach so 2 methods to detect end of travel although I agree not ideal perhaps.

I have tried a few searches for c code examples on the forum but no luck, any pointers?

I seem to be able to read the timer registers TMR0, TMR1 etc with different results being indicated on port B but think the issue is still trying to set the timer at the begining and also clearing it. Flowcode 6 appears to offer bit set/clear as you have shown me and the version 9 that I have just downloaded on 30 day trial seems to allow both bit operation and complete port, i.e. PORTA etc

Although the int is an option its really bugging me now that I cant get at the timer register!!
Attachments
IMG_3833.JPG
IMG_3833.JPG (104.2 KiB) Viewed 8143 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 666
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: Timer on PIC16F1847

Post by chipfryer27 »

Hi

For me,the great thing about FC is that I don't need to know much about "C" to code. Occasionally I need a C-Code block or two for some specifics and the forum usually heps if I'm stuck.

This is a link to the FCv9 forum providing help with setting timers and creating custom interrupts. It may help. If you are using v9, even in trial, you might want to post in the v9 forum as well. Widen the audience :)

https://www.flowcode.co.uk/forums/viewt ... =10&t=1597

Note though that in FCv7 onwards BoostC isn't used so formats changed a bit, Registers now being in capitals (e.g. OSCCON=0x70; ).

If you have access to the rotating shaft, perhaps a Grey Code Encoder could be fitted / used (Inputs>General Inputs>Grey Code Encoder)? It would give better positioning.

Hope this helps.

Regards

jack26
Posts: 23
Joined: Sun Oct 09, 2011 4:38 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Timer on PIC16F1847

Post by jack26 »

Solved!! its was your comment about upper case being used in Flowcode 9, arggh stupid error. :D

So I changed all references that I had done in upper case for lower and away it went! well pleased thanks.

Attached final code but as you say this forum is probably a bit quieter now.

Must admit that version 9 has a lot of addtional features that I might spend some time looking at.

Off to embed that bit of code and do some testing.

Another project that is nearly finished again uses a PIC to control the Victron equipments various enables and 12V / 24V systems installed in the conversion.

Thanks again,

John
Attachments
PIC16F1847 timer0.fcfx
(4.42 KiB) Downloaded 108 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 666
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: Timer on PIC16F1847

Post by chipfryer27 »

Hi

Glad to hear you have it working.

FCv10 is almost upon us, and having had a preview, it is worth taking a look at once available.

My friend has bought Renogy (?) kit for his van. 3 x PV panels, inverters and batteries to suit. He wanted me to make the PV rack tiltable to track sun but I didn't see much need. Inside not even facing a window each gave a surprising output and outside just lying on the ground it gave about 70% of rated output when not in direct sunshine. I didn't think the benefit of tracking would be there, especially as he's mostly going to use it in UK meaning he will never be thaaaat far from a power outlet :)

He has an issue with his trailer socket. Everything works other than reversing lights. As typical nowadays it a black box affair. +12v, Ground and a CAN connection. However although the wiring allows for reversing lights, his vehicle may be too old to actually require them so the CAN signal may not actually be present.

Anyway, hope the testing goes well.

Regards

jack26
Posts: 23
Joined: Sun Oct 09, 2011 4:38 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Timer on PIC16F1847

Post by jack26 »

Hmm I might hold off for version 10,

Its worth having a look at the Victron web site and their white papers on solar panels. The general thoughts amongst all installers is to have the panels at an angle for optimum output. In saying that I have done mine flat mounted on 45x45 aluminium extrusion and going to see how I get on. The idea being with the extrusion is that its easy to mod later if I decide to hinge the panels. There is a YouTube channel Ladi & Margret. The chap is in Czechoslovakia with his wife and has done a camper conversion with motorised tilting panels. Worth looking at his channel for ideas as he carries out some excelent work.

As you say most vehicles have used CAN bus for a while now which usually includes trailer connection. My son has a Ford CMax 2017 and needed his doing. The ford module was a straight forward plugin and did work 'as is'. However a few things were not right like indicators worked but gave an error, rear parking sensors went bonkers due to trailer being there, rear car foglights were not disabled and so on. Fortunatly the programmer I have is for Fords and so plugging that into the ODBC port allowed the trailer to be enabled in a couple of modules so easy fix. If you dont have a programmer though its not worth the grief and no idea what the dealers would charge.

Thanks,

John

chipfryer27
Valued Contributor
Valued Contributor
Posts: 666
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 203 times
Contact:

Re: Timer on PIC16F1847

Post by chipfryer27 »

Hi

I think v10 is only a few weeks away.

My friend uses extruded aluminium for similar reasons to you but I think he also has some "C-Channel" running the length of the roof each side as the main support rails.

Thanks for the YouTube link. I see the tilting panels and will look at it further.

As for the reversing lights he could always tap into the light connection if needed, but I think he has plans to hang lights from the rack, so I'm not losing sleep, hammock or otherwise, especially as you mention, the cost to get a dealer involved would no doubt be astronomical.

Unfortunately for me he sees some of the "gadgets" and modules I have and takes an interest. "Could you create a custom controller with Bluetooth to do blah blah......." He quite likes the idea of being GSM enabled so that gives plenty of options regarding control and monitoring (e.g. using PushingBox to send alerts or the like). Could be fun :)

Regards

jack26
Posts: 23
Joined: Sun Oct 09, 2011 4:38 pm
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Timer on PIC16F1847

Post by jack26 »

You have my sympathy!

Friends who tell you that ' I bet this would not take you long' or ' I have had an idea'.......nightmare.... :shock:

Best of luck,

John

Post Reply