Advice needed for Newbe

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Post Reply
Billoo
Posts: 12
Joined: Mon Oct 30, 2017 10:23 am
Has thanked: 10 times
Contact:

Advice needed for Newbe

Post by Billoo »

Hi Everyone,

This is my first ever post on the Matrix forums and I’m hoping that someone can offer some help and advice on a little project I’m working on.

Firstly a little about me. I’m no programmer (hence my interest in Flowcode), and I’m also no electronics guru, more of a general designer/engineer with some very simple scripting knowledge, and some basic electronics knowledge going back to the 80s!

Secondly, I’m presently using an unlocked demo version of Flowcode 7, so up against the clock to see if I can get what I need to work, before I commit my hard earned to the full version with a Pic pack, as I will need the software commercially going forward to generate different variations.

My project I’m thinking should be basic stuff as all I’m looking to do is control five LEDs in different fixed (defined by the code) looping combinations, and I need to use the smallest and cheapest Pic to do the job, and the smallest amount of supporting components to keep the PCB very small.

Presently I’m using a 12f675 with a Pickit3 programmer and I can get most of everything to work perfectly both in Flowcode, and on the real circuit so when power is applied, the LED pattern runs and loops for a number of times to give a duration of 10-15 seconds then stop. The final part of the puzzle was to add a PTM switch to trigger the program, and this is where I have hit a wall…!!

Digging around on the net I find many 12f675 projects that use both LED sequences and a PTM trigger switches, so I’m convinced the little chip can do what I need however, any example code is either .hex so pointless to analyse, or .asm which for me is incomprehensible :?

The only tutorials I can find that are switch/LED and Flowcode related use other larger microcontrollers, and also use different ports (PORTA for the switch & PORTB for the LED’s), and it seems that in Flowcode 7, PORTA is the only option for the 12f675.

My suspicions are that maybe the 12f675 is not suitable for the task as I did have a 16f676 in my pot (although it’s too big for my needs package wise) and gave it a go, but whilst it did give me both PORTA and PORTC options and I could get it to work in Flowcode, I couldn’t get it to work for real using the same circuit as the 675.

Any advice/pointers on chips, programming etc. would be greatly appreciated, and if you need me to upload any projects and/or circuit diagrams, please let me know. Many thanks in advance.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Advice needed for Newbe

Post by Benj »

Hello,

Regarding the switch can you confirm you have wired the switch as shown on the schematic here.
https://www.matrixtsl.com/wikiv7/index. ... )#Examples

Basically you need two resistors, one to pull the micro input pin to the off state and the other to limit the current when the switch is pressed.

Hopefully this is all that is required to get your 675 up and running as required.

Billoo
Posts: 12
Joined: Mon Oct 30, 2017 10:23 am
Has thanked: 10 times
Contact:

Re: Advice needed for Newbe

Post by Billoo »

Hi,

Many thanks for the quick response. I have been following the guides on the Matrix website and using the "Active High" config as in the link.

Could the issue be in the way I have Flowcode configured as the code isn't working with the switch in the simulator, so wouldn't expect it to work for real however, I did try it!
Attachments
Running5timed.fcfx
(15.21 KiB) Downloaded 226 times

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: Advice needed for Newbe

Post by medelec35 »

Hi Billoo,
You don't want the switch component icon.
The name is confusing so not your fault!
Use the Decision icon (one above the switch component) instead
For

Code: Select all

IF:
within decision branch component properties just use the Variable you named

Code: Select all

switch
Martin
Martin

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: Advice needed for Newbe

Post by Docara »

Hi Billoo,

Welcome to the forum!

Can you post a little more info of what you're doing , length of timings etc we probably will be able to help a lot more than what's been posted already.

Thanks
Matt

Billoo
Posts: 12
Joined: Mon Oct 30, 2017 10:23 am
Has thanked: 10 times
Contact:

Re: Advice needed for Newbe

Post by Billoo »

Many thanks to all for your help, much appreciated.

