View previous topic :: View next topic |
Author |
Message |
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
|
Back to top |
|
|
pykedgew
Joined: 22 Feb 2005 Posts: 17 Location: Australia
|
Posted: Sat Sep 12, 2015 5:31 am Post subject: |
|
|
Hi
Need to do this for 504000 times which equate to 14Hrs at 100ms.
You also need to take into account the extra cycles the rest
of the program generate in each loop when done the whole of 504000.
Somehow factor that extra cycles to become a loss in it as well.
So you could use for next loop or while wend loop.
Ken
ps I notice you are running a LCD display as well, so we are not getting the full picture here.
So this must be one part of the function of a menu of fancy unit.
Or is this a standalone unit with it own AVR chip.
Then what type is it & clock are we looking at?
Need more details what you are doing as this may require interrupt or not, depend. |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Sat Sep 12, 2015 3:30 pm Post subject: |
|
|
Need to do this for 504000 times which equate to 14Hrs at 100ms.
You also need to take into account the extra cycles the rest
of the program generate in each loop when done the whole of 504000.
Somehow factor that extra cycles to become a loss in it as well.
Hello , I understand well that says that equates to 15 hrs 900 minutes .
the 900 minutes equates 54000 sec .
This is an example of 54000 sec per 100 ms but do not need these .
So you could use for next loop or while wend loop.
For if UN project seeks to charge NiMH battery that charge 10% of the rated capacity . So you would need are charged for 15 hours.
ps I notice you are running a LCD display as well, so we are not getting the full picture here.
So this must be one part of the function of a menu of fancy unit.
Or is this a standalone unit with it own AVR chip.
Very true friend is nothing else but an example is not so for my battery functions .
Then what type is it & clock are we looking at?
Need more details what you are doing as this may require interrupt or not, depend.
A battery charger I only need to add a timer start button and nothing else tomorrow I send my code is mine . |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Sat Sep 12, 2015 6:51 pm Post subject: |
|
|
My code but lack introcucir start button and charging time for 15 hrs .
Code: | $regfile = "m8adef.dat"
$crystal = 4000000
$hwstack = 40
$swstack = 16
$framesize = 32
Config Pinb.0 = Input : Inicio Alias Pinb.0
Config Portc = Input
Config Portd = Output
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Dim Leds As Word
Dim Inicio As Word
Do
Leds = Getadc(0)
'Fin carga
If Leds > 895 Then
Portd = &B11111101
End If
'Se inicia las carga con temporizador (15 hrs)
If Leds > 383 And Leds < 895 Then
Portd = &B11111100
Wait 1
Portd = &B11111110
Wait 1
End If
'se inicia las descarga cuando impulsa un boton
If Leds < 383 Then
Portd = &B11111011
End If
Loop |
The 'm using my experimental tarqueta stk500 splitter and voltage is 5 volts test and experiment. |
|
Back to top |
|
|
JC
Joined: 15 Dec 2007 Posts: 584 Location: Cleveland, OH
|
Posted: Sun Sep 13, 2015 12:06 am Post subject: |
|
|
Delay and waitms are done in software, and are only an approximate delay.
For more accurate timing it is better to set up a Timer/Counter in CTC mode, so that it generates an interrupt at a known interval, (e.g. every 1 mSec, every 10 mSec, etc.).
Inside the ISR one can use a variable to count the interrupts that have occurred.
In the Main Loop, watch the count to see when your desired time has occurred.
One could also just set a flag in the interrupt, and watch for the flag in the Main loop, increment a variable, and clear the flag.
This Thread:
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=9984&highlight=ctc
has an example of setting up a timer n CTC mode to flash an LED.
You will have much better timing accuracy if you use an external crystal rather than the internal RC oscillator.
Depending upon the uC, the internal RC frequency can be off by +/- 10%.
JC |
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
Posted: Wed Sep 16, 2015 12:45 am Post subject: |
|
|
JC wrote: | Delay and waitms are done in software, and are only an approximate delay.
For more accurate timing it is better to set up a Timer/Counter in CTC mode, so that it generates an interrupt at a known interval, (e.g. every 1 mSec, every 10 mSec, etc.).
Inside the ISR one can use a variable to count the interrupts that have occurred.
In the Main Loop, watch the count to see when your desired time has occurred.
One could also just set a flag in the interrupt, and watch for the flag in the Main loop, increment a variable, and clear the flag.
This Thread:
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=9984&highlight=ctc
has an example of setting up a timer n CTC mode to flash an LED.
You will have much better timing accuracy if you use an external crystal rather than the internal RC oscillator.
Depending upon the uC, the internal RC frequency can be off by +/- 10%.
JC |
Hi I was reading but do not understand your code these very advanced for me.
Timer/Counter #1 is set up in CTC Mode to generate an interrupt once every mSec, (1000 interrupts/Sec)
Its interrupt fires once every mSec.
The Heart Beat counter counts up to 1000 then rolls over to 0.
It the Heart Beat counter is < 100 then its LED is on.
This, therefore, flashes this LED briefly once per second.
(It rolls over at 1000 now for clarity, in practice one might have it roll over at 999, as the count starts at 0).
However I find your code Timer / counter # 1 ....
Cheers!! |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Wed Sep 16, 2015 11:15 am Post subject: |
|
|
Hello Printpix52
This is my example of a clock using the main cpu oscillator
with it you get a one second tick
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10604&highlight=simple+clock
This is the code that ticks away each second
Code: |
'-----This increments the system seconds using the CPU clock
Tim0_isr:
Bres = Bres + 262144 '262144 = prescaler:1024 * timer0:256
If Bres > Xtal Then ' = xtal frequency
Bres = Bres - Xtal 'change to your crystal or RC frequency
'turn on clock output and measure frequency
Incr L2 ' Increment system seconds
Systick = 1 'set flag to update clock display
End If
Return
|
|
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
|
Back to top |
|
|
pykedgew
Joined: 22 Feb 2005 Posts: 17 Location: Australia
|
Posted: Fri Oct 02, 2015 12:01 am Post subject: |
|
|
You are missing
|
|
Back to top |
|
|
Printpix52
Joined: 18 Jun 2014 Posts: 282 Location: D.F.
|
|
Back to top |
|
|
|