Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 16th August 2009, 02:41 PM   #91
Default

I want to avoid using .h files since...thats what i know( dont know whether its wrong or right)...when you call a function from a header file then it is replaced on every line the function is invoked..i-e a macro.I am already low on memory(i will have to use two pic micros if i use that technique).I want to differentiate between two ADC conversions(one for temperature and one for a SG) for which i wanted to use a bit.Secondly about the variable problem with two source files.. since i will store temp values in the internal EEPROM i want to use a variable as a counter till 100 and use that same variable as an address to store data.What i have done is that i have given up checking that variable in main and used it in the ADC routine only.

Thanks.
__________________
Syed

Last edited by Wond3rboy; 16th August 2009 at 02:42 PM.
Wond3rboy is offline  
Old 16th August 2009, 02:47 PM   #92
Default

make a function like:

int SetBit(int var, int bit){
var = var | (1<<bit);
return var;
}
int ClearBit(int var, int bit){
var = var & ~((1<<bit));
return var;
}
AtomSoft is offline  
Old 16th August 2009, 03:56 PM   #93
Default

Quote:
Originally Posted by AtomSoft View Post
make a function like:

int SetBit(int var, int bit){
var = var | (1<<bit);
return var;
}
int ClearBit(int var, int bit){
var = var & ~((1<<bit));
return var;
}

I have gone through you cheat sheet(very helpful!). I can just use a 8bit data type cause i can use it for indication.Its the memory i want to save on but already worked around it.

A question about setting automatic acquisition time.How can we do 1TAD? manually?
Thanks.
__________________
Syed

Last edited by Wond3rboy; 16th August 2009 at 03:58 PM.
Wond3rboy is offline  
Old 16th August 2009, 04:42 PM   #94
Default

Which PIC...?
AtomSoft is offline  
Old 16th August 2009, 06:49 PM   #95
Default

The method I provided for a variable shared between files will use no additional memory. The variable is allocated in the file shareStuff.c only.

3v0

Quote:
Originally Posted by Wond3rboy View Post
I want to avoid using .h files since...thats what i know( dont know whether its wrong or right)...when you call a function from a header file then it is replaced on every line the function is invoked..i-e a macro.I am already low on memory(i will have to use two pic micros if i use that technique).I want to differentiate between two ADC conversions(one for temperature and one for a SG) for which i wanted to use a bit.Secondly about the variable problem with two source files.. since i will store temp values in the internal EEPROM i want to use a variable as a counter till 100 and use that same variable as an address to store data.What i have done is that i have given up checking that variable in main and used it in the ADC routine only.

Thanks.
__________________
Please post questions to the forums. PM's are for personal communication.

BCHS/3v0's Tutorials
Junebug USB PIC programmer kit., USB Bit Whacker,
The 15 Minute Printed Circuit Board! (+drill time)
3v0 is online now  
Old 17th August 2009, 04:53 AM   #96
Default

Quote:
Originally Posted by AtomSoft View Post
Which PIC...?
18LF4620.

Quote:
Originally Posted by 3v0 View Post
The method I provided for a variable shared between files will use no additional memory. The variable is allocated in the file shareStuff.c only.

3v0
I am just trying it.
__________________
Syed
Wond3rboy is offline  
Old 1st September 2009, 06:46 PM   #97
Default

I have a few questions about timers, here's a paste from one of microchips manuals

Quote:
#include <timers.h>
void OpenTimer0( unsigned char config0 ); // Configure and enable timer x.
void OpenTimer1( unsigned char config1 );
void OpenTimer2( unsigned char config2 );
void OpenTimer3( unsigned char config3 );
void WriteTimer0( unsigned int value16 ); // Write a value into timer x.
void WriteTimer1( unsigned int value16 );
void WriteTimer2( unsigned char value_8 );
void WriteTimer3( unsigned int value16 );
unsigned int ReadTimer0( void ); // Read the value of timer x.
unsigned int ReadTimer1( void );
unsigned char ReadTimer2( void );
unsigned int ReadTimer3( void );
void CloseTimer0( void ); // Disable timer x.
void CloseTimer1( void );
void CloseTimer2( void );
void CloseTimer3( void );
I'm just wondering about the usage of some of these commands. I'm pretty sure with the open timer command I'm going to first store a configuration into Config0, or any other variable I want to place there, or just put the configuration commands right there in the open command right?

What do I do with the read command? Does it place the value in a variable? How do I access the timer value once it has been read? Is the variable inserted in to that command, or is it a predefined one or what?

I've been away from this for a while with work, so I'm trying to get caught up. Im working on timed multitasking now, but I have to figure out timers and timed interrupts first. I do understand how timed multitasking works in theory, but I'm learning how to actually code it in C18 now.

Edit: found part of the answer to one of my questions in another microchip document
Quote:
Timer register(s) for ReadTimerx and WriteTimerx functions:
· Timer0 (16 bit): TMR0L,TMR0H
· Timer1 (16 bit): TMR1L,TMR1H
· Timer2 (8 bit): TMR2
· Timer3 (16 bit): TMR3L,TMR3H
__________________
-Paul