In order to stave off the effects of unemployment, I'm looking to bring a product to market early next year which in a small part needs four or five LED's that light in different patterns depending on which version of the product the PCB if applied to. This may be a simple repeating running light sequence i.e. 12345, 12345 etc. for say 10 seconds, or it could be 12345, 54321 or 1 & 5 on for the duration and 234 flashing, the permutations are endless and why I though doing it on a PIC was the best way forward. Timing wise its not critical, 10-15 second should suffice.

Each pattern will be fixed for the chip that goes in that version, there is no need for it to change once set.

In operation the electronics need to be powered by 2 x 3V coin cells and the LEDs triggered by a simple momentary switch. That it!

I had already tried using the "Decision" Icon as Martin suggested, and whilst it worked in the sim, it wouldn't trigger on the live circuit and as I was following a tutorial for V6, and wondered if it had changed in V7 so tried the "Switch" instead. Just to confirm, I just tried reverting it back and again its working in the sim, but not in the live circuit with the active high config.

Cheers
Bill

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: Advice needed for Newbe

Post by medelec35 »

Hi Bill,
You have got clock speed set for 2000000Hz whereas it should be set for 4000000.
Also you have not got weak pull-ups enabled.
Therefore where the switch is connected you need to either enabled weak pull-ups which I can help you with.
If you do that you will need to change decision to:

Code: Select all

If switch = 0 Then do LED pattern
Or
Connect an external resistor of say 2K2 to 10K from microcontroller pin to GND.
Connect switch from microcontroller pin to +VCC.
Ben posted a link on how to wire up switches.

So sounds like an issue with hardware.

Can you post a circuit diagram of what you would like to do.
Then I can help you with your flowchart.

Martin
Martin

Billoo
Posts: 12
Joined: Mon Oct 30, 2017 10:23 am
Has thanked: 10 times
Contact:

Re: Advice needed for Newbe

Post by Billoo »

Many thanks Martin.

I have made some changes to the original code, to add back in one of the loops that I originally had but took out for trouble shooting, and the updated version is attached along with the circuit.

Without the switch, this circuit worked great and was proving to be reliable, it was once the switch was added that all went the way of the pear!

I also took the cap out just in case it was causing an issue but it made no difference.

Where would the parameter be for enabling weak pull-ups?

Apologies for my naivety, it has been such a long time since I played with electronics, and still finding my way around Flowcode although I'm enjoying the challenge and do like the software :D

Cheers
Bill
Attachments
Circuit1.jpg
Circuit1.jpg (400.77 KiB) Viewed 11036 times
Latest_Running5timed.fcfx
(14.75 KiB) Downloaded 213 times

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: Advice needed for Newbe

Post by medelec35 »

Hi Bill.
Although simulation will show different, GP3 is an input only so it will not drive a LED.
So you could use GP3 for the switch:
12F675 GP3.png
(29.44 KiB) Downloaded 5341 times
Within Configuration settings you have got MCLR as external.
That means MCLR (GP3) pin must be pulled high via a resistor e.g 10K, if programming via ICSP.
If using MCLR as GP3 input, then MCLR must be changed to internal.
With MCLR set as external if not pulled high, then Microcontroller will be permanently in reset status, so hardware will not run at all.

You have not changed the clock speed to 4000000.
If you don't change the speed to 4MHz to match the internal clock speed of 12F675 then all the timings will be out.
For example 1 second delay on hardware will actually be 20/4 *1 = 5 seconds.

If you want to minimize hardware you can remove the resistors from the switch and use internal pull-ups.
To do this C code must be added.
You add a C code block before the main loop so at the very top will be fine.
Within C code block place

Code: Select all

OPTION_REG &= 0x7F;
Then you need to add another bit of code within the same C code block which is easier if in binary.
Since for the WPU register 1 = pull-up enabled & 0 = pull-up disabled.
e.g. for weak pull-ups on GP2 and GP4 you can use

Code: Select all

