PIC16F684 LED flasher using TIMER module
Moderator: Benj
-
- Posts: 53
- Joined: Wed Feb 25, 2015 1:31 pm
- Has thanked: 15 times
- Been thanked: 4 times
- Contact:
PIC16F684 LED flasher using TIMER module
Hi,
I am new to flowcode6 and at the learning stage. I want to generate 400 ms LED flasher without disturbing the main routine. Kindly guide me how to use TIMER module to generate 400ms delay and further turn ON / OFF the LED at every 400 ms by interrupt generated at TIMER over flow.
Regards
I am new to flowcode6 and at the learning stage. I want to generate 400 ms LED flasher without disturbing the main routine. Kindly guide me how to use TIMER module to generate 400ms delay and further turn ON / OFF the LED at every 400 ms by interrupt generated at TIMER over flow.
Regards
- 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: PIC16F684 LED flasher using TIMER module
Hello,
You don't mention your clock speed but assuming 19.6608MHz crystal this program should work.
I set up the timer to interrupt at 75Hz which equals a period of 1/75 = 13.333ms.
We then count the number of interrupts until we reach a count of 30.
400ms / 13.333 = 30
We then toggle the state of the LED between 0 and 1 and reset the counter.
You don't mention your clock speed but assuming 19.6608MHz crystal this program should work.
I set up the timer to interrupt at 75Hz which equals a period of 1/75 = 13.333ms.
We then count the number of interrupts until we reach a count of 30.
400ms / 13.333 = 30
We then toggle the state of the LED between 0 and 1 and reset the counter.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 53
- Joined: Wed Feb 25, 2015 1:31 pm
- Has thanked: 15 times
- Been thanked: 4 times
- Contact:
Re: PIC16F684 LED flasher using TIMER module
Hello Sirs,
I want to generate 10 Hz to 60 Hz using component macro. My application is Under frequency roll off function. With decreasing frequency PWM duty cycle is increased up to specified cutoff frequency. Please advise which component macro can be used to generate the frequency. I did not find such a frequency generator in flowcode6
I want to generate 10 Hz to 60 Hz using component macro. My application is Under frequency roll off function. With decreasing frequency PWM duty cycle is increased up to specified cutoff frequency. Please advise which component macro can be used to generate the frequency. I did not find such a frequency generator in flowcode6
-
- Posts: 53
- Joined: Wed Feb 25, 2015 1:31 pm
- Has thanked: 15 times
- Been thanked: 4 times
- Contact:
Re: PIC16F684 LED flasher using TIMER module
Hi Mr.Ben.
The LED flasher program did work well. Thanks for your support. But I need to understand meaning of below calculation.
LEDState = (LEDState + 1) & 1
Microcontrollers are totally new subject for me so I am struggling in understanding the calculations, macros & interrupts.
Awaiting your reply at the earliest.
Regards.
The LED flasher program did work well. Thanks for your support. But I need to understand meaning of below calculation.
LEDState = (LEDState + 1) & 1
Microcontrollers are totally new subject for me so I am struggling in understanding the calculations, macros & interrupts.
Awaiting your reply at the earliest.
Regards.
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: PIC16F684 LED flasher using TIMER module
To understand the formula you need to understand normal calculations (LEDState + 1) which I assume you do. For the '& 1' part I suggest you take a look at the calculations help page for the name of the operator, then use Wikipedia or this page to find what it does.
Assuming LEDstate is 0, the formula reads:
LEDState = ( 0 + 1 ) & 1 = 1 & 1 = 1
Next LEDState is 1, now the formula reads
LEDState = ( 1 + 1 ) & 1 = 2 & 1 = 0
(& is the and operator, check one of the last two links above to find what is does)
Assuming LEDstate is 0, the formula reads:
LEDState = ( 0 + 1 ) & 1 = 1 & 1 = 1
Next LEDState is 1, now the formula reads
LEDState = ( 1 + 1 ) & 1 = 2 & 1 = 0
(& is the and operator, check one of the last two links above to find what is does)
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- Posts: 53
- Joined: Wed Feb 25, 2015 1:31 pm
- Has thanked: 15 times
- Been thanked: 4 times
- Contact:
Re: PIC16F684 LED flasher using TIMER module
Dear Benj.
In one of my application using PIC16F1824, I have used up / down push button to modify 8 bit data. This 8 bit data is to be stored in data memory when either of push botton is pressed last so that at power up that last 8 bit data stored is recalled for processing. For example initial 8 bit data is 10100101, now push button is used to modify this data to 11001000, therefore this last modified data should be stored in data memory so that in next power up this data is available for reading.
Can you please guide me how it is to be done in flowcode6.
Regards.
Juzar.
In one of my application using PIC16F1824, I have used up / down push button to modify 8 bit data. This 8 bit data is to be stored in data memory when either of push botton is pressed last so that at power up that last 8 bit data stored is recalled for processing. For example initial 8 bit data is 10100101, now push button is used to modify this data to 11001000, therefore this last modified data should be stored in data memory so that in next power up this data is available for reading.
Can you please guide me how it is to be done in flowcode6.
Regards.
Juzar.
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: PIC16F684 LED flasher using TIMER module
Juzar,
To store information when power is removed you need to use eeprom with the the eeprom component, data memory looses its contents when power is removed from the device. Check the documentation and examples.
To store information when power is removed you need to use eeprom with the the eeprom component, data memory looses its contents when power is removed from the device. Check the documentation and examples.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- Posts: 53
- Joined: Wed Feb 25, 2015 1:31 pm
- Has thanked: 15 times
- Been thanked: 4 times
- Contact:
Re: PIC16F684 LED flasher using TIMER module
Dear Kersing.
I want to store some default values in PIC EEPROM before loading the main program or at the time of loading the program on PIC. So after programming the PIC the main routing will read those default value from EEPROM for further processing. I tried to do this but was not successful, because every time when main routing starts those default values are not present at that particular locations of EEPROM and it picks up some random value. So it is compulsory to first store the default values in EEPROM before the main routing executes.
Awaiting your reply at the earliest.
Regards.
Juzar.
I want to store some default values in PIC EEPROM before loading the main program or at the time of loading the program on PIC. So after programming the PIC the main routing will read those default value from EEPROM for further processing. I tried to do this but was not successful, because every time when main routing starts those default values are not present at that particular locations of EEPROM and it picks up some random value. So it is compulsory to first store the default values in EEPROM before the main routing executes.
Awaiting your reply at the earliest.
Regards.
Juzar.
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: PIC16F684 LED flasher using TIMER module
Every time you program your controller the EEPROM contents will be reset. There are two options to solve this:
1) Set the default values in the 'Initial Values' in the properties window. These values will be stored to eeprom when programming the controller.
2) A cleared eeprom location has value 255. After storing your values set one location to a special value like 101. When starting your program check if that location contains 101, if it does not you start a macro to set all values to the default your program requires.
1) Set the default values in the 'Initial Values' in the properties window. These values will be stored to eeprom when programming the controller.
2) A cleared eeprom location has value 255. After storing your values set one location to a special value like 101. When starting your program check if that location contains 101, if it does not you start a macro to set all values to the default your program requires.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- Posts: 53
- Joined: Wed Feb 25, 2015 1:31 pm
- Has thanked: 15 times
- Been thanked: 4 times
- Contact:
Re: PIC16F684 LED flasher using TIMER module
Hi Kersing.
I am trying to simulate a PWM using dashboard panel. The duty cycle of PWM is increased & decreased by using two push buttons. All three are component macros. Now when I try to simulate, it takes approximately 5 to 6 seconds to respond and display the first PWM. When pushbuttons are pressed the PWM duty cycle changes very slowly and PWM waveform displays randomly before settling. No delays are used in the software and also the simulation speed set to NORMAL. The processor speed is set to 20 MHz. Requested to kindly guide me how check the simulation near to real time.
I am trying to simulate a PWM using dashboard panel. The duty cycle of PWM is increased & decreased by using two push buttons. All three are component macros. Now when I try to simulate, it takes approximately 5 to 6 seconds to respond and display the first PWM. When pushbuttons are pressed the PWM duty cycle changes very slowly and PWM waveform displays randomly before settling. No delays are used in the software and also the simulation speed set to NORMAL. The processor speed is set to 20 MHz. Requested to kindly guide me how check the simulation near to real time.