PWM input?

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

Moderators: Benj, Mods

Post Reply
Flint3058
Posts: 10
Joined: Sat Jan 17, 2009 12:01 am
Contact:

PWM input?

Post by Flint3058 »

Hello, I am a RC hobbyist and been looking to control LEDs and such off a spare servo channel, been reading and learning about PIC micros and when I found out about flowcode it looked like something that I could use, right now I downloaded the demo and trying to figure out how to read PWM as a input in flowcode is it possible to do this in flowcode? If can make this work I would buy flowcode for future use so far I like the fact I can easily control LEDs on outputs and already that is a big plus for me.
Thank you for any help or advice.

-Flint

chevy6600
Flowcode V4 User
Posts: 115
Joined: Fri Feb 22, 2008 6:38 pm
Contact:

Re: PWM input?

Post by chevy6600 »

Hi Flint3058,
seems we are both travelling the same path, i too am a Rc hobbyist, wanting to program my own controller, i have not come across any others in this field here in the forum....either they don`t post or don`t exist here.....it is a pretty quite forum on members chipping in....a bit different than the RC forums. :|
So.. good to see you.

My intentions are to make vtol/uav flying contraptions.
So pretty much all of my posts here are to do with PWM for a servo signal.

If i`m right in guessing, you want the PWM as per RC control, i found out in the early part of my learning that
the PWM function on chips is focused on using it to control.... say, motor speed control....and when i/we (help from the good guys here at matrix) tried to use it for the type of signal used in Rc servos, the servo does not like the kind of signal that it receives, it would appear that PWM from these chips is on a higher frequency wave (my view) and causes the servos to hum and jam up while over heating. So it was found better to use an interrupt method that was found to give the required result.
The whole saga can be followed through my posts if you so wished.
As i understand, the up coming flowcode v4 is likely to have a servo component along with other things.
Best of luck.

Flint3058
Posts: 10
Joined: Sat Jan 17, 2009 12:01 am
Contact:

Re: PWM input?

Post by Flint3058 »

Hey chevy6600, excellent another RC guy. I played around with PWM output and found that I can dim and pulse a LED light for effects witch is really neat but the PWM on the PIC chips seems to be output only I'm not looking to drive a servo but read the signal that normally would go to one, I connected my scope to the spare channel and I get a 1ms pulse for low and 2ms for high and every thing in between from what I read its suppose to be 20ms long but my scope(cheap scope) only samples up to 10ms. What I would like to do is get the PIC to read the 1~2ms pluses but don't know how or where to start. I know its been done and seen projects online but no one seems to say how they did it and the only source code I've found was in assembly.

chevy6600
Flowcode V4 User
Posts: 115
Joined: Fri Feb 22, 2008 6:38 pm
Contact:

Re: PWM input?

Post by chevy6600 »

Hi flint, i`ll start off saying that i am no expert at this programing lark, but if i can help i will. I started using flowcode about this time last year. Great program to play with.

A couple of questions.
What kind of pic are you looking to use :?: .

Are you using any of the matrix development boards to mount your chip :?:

I do not know how knowledgeable you are programing pic`s, but i think it fair to say you are going to need to use a mixture of flowcode and `C` code within the flowcode environment.

Are your programs likely to be a fare size :?: , i`m thinking that if you `polled` the input pins to read the signal, i myself would choose one of the faster pics, to be able to keep up with the updates....i`m not too sure what the resolution would likely be, but something to think about.

Another idea i had, would be to change the pulse into a voltage then use the ADC to get my readings.
If you were not wanting a large resolution, just on or off, just reading the input would be o.k.
The interrupts could also be used from what i understand, but i cannot help there.

Although i have not yet tried `reading a pwm signal`, but i have pondered about it, so i will watch to see
how you get on with great interest.
The guys here at matrix are a clever bunch, so if you post your problem i`m sure they will chip in on monday.

p.s. some of my posts have got oscilloscope picture files if you fancy having a look at the sort of servo signal that is used in RC, sorry if you know this already but i get the impression from your post that you have a few doubts on the signal size.

Flint3058
Posts: 10
Joined: Sat Jan 17, 2009 12:01 am
Contact:

Re: PWM input?

Post by Flint3058 »

Thanks for the reply, I was looking over your posts and some other servo based posts and have some what of an idea.
I know a little C code have read up on it so I know the basic syntax of it but never really did any programming. A friend of my'n gave me a JDM programmer and a few different PICs from his days in collage. I would have asked him for help but he failed the course and really knows little about microcontrollers, so far from reading datasheets and looking at similar projects would plan on using a 12F675 , small is what i'm looking for as this will be mounted on a RC heli .
I'm a electrician by trade so I have experience with reading and understanding circuits and a basic electronics knowledge. I got drawn towards flowcode because it reminds me of industrial PLC programming software but flowcode and micros are very different from PLCs.

chevy6600
Flowcode V4 User
Posts: 115
Joined: Fri Feb 22, 2008 6:38 pm
Contact:

Re: PWM input?

Post by chevy6600 »