WPU = 0b10100;
The only issues for that is GP3 is the only pin that does not have a weak pull-up.
Also Since the switch will need to be connected between the i/p pin and ground:
The input will be logic 1 when switch has not been pressed & logic 0 when the switch is pressed.

The other thing you may find interesting is the LED Charlieplex component
It's located within Outputs.
Basically with three control pins you can control up to six LEDs.
With four control pins you can control up to twelve LEDs Etc.

Martin
Martin

Billoo
Posts: 12
Joined: Mon Oct 30, 2017 10:23 am
Has thanked: 10 times
Contact:

Re: Advice needed for Newbe

Post by Billoo »

Again, many thanks for your help Martin. I will have a good look at this later when I'm back at base camp.

Cheers
Bill

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: Advice needed for Newbe

Post by Docara »

Hi Billoo,

I did mean the specifics of your project not your life LOL

I notice you are sourcing the supply to the LEDs, generally speaking sinking is preferred. Have you checked the PICs datasdheet for driving currents. Have you done some research on buffers or transistors etc and pull up /pull done resistors. The switch will need a PU or PD resistor and switch denounce. So the PIC can easily detect the transition.


My initial thought would be to tie the anodes (via a resistor) to the supply.

Also if you're using 2x 2032 or similar at 3v your circuit diagram is wrong (should be 6V). As some rules of thumb LED drop 2V when operating and need need 10-20mA to light. Therefore R=(Supply - Voltdrop)/current so R= (6V-2V)/15x10-3 = approx 266Ohms BUT PLEASE CHECK YOUR DEVICES.

Matt

Billoo
Posts: 12
Joined: Mon Oct 30, 2017 10:23 am
Has thanked: 10 times
Contact:

Re: Advice needed for Newbe

Post by Billoo »

A BIG THANK YOU to all, I now have a working a stable chip and circuit :D

Not quite sure why the clock speed change hadn't registered correctly as I had changed it but already realised that this was the reason for the timing being out although this wasn't critical. It is now set and can confirm that the timing is spot on.

The killer in the end was the MCLR switch as when I reverted the LED's back to using pins 0,1,2,4,5 and the switch on 3 and set the MCLR to internal, it just worked as expected with the circuit and values as in the original diagram.

I have made a note on the Charlieplex component, sounds useful. Thanks Martin.

As Matt had pointed out, I'm looking to use 2 x 3V cell so 6V is what my bench PS is set at although it does run well on 3V just the LED's are not as bright as I need, the 5V was a typo, sorry about that!. I will play with the values to get the best ratio between safe for the LED's and as bright as they will go :shock:

I will also experiment with sinking instead of sourcing and will look into adding other components to get the standby current down as its presently at 1mA. Fine if the circuit is powered by a mains adaptor, but not so good for the batteries.

The main thing that I needed to know is could I work with Flowcode and did I have all I needed to get my simple circuit up and running, and to establish this before my trial ran out. The answer to that and with all your help is a big yes, so will be purchasing the software shortly so I can create my little sequences without having to code manually.

As I will be using the generated code's commercially, I understand that I need the pro version, and an 8bit chip pack to go with it, and I'm assuming that's all for now with this chip and this simple code. Can anyone confirm this?