Last edited by Triode; 1st September 2009 at 07:08 PM.
Triode is offline  
Old 1st September 2009, 07:50 PM   #98
Default

Straight from the manual:
Code:
1.3.1        ReadTimer0
For TMR_V1, TMR_V2, TMR_V3, TMR_V4, TMR_V5 and TMR_V6

Function:
Reads the value of the timer0.

Include:	
timers.h

Prototype:
unsigned int  ReadTimer0( void );

Remarks:
This function reads the value of the timer0 register.

Timer0:                         TMR0L,TMR0H

 

Note: When using a timer in 8-bit mode that may be configured in 16-bit mode (e.g., timer0), the upper byte is not ensured to be zero. The user may wish to cast the result to a char for correct results. For example:
 

  // Example of reading a 16-bit result
  // from a 16-bit timer operating in
  // 8-bit mode:

  unsigned int result;

  result = (unsigned char) ReadTimer0();

Return Value:
	
The current value of the timer.

File Name:
t0read.c

Last edited by AtomSoft; 1st September 2009 at 07:52 PM.
AtomSoft is offline  
Old 1st September 2009, 08:38 PM   #99
Default

Thanks, I got that far.

Which structure do people generally use for multitasking?

I can picture one where you have a loop that monitors the timer, and when it hits a value it increments all of the variables that are counting up for their respective tasks, and then resets the timer. Or one that has a timer interrupt triggered event that increments the variables then resets the timer. I'm guessing the ladder would be more accurate, but I'll have to learn to use interrupts to try it. I'm working on that right now.
__________________
-Paul
Triode is offline  
Old 1st September 2009, 09:13 PM   #100
Default

where did you learn multitasking? From the NET? (everything i learned or know about on any subject i learned online)

Any good resources you can share?
AtomSoft is offline  
Old 1st September 2009, 09:16 PM   #101
Default

I know so little about PIC timers. (or arm ) but i have a question since on the subject here. And not sure if you know but may benefit from a answer.

If i have 2 times on a pic can i have both on at the same time?
Also if so ... if both are on and 1 triggers. will the other continue counting?
if so.... if the other triggers then which function will i be in?
AtomSoft is offline  
Old 1st September 2009, 09:28 PM   #102
Default

I learned C++ programming mostly online, though I did take one class on it. And I've taken one other computer science class that went through all sorts of math and structure concepts, but that was focused on PC programming. So I am learning MCU programming from the internet. Trying to anyway, I'm just reading whatever microchip document seems related to what I'm doing and tutorials I find online, probably similar to what you're doing. I just get stuck a lot because there's so much out there, and cause I keep having long breaks in working on this where I'm too busy for my hobby.

Anyway, once I develop a general structure for timed multitasking in C18 I'll be sure to post it, but its been slow going.

right now I'm working off of this document
http://w3.id.tue.nl/fileadmin/id/obj...NS_18F4550.pdf

and in general, the manuals for C18 released by microchip, data sheets, errata and that whole mess.
__________________
-Paul
Triode is offline  
Old 1st September 2009, 09:51 PM   #103
Default

Have you read my tutorial on cooperative multitasking ? It uses a timer to block and enable tasks. Even if it is not what you want to do it should get you started.

3v0's Tutorials

Bottom entry in the table

3v0-
__________________
Please post questions to the forums. PM's are for personal communication.

BCHS/3v0's Tutorials
Junebug USB PIC programmer kit., USB Bit Whacker,
The 15 Minute Printed Circuit Board! (+drill time)
3v0 is online now  
Old 2nd September 2009, 12:25 AM   #104
Default

I have, that's actually what I was using, I just lost track of it, like I said I was away from this hobby for a few months, so I forgot where some of the resources I was using were. Thanks.

Its kind of hard to keep up a hobby when your life goes between super busy and a lot of free time, when you get a break you spend most of it just picking up where you left off. Oh well.
__________________
-Paul
Triode is offline  
Old 2nd September 2009, 01:04 AM   #105
Default

It you document is fits I would be glad to add it to my list.
__________________
Please post questions to the forums. PM's are for personal communication.

BCHS/3v0's Tutorials
Junebug USB PIC programmer kit., USB Bit Whacker,
The 15 Minute Printed Circuit Board! (+drill time)
3v0 is online now  
Reply

Tags
c18, questions

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
A few questions erosennin Feedback/Comments 24 29th November 2007 12:08 AM
2 questions juan123 Electronic Projects Design/Ideas/Reviews 5 27th September 2007 03:46 AM
A few questions. Marks256 General Electronics Chat 55 5th August 2006 11:49 PM
few questions Victor Frankenstein General Electronics Chat 13 5th July 2005 07:29 PM
Questions? Philipc Electronic Projects Design/Ideas/Reviews 4 7th August 2003 07:18 PM



All times are GMT. The time now is 09:09 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker