ADC help!

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Gaz
Posts: 18
Joined: Thu Dec 11, 2008 10:02 am
Contact:

ADC help!

Post by Gaz »

Hi folks

Could anyone give me any pointers on how to use the ADC in Flowcode V4?

Ive got 2 LED's flashing flip flop style but would now like to use the ADC facility to control the flash rate.

I aint got a clue where to start! :roll:

cheers

Gaz

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9102
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: ADC help!

Post by medelec35 »

have a look here:
http://www.matrixmultimedia.com/mmforum ... 12&p=14003
It was created when V4 was new to me, so its not the most advanced in the word, but it works well to alter led brightness, hence flash rate.

Also to learn more about flowcode 4 you can find a link to V4 examples here:
http://www.matrixmultimedia.com/Flowcode3a-X.php
Scroll down to flowcode extras, then you will see 'Flowcode V4 Examples'
What I do to learn is just load a flowcode example, then press F8, to run single step, then in variable windows, right click and select 'Add variable...'
If you want to add all variables then highlight top one, hold shift key, then left click on lowest variable, then click 'use variable'
You could either run simulation by holding down F8, or you can go to View, project options and change simulation speed from 'As fat as possible' to 1000. If left on 'As fast as possible' variables will not be displayed in variables window.

You could just read adc value, convert to a delay period. then a continuous loop of: led on, read ADC Calculate delay led on,delay, led off, delay
Also included a couple of very basic programs to get you started.
First one (LED Delay1) using reading 8 bit ADC
Second one (LED Delay2) using 10bit ADC and delay variable from 0 to 1023 ms . You don't have to stick with max 1023 ms Delay, using a formula you can go up to something like 32767 ms. Or Change delay form ms to Seconds.
Hope it helps.
Attachments
LED Delay2.fcf
(6.5 KiB) Downloaded 257 times
LED Delay1.fcf
(6 KiB) Downloaded 229 times
Martin

Gaz
Posts: 18
Joined: Thu Dec 11, 2008 10:02 am
Contact:

Re: ADC help!

Post by Gaz »

Thanks for that fella.

I will have a look and see if I can digest it all! :lol:

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9102
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: ADC help!

Post by medelec35 »

Your welcome.

Since there is quiet a bit to digest, If I were you I would just save and run the two attached files, and just see how they work. There probably won’t be a need to read the rest.
Martin

Gaz
Posts: 18
Joined: Thu Dec 11, 2008 10:02 am
Contact:

Re: ADC help!

Post by Gaz »

I downloaded the first file and V4 says its an unexpected format? are V3 files not compatable with V4?
Seems a bit odd?

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9102
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: ADC help!

Post by medelec35 »

Yes that’s odd!
Files were created with V4. Just downloaded file and opened it. Opens fine with my V4.
Martin

Gaz
Posts: 18
Joined: Thu Dec 11, 2008 10:02 am
Contact:

Re: ADC help!

Post by Gaz »

Im running V4 pro. Do any of the mods know why this could be?

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9102
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: ADC help!

Post by medelec35 »

Within flowcode, go to help, and check for updates. Are you using latest .. V4.2?
Martin

Gaz
Posts: 18
Joined: Thu Dec 11, 2008 10:02 am
Contact:

Re: ADC help!

Post by Gaz »

Cheers again fella

I did the update and it loads up now.

Right, I'm off for a play! :lol:

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9102
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: ADC help!

Post by medelec35 »

Glad you have got V4 working now 8)
Sorry mate, I slightly misread :oops: .
You wanted to flash two LEDS like flip flop style.

Here you go. You will like this one much better.
Connect pot to RA1.
LED1 to B0 and LED2 to B1

f you want specific times in which they change rate e.g. from 100ms to 1 second, then let me know and I will work out correct formula for you.

This was tested on 16F872. You will need to change target, configuration and perhaps port settings to suit.
Attachments
LED Flip Flop1.fcf
(8 KiB) Downloaded 382 times
Martin

Gaz
Posts: 18
Joined: Thu Dec 11, 2008 10:02 am
Contact:

Re: ADC help!

Post by Gaz »

Thats exactly what I wanted mate, top stuff 8)

I have a play around with that now and try and understand how various parts work.

Thanks again fella

Gaz

Post Reply