Probably not the best thread to ask this, but has anyone got any advice on software for the generation of single layer PCB (For etching process) and driving a CNC router for cutting odd shaped boards and hole drilling? I have been looking at TINA for this but realise there are lots of options out there, but need something easy to use especially with generating the Gcode (Remember, I don't do manual coding :cry: )

Once again, many thanks everyone.

Cheers
Bill

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: Advice needed for Newbe

Post by Docara »

Hi Bill,

Don't rush!! You have a lot to do before you finalise your work enough to go into production. Get the normal version then upgrade to the Pro only when you're ready. Don't forget you need to consider CE marking.

I don't think the 12F you specified is necessarily the right choice. Have a look at Mirochips MAPS selector for ultra low power devices

Look at Design Spark, and just send your design to a PCB Manufacturer. Look at Fusion360 for the enclosure.

Time this evening has got the better of me but I was looking at the (I think) 16F1674 for you which includes PWM many more timers and better Interrupts so things run much more smoothly than polling

To give you a heads up I was sorting out an interrupt driven 10Hz base timer with an interrupt driven button detection using INT pin.

Lastly, multiplexing of the LED power will also reduce the loading on the battery

Matt

Billoo
Posts: 12
Joined: Mon Oct 30, 2017 10:23 am
Has thanked: 10 times
Contact:

Re: Advice needed for Newbe

Post by Billoo »

Hi Matt,

thank you for the info. The circuit and device I have been sharing is only a very small part in an overall multi-item system of products that has been in development for over 18 months, most of which are already built and ready to go and which doesn't include electronics. Initially we had this part of the product ready with standard discrete components (555's and Dec counters plus links to rewire to gain different patterns) which had been field tested however, our options were limited going forward as we needed to get the size and component count down to a minimum along with build time, hence the last minute re-think and peak into microprocessors. We are only looking to launch with something very basic for this small part and this is really only to test the water.

Saying this, the simple PIC12 is already proving much more viable than what we were considering previously. So far, our little dev board is on an automated test bed to simulate a user pressing the button and it has been running for almost 18 hours without fail and which equates to about 2 years of use in real time.

Long-haul and depending on market feedback, we have many more applications within the product line to consider, and which will require more advanced designs electronics wise, but we wish to crawl before standing before walking etc. :D

I'm already on Design Spark as I use RS quite a bit although I don't find them the cheapest for the same item I can source reliably elsewhere, but always open to other options as long as its not out sourcing as this throws the viability cost wise out the water, and we have been down many avenues with this!

Cheers
Bill

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Advice needed for Newbe

Post by QMESAR »

Billoo wrote: Saying this, the simple PIC12 is already proving much more viable than what we were considering previously. So far, our little dev board is on an automated test bed to simulate a user pressing the button and it has been running for almost 18 hours without fail and which equates to about 2 years of use in real time.
Hi.
Well let me say this the PIC10 and PIC12 families were designed and brought into the electronics market to do exactly what you are doing with it replacing the old discrete componets with a component that is much more flexible and can replace things like a 555 time or relay drivers easily and at low cost ,
as Matt said if you go with a battery supply then take a look at the XLP families as they are less power hungry :D
Good luck with your endeviours and you made a good choice by choosing Flow-code ( choosing a MICROCHIP product is also no mistake ), this is one of the best support forums in the world ,people are keen and motivated to help other users of the product very professional Forum :D

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: Advice needed for Newbe

Post by medelec35 »

Hi Bill,
What you will find with experience is there are neater ways of achieving the same results.
Take a look at the attached Flowchart.
The << just means shift all the bits one to the left.
This is the same as x result by 2

Martin
Attachments
Running5timed V2.fcfx
(14.64 KiB) Downloaded 150 times
Martin

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Advice needed for Newbe

Post by QMESAR »

I have been looking at TINA for this but realise there are lots of options out there,
Yes there are many but it is a bit like Aliba and the 40 thiefs :D situation
I can recommend you to look at Proteus (Basic option) it is a very good CAD package in my opinion secondly you can link your Flow-code generated Hex file to your micro on your schematic and simulate your circuits and code and test it before you build any real HW of course all add on's cost money however they are reducing your development efforts a great deal

OK I am no salesman for Proteus however I am using the professional version with PIC and advance simulation add ons for many years and it saved me a lot of time and money over the years :D

Billoo
Posts: 12
Joined: Mon Oct 30, 2017 10:23 am
Has thanked: 10 times
Contact:

Re: Advice needed for Newbe

Post by Billoo »

medelec35 wrote:Hi Bill,
What you will find with experience is there are neater ways of achieving the same results.
Take a look at the attached Flowchart.
The << just means shift all the bits one to the left.
This is the same as x result by 2

Martin
Thanks Martin,

I sort of get it :? Still got a lot to learn though. My day job takes me into the world of VB scripting and I know what I need but even here, I only scratch the surface.

Billoo
Posts: 12
Joined: Mon Oct 30, 2017 10:23 am
Has thanked: 10 times
Contact:

Re: Advice needed for Newbe

Post by Billoo »

QMESAR wrote:
Billoo wrote: Saying this, the simple PIC12 is already proving much more viable than what we were considering previously. So far, our little dev board is on an automated test bed to simulate a user pressing the button and it has been running for almost 18 hours without fail and which equates to about 2 years of use in real time.
Hi.
Well let me say this the PIC10 and PIC12 families were designed and brought into the electronics market to do exactly what you are doing with it replacing the old discrete componets with a component that is much more flexible and can replace things like a 555 time or relay drivers easily and at low cost ,
as Matt said if you go with a battery supply then take a look at the XLP families as they are less power hungry :D
Good luck with your endeviours and you made a good choice by choosing Flow-code ( choosing a MICROCHIP product is also no mistake ), this is one of the best support forums in the world ,people are keen and motivated to help other users of the product very professional Forum :D
Thanks QMESAR,

I must say, I have been impressed by the support I have received, very comforting. On the battery, this is only one option for how the product can be powered and is dependant on the how the overall system is used. There are alternatives such as mains adaptor and solar and larger battery packs. Under coin cell usage, it will only be used occasionally for a short period, however having it sat their with a 1mA drain, it wouldn't have lasted long. I have some ideas on how I can work around this quite easy, just need to find a little time to have a play.

Cheers
Bill

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: Advice needed for Newbe

Post by Docara »

Like I said , look into different PICS with interrupts. A PIC can be put to sleep and woken up on a key press and or aninterrupt. Continually polling a switch to see if it has been pressed is madness when running on a battery.

Matt

Billoo
Posts: 12
Joined: Mon Oct 30, 2017 10:23 am
Has thanked: 10 times
Contact:

Re: Advice needed for Newbe

Post by Billoo »

Hi everyone, hope you all had a great Christmas.

I’m hoping that by saying what I’m about to doesn’t break any forum rules however, can anyone offer any advice to where I can go to get someone to design a circuit and code for my project, and code that will work in Flowcode 7?

Simply put, it has beaten me in the time that I have, and for the past couple of months I have just been chasing my tail and now time and money is running out, as I need to launch the overall project early in 2018!

As I said earlier, this circuit is only a very small part of a much larger system which is ready and just waiting on what I feel should be a very simple component. To date I have got what I thought was very close as I have a circuit and code which is working as expected and meets all the criteria except for one, the current draw in sleep mode, and where my lack of knowledge in both coding and electronics has let me down as I’m either adding too many other support components to shut the chip down by removing power, or just creating C code blocks in an attempt to get the draw to the stated spec but which won’t compile as its not drag and drop and I don’t know what I’m doing!

Whilst many on this forum have offered great advice and I have also found many articles both on this forum and on-line in general, when you simply don’t understand it and/or have the time to learn it, I’m forced to look at other options!

The item was intended to consist of a low cost (less than 50p) 8DIL package for the space, absolute minimum additional discrete components also for the space and simplicity of build, be powered by one or two 3V coin cell/s, be triggered by a remote wired SMD PTM switch, drive up to 5 LED O/P’s of which can be any pattern and/or looping combination, and be simply changed by the code blocks. Lastly, when the sequence is finished, it should have a current drain that would last at least 12 months should it not be used.

Going forward I need to be able to change the patterns and timing myself through the code blocks to suit different projects, and now have the full commercial version of Flowcode 7 to do this, however the actual physical circuit will remain the same.
I can post the latest versions of my code and circuit (although it hasnt changed that much) and any advice would be greatly appreciated.

Cheers
Bill

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Advice needed for Newbe

Post by QMESAR »

Hi Billoo

You can go here on the forum ,it has a section with freelance engineers that could help you ,

viewtopic.php?f=32&t=6684

Good luck

Post Reply