Hi flint, Just one other point i would like to mention. As it is inevitable that you will end up using `C` code within flowcode, this renders the flowcode debugger pretty much unusable as the debugger does not read `C` code. So while your pondering about how to tackle your project, i would also have a think about how best to debug your program. Looks as though you will be doing a lot of downloading to the chip. :!:

A lot of people seem to use microchips mplab, i do not use this myself....too complicated...looks to me as though you need to learn too much of programming in assm. or c code. to use but as you have some understanding in `c` maybe of interest to you.
Flint3058 wrote: small is what i'm looking for as this will be mounted on a RC heli .
I know where your coming from on this score :lol:
I`m just in the process of trying to solder smd microchip :shock: ......eyes are not as they use to be.

Flint3058
Posts: 10
Joined: Sat Jan 17, 2009 12:01 am
Contact:

Re: PWM input?

Post by Flint3058 »

After doing some hard reading and looking I think I know now what I want to do, so to read a PWM since its a square wave pulsing on/off ( 1 / 0 ) I just want to read the length of 1 , so when the input goes high 1 a timer should start and count how long the input is high till it goes low , since the signal is 20ms long I should be able to read two or three pulses and compare to prevent any glitching and have it make a decision to do something is its 1ms, 1.5ms or 2ms. The only question now is how would I do this? and how would it work?
I maybe over my head with this microcontroller stuff?

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: PWM input?

Post by Benj »

Hello

This is how I would go about doing what you are suggesting.

In your main program first initialise a count variable to 0 and then wait for the signal to go low 0 and then for the signal to go high 1 this is to make sure we catch the start of the pulse. Now enable timer interrupts with a fast interrupt rate, low prescalar etc. This will be your unit of scale, the more interrupts that fire off the longer the pulse period. In your interrupt routine simply increment a variable. In your main program continue monitoring the pin until it goes low. When this happens disable the interrupts. Your count variable now tells you the pulse duration.

You could repeat a few times and take an average count etc if you wished.

chevy6600
Flowcode V4 User
Posts: 115
Joined: Fri Feb 22, 2008 6:38 pm
Contact:

Re: PWM input?

Post by chevy6600 »

Hi flint,I have a couple of thoughts that you may be interested in. You mentioned you had a 10mhz oscilloscope, assuming this means you are able to read 10mhz signal and not got a max bandwidth of 10mhz ie. You need an oscilloscope rated 20 - 30mhz bandwidth, some say you will need a bandwidth 10 X the monitored signal your reading.
when you program your chip you could run the chip at half clock speed to do the monitoring, knowing that when you double the chip speed the signal/ program would scale back up...mind you, your`ll need to use half input signal! , servo testers usually have over range adjustment on, if not, a pwm signal generator would be simple and easy to knock up.

As you seem willing to get into digging out information, you may like to learn about how the interrupts work,
i came across an interesting web site that sells micro chip info as well as giving out tit bits of info....your likely to of come across it though...anyway, the information that i bought from them was an article solely on how to use the interrupts on the pic chip family. It is a download of 63 pages just on the use of interrupts, i forget how much it cost ...around $10...so it did not break the bank and i used it more than all the other books i read that had sections on using the interrupts.
http://www.best-microcontroller-project ... -sale.html scroll down and you will find the article "PIC Interrupt Secrets".

keep us posted how you get on.

Flint3058
Posts: 10
Joined: Sat Jan 17, 2009 12:01 am
Contact:

Re: PWM input?

Post by Flint3058 »

Thank you Ben , Thank you Chevy !
I looked at the interrupt and saw TMR0 overflow and it gave me some settings clock source = internal clock , source edge select = low to high transition T0CKI , and prescale = 1:4 , with the interrupt it gave me a window for a sub routine I'm guessing this is where I set it up to read the input?

Chevy I got the book you recommended and well I'm at I need to buy Flowcode before my trial expires, seeing now I can make some headway in this.

Flint3058
Posts: 10
Joined: Sat Jan 17, 2009 12:01 am
Contact:

Re: PWM input?

Post by Flint3058 »

Nope, wait I just looked more into the interrupt and saw transition low to high on T0CKI and found out T0CKI is a pin so this pin is my input and in the sub routine for TMR0 I just do a calculation of count = count + 1 and I can set up a LCD in the main program to out put the results correct??

chevy6600
Flowcode V4 User
Posts: 115
Joined: Fri Feb 22, 2008 6:38 pm
Contact:

Re: PWM input?

Post by chevy6600 »

Hi flint, i have just had a look at the great little program of yours that you sent me via `pm post`. Although i have no hardware to try it out on it is the sort of program that i would use so i have added it to my `program toolbox`and even better, you have managed it without using `c` code. Well done, and thank you very much for sharing it with me.
This program is small, clear, uncluttered, how about putting it up here on the forum :?: , perhaps when there
are sufficient program titbits we might be able to justify a special section for PWM servo for the likes of RC and robotics! 8)
Thanks very much.

Flint3058
Posts: 10
Joined: Sat Jan 17, 2009 12:01 am
Contact:

Re: PWM input?

Post by Flint3058 »

Just trying to refine it a bit I want to test it some more I think I can make better! But yes I'm willing to share it to show hobbyists how powerful and useful Flowcode can be!

Post Reply