LED flashing without Delay icon at 1HZ or so

Moderator: Benj

Post Reply
mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

How to make a simple program to flash an LED without using Delay icon and in the meanwhile reading the switch (input). eg, if i want delay of 1 sec of flashing, read the switch simultaneously and switch run other task, but LED must flash at 1 HZ no matter what other programs are being run at the same time. OR it is possible to make a piano when one tone is working by pressing a key and I press another tone key and it also starts without stopping first one, ie both run simultaneously without compromising on tone or time loss to run both tones. eg, one tone finishes 1 second and other tone finishes 2 seconds, if I play both tones by pressing key one after other they both should finish by their times ie 1 second and 2 second respectively they should not be prolonged. (a kind of multitasking). :!:

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: LED flashing without Delay icon at 1HZ or so

Post by medelec35 »

Hi mtqc76,
what version of Flowcode are you running?
can you post as mush detail as possible pls.
E.g target device and speed, type of osc i.e internal, external etc.

If you want to gain some knowledge on how to achieve this 1st,
then best bet is to learn about bit bang PWM using timer interrupt.

Martin
Martin

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by Enamul »

Hi,
I have made the program using TMR0 for 1s using internal clock and TMR1 for 2s using internal clock too but both independent. If you press RB0 key TMR0 will activate and 300 Hz signal will generate at RC0 which will last for 1s..If you press RB1 key TMR1 will activate and 75 Hz signal will generate at RC1 which will last for 2s...

If you press both key simultaneously both TMR will be activated and both signal will come out..

Hope this will help.. :)
Enamul
Attachments
MULTI_TONE.fcf
Using FC v5
(17.6 KiB) Downloaded 517 times
Enamul
University of Nottingham
enamul4mm@gmail.com

mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

Thanks Sir:

We use flowcode V4 PIC. I am student and learning. PIC is 877a, 20 MHZ osc. But other can be. Enamul, you made a great simple program of multitone. sir, plz explain that interrupt frequency is the generated frequency and how you calculated time ie 1 second and 2 second. in icons. 150 count=1 sec and 300 count=2 sec. Is it possible to use only TMR0 for both frequency and time.
thanks

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by Enamul »

Hi,
Do you need a v4 version of the program? Actually with the current interrupt setting for TMR0 ..in each seconds 300 times program calls My_TMR0 macro..I have flipped RC0 300 times in one second which produces one tone that lasts for one sec..

for TMR1..in each seconds 75 times program call My_TMR1 macro..I have flipped RC1 75 times in one sec which produces second 75 Hz tone but this lasts for 2 seconds as I have continued count2 upto 150(75*2)..Hope this is now clear :)

If you want to use one TMR i.e. TMR0, I have to think again..
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

Thanks, I do have V5 demo and it is working fine. I asked for one timer TMR0 bcz if one want to use say 12 keys, then how to manage.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by Enamul »

Hi,
I have managed to make program using TMR0...now tone1 freq is 300Hz and tone2 freq is 150Hz..

Enamul
Attachments
MULTI_TONE_TMR0.fcf
(16.89 KiB) Downloaded 514 times
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by Enamul »

Hi,
mtqc76 wrote:I asked for one timer TMR0 bcz if one want to use say 12 keys, then how to manage.
The version just I have posted earlier can be modified to use with 12 keys...Have close look at the program and ask me please if you are not clear..
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

Thanks sir:

I got it. I will try on hardware then let you know. Sir, one question more plz. Actually I was trying to build an inverter 220 volt with microcontroller. The objective was to make a 50 Hz square wave with 877a. I used two pins for it, on and off. Other pins of microcontroller were used to read the temperature, voltage, main power supply, inverter output, battery under voltage, charging voltage, auto cutoff etc. when i did it, simulator showed that i was not able to make 50 hz output, but it was rather 25 hz, (due to busy on other pins)anyhow, it was not consistent when microcontroller was doing other jobs simultaneously that was why i asked for multitasking. Objective was to make a stable 50 hz output and stable with no effect of other jobs that microcontroller was doing. I will try your fcf and make changes in program to make it and let you know about it. If you have any idea about generating 50 hz stable square wave and no effect of other function on it then plz.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by Enamul »

Hi,
I have started my PIC life with IPS..UPS.I have made such program ages ago..I will post something whenever I can manage some time.. :)
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

Enamul and medelec:

Sir, I am uploading UPS 877a fcf and proteus file. I want it to be generating 50 hz frequency. Plz have a look on it and make ammendment so that it work for 50 hz. Other function, like battery, main etc are working well. If possible is there anyway to optimize fcf file or by adding c code in it to make professional.
Attachments
ups.rar
fcf, proteus
(224.96 KiB) Downloaded 524 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: LED flashing without Delay icon at 1HZ or so

Post by medelec35 »

