![Exclamation :!:](./images/smilies/icon_exclaim.gif)
LED flashing without Delay icon at 1HZ or so
Moderator: Benj
LED flashing without Delay icon at 1HZ or so
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). ![Exclamation :!:](./images/smilies/icon_exclaim.gif)
![Exclamation :!:](./images/smilies/icon_exclaim.gif)
-
- 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
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
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
- 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
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
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..
![Smile :)](./images/smilies/icon_smile.gif)
Enamul
- Attachments
-
- MULTI_TONE.fcf
- Using FC v5
- (17.6 KiB) Downloaded 527 times
Re: LED flashing without Delay icon at 1HZ or so
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
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
- 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
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
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
![Smile :)](./images/smilies/icon_smile.gif)
If you want to use one TMR i.e. TMR0, I have to think again..
Enamul
Re: LED flashing without Delay icon at 1HZ or so
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.
- 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
Hi,
I have managed to make program using TMR0...now tone1 freq is 300Hz and tone2 freq is 150Hz..
Enamul
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 525 times
- 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
Hi,
Enamul
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..mtqc76 wrote:I asked for one timer TMR0 bcz if one want to use say 12 keys, then how to manage.
Enamul
Re: LED flashing without Delay icon at 1HZ or so
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.
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.
- 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
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
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..
![Smile :)](./images/smilies/icon_smile.gif)
Enamul
Re: LED flashing without Delay icon at 1HZ or so
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.
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 536 times
-
- 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
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: As you can see frequency is 49.98261 Hz
Martin
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: As you can see frequency is 49.98261 Hz
Martin
- Attachments
-
- ups lcd 877a V2.fcf
- (27.52 KiB) Downloaded 497 times
Martin
Re: LED flashing without Delay icon at 1HZ or so
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
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
-
- 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
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
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
- 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
Hi,
I thought I will make a try to post something..but seems Martin is not willing to give me chance
Thanks Martin,
Enamul
I thought I will make a try to post something..but seems Martin is not willing to give me chance
![Wink :wink:](./images/smilies/icon_wink.gif)
Thanks Martin,
Enamul
-
- 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
Hi Enamul,
No probs.
Looks like we need to be participating in job share scheme
Martin
No probs.
![Smile :)](./images/smilies/icon_smile.gif)
Looks like we need to be participating in job share scheme
![Wink :wink:](./images/smilies/icon_wink.gif)
Martin
Martin
Re: LED flashing without Delay icon at 1HZ or so
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
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 476 times
-
- 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
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.
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
Re: LED flashing without Delay icon at 1HZ or so
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.
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.
-
- 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
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.
Martin
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.
This is correct section, I have just moved it from General section.mtqc76 wrote: Plz give me link where you posted this topic.
Martin
Martin
Re: LED flashing without Delay icon at 1HZ or so
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
-
- 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
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?
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
Re: LED flashing without Delay icon at 1HZ or so
Sorry sir, i might have confused you.
I want to generate 50 hz PWM signal via hardware PWM on 877a. Can it be done?
I want to generate 50 hz PWM signal via hardware PWM on 877a. Can it be done?