Question for example TUT22 (clock)
-
- Posts: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Question for example TUT22 (clock)
Hi! I have a question for example TUT22 (clock). It would be interesting to set up 2 buttons to set the time, one button to set hours, the other - to set minutes. Which way is better to do this?
Respectfully, Alexander
- 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: Question for example TUT22 (clock)
Hello Alexander
In the main program loop you could add an input icon to read your switches. If they are pressed then increment the hour or minute variable approproiatly. Then include a while loop to hold the program while the switch is pressed. This should allow you to increment a single digit at a time. Looking at the example there is a much better way of processing the time then has been shown. You simply need a timer count and variables to hold the Hours, Mins and Seconds. Then when printing out the variables you need to check if they are under 10. If they are then first print out a 0 to allow the spacing to stay constant. If I get time today I will make a better clock example file.
In the main program loop you could add an input icon to read your switches. If they are pressed then increment the hour or minute variable approproiatly. Then include a while loop to hold the program while the switch is pressed. This should allow you to increment a single digit at a time. Looking at the example there is a much better way of processing the time then has been shown. You simply need a timer count and variables to hold the Hours, Mins and Seconds. Then when printing out the variables you need to check if they are under 10. If they are then first print out a 0 to allow the spacing to stay constant. If I get time today I will make a better clock example file.
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: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Question for example TUT22 (clock)
I did so (attached), but when I click on the button B0 to set the hours, the program stops. Where I made a mistake?
- Attachments
-
- TUT_22_16F887_clock_new.fcf
- (16.07 KiB) Downloaded 408 times
Respectfully, Alexander
- 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: Question for example TUT22 (clock)
Hello Alexander
The reason your program seems to be stopping is because the connection point is just below the read switches icon meaning the switch variable does not get updated and the program therefore becomes trapped in a loop. Moveing the connection point label to above the read switches should solve this for you.
The reason your program seems to be stopping is because the connection point is just below the read switches icon meaning the switch variable does not get updated and the program therefore becomes trapped in a loop. Moveing the connection point label to above the read switches should solve this for you.
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: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Question for example TUT22 (clock)
Thank you, I moved the connection point above the switches reading, but still does not work. When pressed, the program stops, and when I release the button, the program is working again. But the hours is not set as I had planned.
- Attachments
-
- TUT_22_16F887_clock_new2.fcf
- (16.07 KiB) Downloaded 331 times
Respectfully, Alexander
- 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: Question for example TUT22 (clock)
Hello Alexander
Here is the better clock example I mentioned. It should be much easier to follow then the old example and also allows for the user to set the time using switches for hours and minutes.
Let me know if you have any problems.
Here is the better clock example I mentioned. It should be much easier to follow then the old example and also allows for the user to set the time using switches for hours and minutes.
Let me know if you have any problems.
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: 79
- Joined: Mon Aug 03, 2009 12:14 pm
-
- Posts: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Question for example TUT22 (clock)
Why use clock frequency 19660800 Hz? Is there are quartz crystals with such frequency?
Respectfully, Alexander
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Question for example TUT22 (clock)
Yes, EB0006 programer which you can use with Eblocks has a crystal which runs at that frequency.alexander70 wrote:Why use clock frequency 19660800 Hz? Is there are quartz crystals with such frequency?
I agree Good example.
Martin
- 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: Question for example TUT22 (clock)
Hello Alexander
Yes there certainly is a crystal with this frequency. Crystals like this are designed for use with 8-bit micros for generating baud rates etc. eg the 19.6608MHz crystal gives a timer interrupt of exactly 75hz. Our EB006 and HP488 boards all come with a 19.6608MHz crystal pre fitted.
19660800 / internal clock divider 4 = 4915200
4915200 / timer count register 256 = 19200
19200 / interrupt prescaler 256 = 75
If you using a different crystal eg the 8MHz internal crystal then you will need to check the interrupt frequency in the interrupt enable options, You will then need to update the interrupt handler macro so that it uses the updated count value to time a second interval. At 8MHz there is a slight error in the interrupt timing so instead of the dead on 75hz you get the closest value of 61.035. This is an error of 0.035 that will accumilate every second. Eg in 10 seconds the error will have grown to 0.35. 100 seconds and the error is now 3.5 seconds.
I have attached an updated example for an 8MHz clock so you can see the differences.
Yes there certainly is a crystal with this frequency. Crystals like this are designed for use with 8-bit micros for generating baud rates etc. eg the 19.6608MHz crystal gives a timer interrupt of exactly 75hz. Our EB006 and HP488 boards all come with a 19.6608MHz crystal pre fitted.
19660800 / internal clock divider 4 = 4915200
4915200 / timer count register 256 = 19200
19200 / interrupt prescaler 256 = 75
If you using a different crystal eg the 8MHz internal crystal then you will need to check the interrupt frequency in the interrupt enable options, You will then need to update the interrupt handler macro so that it uses the updated count value to time a second interval. At 8MHz there is a slight error in the interrupt timing so instead of the dead on 75hz you get the closest value of 61.035. This is an error of 0.035 that will accumilate every second. Eg in 10 seconds the error will have grown to 0.35. 100 seconds and the error is now 3.5 seconds.
I have attached an updated example for an 8MHz clock so you can see the differences.
- Attachments
-
- Better_Clock_Example.fcf
- (15 KiB) Downloaded 417 times
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: 79
- Joined: Mon Aug 03, 2009 12:14 pm
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Question for example TUT22 (clock)
If using 8MHz then: Prescaler = 256 timer offset = 4 then interrupt frequency = 31.002Hz
which is slightly better.
which is slightly better.
Martin
-
- Posts: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Question for example TUT22 (clock)
I want to ask about the internal clock. If 19660800 divided by 256 is equal to 76800. How is the frequency of interruption of 75 Hz?
Respectfully, Alexander
- 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: Question for example TUT22 (clock)
Hello Alexander
The answer is shown above.
The answer is shown above.
19660800 / internal clock divider 4 = 4915200
4915200 / timer count register 256 = 19200
19200 / interrupt prescaler 256 = 75
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: 79
- Joined: Mon Aug 03, 2009 12:14 pm
Re: Question for example TUT22 (clock)
Thank you very much, it is now clear.
Respectfully, Alexander