Can you give this a try please.
I have changed timer0 interrupt properties from external T0CKI to internal clock.
Changed interrupt frequency so toggle rate is 50Hz
Changed D0 and D1 outputs so they are 180 deg out of phase i.e. inverted. I think this is what you want?
Here is a screen shot of waveform taken with Matrix test pod connected to a 16F887A:
flipflop 50Hz.png
(146.44 KiB) Downloaded 13663 times
As you can see frequency is 49.98261 Hz
Martin
Attachments
ups lcd 877a V2.fcf
(27.52 KiB) Downloaded 484 times
Martin

mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

Great sir, you are my BOSS!

Million of thanks. Sir, do little explain about how you calculated interrupt frequency to make 50 hz. (tmr0). second as i early mentioned, i am student new to pic. I did run simulation on proteus, frequency counter is nothing showing anything. Plz also do have a look on proteus file.

Thanks

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: LED flashing without Delay icon at 1HZ or so

Post by medelec35 »

No problem,

Here is how I got 50Hz.

Since togging on each interrupt, an interrupt of 100Hz is required.
I worked out that if i select an interrupt of 300Hz then it's exactly 3 times too fast. So to divide by 3 I used if Count>=3 then toggle port a bits 0 and 1
Since statement is true on each 3rd time interrupt is accessed.

Martin
Martin

mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

Once again thanks sir! :D

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by Enamul »

Hi,
I thought I will make a try to post something..but seems Martin is not willing to give me chance :wink:
Thanks Martin,
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

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: LED flashing without Delay icon at 1HZ or so

Post by medelec35 »

Hi Enamul,
No probs. :)

Looks like we need to be participating in job share scheme :wink:

Martin
Martin

mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

Hi Medelec and Senior:

Sir, I made a prototype of stable 50Hz inverter. It worked fine. It was with center tapped transformer. I have high frequency transformer and no problem in generating high DC voltage, hence i I started working on H bridge inverter.

How to make 50 HZ PWM pulses. In hardware PWM cannot be configured to such low frequency. Is there any way to make it low to 50 hz in hardware PWM. I made in software PWM, but not working as expected, though it is 50 Hz.

Thanks
Attachments
UPS PWM 50 Hz.rar
FCF 50 Hz, proteus, H-bridge
(131.76 KiB) Downloaded 465 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: LED flashing without Delay icon at 1HZ or so

Post by medelec35 »

Hi mtqc76,
I'm not sure what your asking?

Do you want 50Hz and be able to vary duty
Or
Two 50Hz o/p in 180 deg to each other so can control a bridge arrangement tor both?

I do not have Proteus installed, so unable to view any circuit diagrams.


Also since you said your using V5 demo, I have moved topic to Flowcode V5 Free Edition.
Martin

mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

Thanks for reply:

PWM hardware: Two 50Hz o/p in 180 deg with variable duty cycle to each other so can control a bridge arrangement

Plz give me link where you posted this topic.
Attachments
New Bitmap Image.GIF
(86.19 KiB) Downloaded 5981 times
Last edited by mtqc76 on Sat Aug 04, 2012 1:27 pm, edited 1 time in total.

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: LED flashing without Delay icon at 1HZ or so

Post by medelec35 »

I have noticed you have changed osc from 19660800Hz to 20000000Hz

It is better with 19660800Hz crystal if you can use that.
Or you sticking to 20000000Hz?
I need to know so make sure all is working at correct frequency.

mtqc76 wrote: Plz give me link where you posted this topic.
This is correct section, I have just moved it from General section.

Martin
Martin

mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

It was just for testing purpose. else i will use 19 mhz. I got grip on how to generate 50 hz, but regarding PWM at 50 Hz with hardware 877a is troublesome. I think cannot be done, but there should be other way. I created software PWM from tut and i am not concern of frequency anymore as it is generating 50 hz or so, but confusing regarding making its phase shifting. I just want to know how to change phase of two PWM at 50 hz. i did try, but seems not okay. waveform of one PWM is not so fine, little problem at its edge where as other PWM seems okay. I did not tested on hardware. Sir, just guide me or make such changes in fcf file that i can produce phase shifting from anywhere 0-180 in programming and in image see why PWM wave is not fine as other one in software PWM.
Attachments
untitled.GIF
(117.45 KiB) Downloaded 5980 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: LED flashing without Delay icon at 1HZ or so

Post by medelec35 »

Im a bit confused.

Flowchart iin this post:
http://www.matrixmultimedia.com/mmforum ... 976#p37574

Runs at 50Hz and two signals are aout of phase by 180 deg.

The timing waveform shown on USBEE Test pod wad measuring on real hardware.

What would you like to change?
Martin

mtqc76
Posts: 48
Joined: Fri Jun 17, 2011 11:44 am
Contact:

Re: LED flashing without Delay icon at 1HZ or so

Post by mtqc76 »

Sorry sir, i might have confused you.

I want to generate 50 hz PWM signal via hardware PWM on 877a. Can it be done?

Post Reply