Well, believe it or not, and if MPLAB StopWatch don't lie, your ISR need 4.6 mSec to execute... and usually you want to reload the timer before re-starting it.
Do you have any schematic of your thing and a brief description of what you want to do?
Well, believe it or not, and if MPLAB StopWatch don't lie, your ISR need 4.6 mSec to execute... and usually you want to reload the timer before re-starting it.
Do you have any schematic of your thing and a brief description of what you want to do?
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Thanks, I didn't know how long the ISR really was.
Now we know this, there are a couple of possible solutions..
make the timer longer to 6 or 8 mSec, restart and reload the timer after the ISR or make the ISR less long.
I tried to restart the timer after the ISR(above post) but that didn't work.. Suprisingly did it work somehow when the end of the ISR was 'resume loop'. Then was the program able to make a I2C-read from the RTC and update the var's.
So, the first possible solution is to make longer the timer to let's say 8mSec and afther that reduce the length of the ISR and posible to set the timer back to 2mS.
The ISR is doing a lot of work every time and that is not necessary do execute every time. The lookup for segments is not deeded everytime but can be executed in the program somewhere else and 1 in the 10 times of shiftout is also very acurate(I'm not placing it in a nucear powerplant...) So the only thing left for the ISR to do is shiftout the segmentsdata.
I had problems with var's I did change at the mainloop. He didn't update them by the shiftout.
So, when I place this T2CON = %00000010 is the presale to 1:16 and is the timer about 8mSec, right? Then it have to work anyway?
about the schematic: a ds1307 is connected to A0 & A1. the two 74HC595 are placed at B0 & B1. The pushbuttons for the menu are at port A2, A3 & A7. All including external pullups. For the 7segmentsdisplays are resistors added. The 7segmentsdisplays are Common Cathode and connected with a BC557C to the GND. The PIC16f628 is working at it's internal oscillator. And a smal capacitor of 0,1uF added from V+ to GND near the IC's. So, it's all very basic and there isn't more to tell about the schematic.
Can you also measure how long it takes for a I2C-read and write? Because, when I delete it from the mainloop the ISR can use other var's from the loop...
Last edited by ADCON; - 30th December 2007 at 13:00.
To measure how long a single code line or chunk of code need toexecute, you have several method
1: Scope method
you Set/Clear an I/O before and after a code chunk, then you measure it with a scope
2: MPLAB StopWatch
You set a breakpoint at the end of the code chunk you want to measure, You set the PC at the start of the code chunk, then you click on Run at PC (refer to MPLAB help file)
3: use a PIC timer
Same concept as StopWatch but you need to send the results to a LCD or via serial communication. The following link explain it better
instruction execution time
http://www.picbasic.co.uk/forum/showthread.php?t=365
i'll try to figure out what the heck happen here... would be nice if i had those shift register![]()
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
thanks, I use microcodestudio but this is a reason to look for MPlab.
Microcodestudio sadly don't have a timerfunction. A time ago did I look for MPlab but it looked a lot harder to work with to me.
The shiftregisters works simple. It is data+clock and when all data is loaded a puls so the latches reset to the new value.
Maby you do have Proteus VSM? I mean that they have also this registers(haven't a lisence myself). The datasheet is here: http://www.alldatasheet.com/datashee...S/74HC595.html
The RTC I used is a DS1307 from Maxim-ic.com but that works fine..
ProteusVSM
any sim
E+457810214
sorry not for me.
Yeah i know those shift register and i know what a shift register is, what i meant is that it would be great if i had them in stock to build the circuit and test it in a real environment.
I'm not a Sim fan... i know a few people using it for all their design and they seems to be more than happy with it.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Yes, sim programs are expensive. I had a free beta-testversion once, it had still to much bugs to work with, after that came the pay-version.. I also like to life-testalso my bankaccount.. it only takes sometimes some more time. But the good side is that when it workt it really works and with sim-programs is that always a question..
Well, Possibli can you tell me the length of a I2Cread/write procedure because I think that it is also to long. When I start the timer after the ISR it will only read the RTC, it never finishes the coldstart.
I did try to set the prescale to 1:16 but it hadn't any good progress. How do I become a timerinterrupt every 8mSec? of 16msec? Maby I can thy that so it works..
Well the prescaler was already 1:16 at the first post.. hence why you didn't had any better results
Now what you need to do is to use the POSTscaller. if you set the postscaller to 1:2 you'll have a 2mSec*Prescaller int. 8mSec, postscaller 1:4 and so on
seems to work with the second suggestionCode:T2CON = %00011010 'X------- Unimplemented '-0011--- postscale 1:4 '-----0-- Timer2 off '------10 prescaler 1:16
Code:// Snip ON INTERRUPT GOTO ISR PR2 = 124 ' load period register for 2mSec PEIE = 1 ' Enable peripheral interupt GIE = 1 ' enable Global interrupt TMR2ON = 1 ' TMR2 ON GOTO LOOP disable ISR: TOGGLE PORTB.0 TMR2IF = 0 ' Clear interrupt flag resume enable // end snip
Last edited by mister_e; - 30th December 2007 at 22:26.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks