32-bit variable in 16-bit dsPIC microcontroller.

Status
Not open for further replies.

variaseng

New Member
Hi, I am using dsPIC30f4011 microcontroller. I have this counter variable that should reach up to 33333 counts. But since the dsPIC is only a 16-bit microcontroller, I am only able to reach until 32768. How can I extend this count such that I can reach up to the maximum value I need? Thank you very much for your help!
 
You need to create a high word and low word.. when the low word is incremented and over spills check the carry flag and increment the high word (I take it you are using assembler).
 
@Ian Rogers. Thank you very much! I am using C in mikroC dsPIC environment. If I do the high word/low word in C, how do I detect the carry flag?
@Pommie. Thank you very much! Yes, but I need a signed counter.
 
If you are using C then you should have access to 32 bit signed variables. Check the manual, it could be int or long.

Edit, a long is a 32 bit variable in MikroC for DsPic.

Just for fun, using 16 bit variables, you could do,
Code:
// to increment
    if(VarLo==32767){
        VarLo=0;
        VarHi++;
    }else{
         Varlo++;
    }
//to decrement
    VarLo--;
    If(VarLo==-1){
        VarLo=32767;
        VarHi--;
    }

Mike.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…