Discussion in "Project Help" started by    PsySc0rpi0n    Nov 27, 2014.
Wed Feb 11 2015, 04:45 pm
#41
There is something I'm not understanding about timers and real time...

As far as I understand, if I use a 11.0592Mhz crystal, my MCU (DS89C450) can count up to 11059200/12 = 921600 times per second (a machine cycle consists in 12 crystal pulses).

For example, 50000 timer increments will, theoretically, take 0.0542 S.
This comes from 50000/921600 = 0.0542

So, if I want to count 0.1 seconds I'll do:

x/921600 = 0.1 <=> x = 92160

So, this is the amount of times my timer has to increment.

So I configure my timer in 16 bit mode.
Then I do the following math:

92160/65535 = 1.41
So, I need 1.41 overflows to match up the 92160.

I do this by taking 1 complete overflow and then count the remaining time but in reverse order, like:

92160-65535 = 26625 - This is the remaining value after 1 overflow.

65535-26625=38910 - This is the initial value that my timer will have first. So I load my timer with 38910, then I start the timer and it will count from 38910 up to 65535. This will count the remaining from 65536 up to 92160. Then I let the timer to count from 0 up to 65535. At the end the timer has counted the 92160.

This should give me a real time simulation time of 100mS but my IDE only shows me 26mS

Am I doing anything wrong?


[ Edited Wed Feb 11 2015, 04:46 pm ]
Thu Feb 12 2015, 10:12 am
#42
Well.. DS89C450 is a single clock cycle MCU unlike traditional 12clock cycle operation of 8051. So your first calculation itself is wrong: 11059200/12 = 921600 should be: 11059200/1 = 11059200

try to redo your calculation now.
Thu Feb 12 2015, 01:59 pm
#43


Well.. DS89C450 is a single clock cycle MCU unlike traditional 12clock cycle operation of 8051. So your first calculation itself is wrong: 11059200/12 = 921600 should be: 11059200/1 = 11059200

try to redo your calculation now.

ajay_bhargav


Where can I find that info?
Can I trust the simulator IDE real time simulation info to check my calcs?
Fri Feb 13 2015, 05:49 am
#44


Can I trust the simulator IDE real time simulation info to check my calcs?

PsySc0rpi0n


Not really
You can't always be sure what settings the simulator is using.

Your figures look about right, although not the method I'd choose.
According to the data sheet there are several settings that
affect the clock speed being fed to the timer,
so double check those.
Does your compiler set up any clock sources ?


As for your LCD problem, you need extra long delays during
initialization, where the "Busy" bit does not work.
These delays are of the order of 10s of ms

Do you have the source code for the ASM program that does work?
Fri Feb 13 2015, 06:05 am
#45
Hello ExperimenterUK.

I'm using SDCC but I'm not an expert and I can't tell you (because I don't know) if my compiler sets up any clock sources...

I have the ASM code that works. It's here:

IDEONE

I didn't posted it all here because somehow the code wouldn't be indented correctly. It would stay centred I don't know why!


[ Edited Fri Feb 13 2015, 06:05 am ]
Fri Feb 13 2015, 10:14 am
#46
You can zip it and attach the file instead of directly posting it. Well as far as I know about sdcc there is nothing related to clock that is done in startup script. its solely on programmer to do the initialization. regarding single clock cycle operation I was talking about, you can get it from data sheet, its on the first page.

Also try to use for loops for delay so you dont have to worry about setting right value for timer. You can change the count anytime and see if things work in C.
Fri Feb 13 2015, 09:42 pm
#47
When you say I should divide the crystal value by one is because this quote from datasheet (underlined line)??


FEATURES
 High-Speed 8051 Architecture
One Clock-Per-Machine Cycle
DC to 33MHz Operation
Single Cycle Instruction in 30ns
Optional Variable Length MOVX to Access
Fast/Slow Peripherals
Dual Data Pointers with Automatic
Increment/Decrement and Toggle Select
Supports Four Paged Memory-Access Modes



[ Edited Fri Feb 13 2015, 09:42 pm ]
Mon Feb 16 2015, 07:36 pm
#48
Ok, anyway... I found what the problem was when I said I couldn't make any C code to work in my MCU.

Now I have another challenge going on... I can work with port P1 and LCD but I can't work with port P0 and LED's or LCD. I just can't make this port go "high" (+5Vcc) and I can't figure out why.

I'm using 8 resistors of 4K7 ohms connected to the 8 LEDs and each one connected to each MCU P0 pin, like:

P0_0--->+LED--->-LED--->4K7R--->GND

Any thoughts?
Mon Feb 16 2015, 08:21 pm
#49


Now I have another challenge going on... I can work with port P1 and LCD but I can't work with port P0 and LED's or LCD.
I just can't make this port go "high" (+5Vcc)

PsySc0rpi0n


That's an easy one
Port 0 is open drain, that is, it can sink current but not
supply it.
To get a high output you will need pull up resistors.
Check the data sheet to see what the other ports can do
it varies between types.

The usual way to drive LEDs on P0 is ...

+5 --- 1k --- +LED- ---P0_0
Pin low gives LED on.

4K7 will be very dim.
 PsySc0rpi0n like this.
Mon Feb 16 2015, 11:48 pm
#50
Ok, nice... My mind always plays tricks on me when it comes to port 0.

Now I'm trying to draw a simple round ball using 4 custom chars to draw later a smile from this ball but using the code attached, I'm not getting what I expected...

Can you help and try to see what's wrong in the code?
Attachment






Edited;

Ok, I got it... Missing parenthesis when calling init_LCD () function in main ()... But the compiler didn't even complained!


[ Edited Tue Feb 17 2015, 12:39 am ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am