A discussion group for the PICMicro microcontroller. Also called the Microchip PIC, this list is dedicated to the use and abuse of this fine, simple, microcontroller. Close to topic posts are welcome, ie. general electronics.
|
Ok here goes another PIC Newbie question. Background information: I have an LM34DZ (Temperature Sensor) connected to the AD converter and I can get the AD converter to perform properly and place the result into ADRESL. I can display ADRESL information on a LED's and can see it change values as I heat up the LM34DZ or let it cool down. I have also created Macros to turn on different bits of the various ports to show a numbers on Seven Segment displays. Now for the question that I have. How do I go from the Raw value of the AD to calling the correct Macro in assembly. In C I would use math.h library and a switch statement to accomplish this. So below is what I would do to get the values to display in C but I do not have a C compiler yet (Ordered but has not arrived yet). /*Code sample * *Macros would be small functions to call. *The Macros are correct I have tested them. * * * *Macros/Functions * * ZERO "Ones value" * ONE * TWO * . * . * TEN "Tens Value" * TWENTY * . * . * NINTEY */ INT iADRESLresult; FLOAT flTemperature; INT iTENSdigit; INT iONESdigit; iADRESLresult = ADRESL; flTemperature = (FLOAT)iADRESLresult * 0.004; /*4 Millivolts per division*/ iTENSdigit = (INT) (flTemperature / 100.0); /*1deg = 10 millivolts*/ iONESdigit = (INT)((flTemperature - (FLOAT)(iTENSDigit * 100))/10); switch(iTENSdigit) { case(1): TENS; case(2): TWENTY; . . case(9): NINTEY; } switch(iONESdigit) { case(1): ONE; case(2): TWO; . . case(9): NINE; } /*END CODE SAMPLE*/ Any type of example of the math and/or using the branch statements to produce a switch type of construct would be greatly appreciated. Best Regards, Newbie Chad |
|
|
|
Your biggest issue is seperating out the 10s and 1s (hundreds?). there are a number of ways to go: - there are div/mul routines out there. google or check www.piclist.com - do a bcd conversion and use the digits from there. bcd code is available from same places - use a giant table lookup scheme. It could do a bcd conversion or perhaps a direct coding of what your macros do. tables are pretty useful on the PIC but a PITA. look for the table lookup apnote on microchip.com By the way, aren't you losing the top 2 bits if only using ADRESL? I left justify and just use ADRESH. You'll probably have at least 1 LSB of noise and maybe more so losing the two lower bits isn't a problem. --- In , "xdriverdude" <pigleychu@a...> wrote: > Ok here goes another PIC Newbie question. > > Background information: > I have an LM34DZ (Temperature Sensor) connected to the AD converter > and I can get the AD converter to perform properly and place the > result into ADRESL. > > I can display ADRESL information on a LED's and can see it change > values as I heat up the LM34DZ or let it cool down. > > I have also created Macros to turn on different bits of the various > ports to show a numbers on Seven Segment displays. > > Now for the question that I have. > > How do I go from the Raw value of the AD to calling the correct Macro > in assembly. > > In C I would use math.h library and a switch statement to accomplish > this. So below is what I would do to get the values to display in C > but I do not have a C compiler yet (Ordered but has not arrived yet). > /*Code sample > * > *Macros would be small functions to call. > *The Macros are correct I have tested them. > * > * > * > *Macros/Functions > * > * ZERO "Ones value" > * ONE > * TWO > * . > * . > * TEN "Tens Value" > * TWENTY > * . > * . > * NINTEY > */ > > INT iADRESLresult; > FLOAT flTemperature; > INT iTENSdigit; > INT iONESdigit; > > iADRESLresult = ADRESL; > flTemperature = (FLOAT)iADRESLresult * 0.004; /*4 Millivolts per > division*/ > > iTENSdigit = (INT) (flTemperature / 100.0); /*1deg = 10 millivolts*/ > iONESdigit = (INT)((flTemperature - (FLOAT)(iTENSDigit * 100))/10); > > switch(iTENSdigit) > { > case(1): > TENS; > case(2): > TWENTY; > . > . > case(9): > NINTEY; > } > > switch(iONESdigit) > { > case(1): > ONE; > case(2): > TWO; > . > . > case(9): > NINE; > } > /*END CODE SAMPLE*/ > > Any type of example of the math and/or using the branch statements to > produce a switch type of construct would be greatly appreciated. > > Best Regards, > Newbie Chad |
|
|
|
I am far from being an expert, but I have implemented a switch-like function in assembler as below. This is a project that I am just now wrapping up, so I know it works! Caveat: There may be better ways of doing this, since I have only been doing PIC's for about 6 or 7 months now...... --Joe JansenProcCmd movff CMD ,C_TEMP movf C_TEMP ,F ;Move C_TEMP into itself. Load the Z flag BZ VTCmdEnd ;If no command, then we are done decf C_TEMP bz VTPing ;0x01 is Ping Command decf C_TEMP ;0x02 is Ping reply. No reaction decf C_TEMP bz VTSetDebug ;0x03 is Set Debug Mode decf C_TEMP bz VTUnDebug ;0x04 is Clear Debug Mode decf C_TEMP bz VTSetNode ;0x05 is Set Node Number movlw 0x0B subwf C_TEMP bz VTDAChange ;0x10 is Set D/A value decf C_TEMP bz VTPTChange ;0x11 is change pulse time limit decf C_TEMP bz VTCondChange ;0x12 is change conditioner value goto VTCmdEnd ;Nothing else is implemented. > > ________________________________________________________________________ > ________________________________________________________________________ > > Message: 9 > Date: Thu, 12 Feb 2004 17:55:49 -0000 > From: "xdriverdude" <p...@aol.com> > Subject: Another Newbie Question > > Ok here goes another PIC Newbie question. > > Background information: > I have an LM34DZ (Temperature Sensor) connected to the AD converter > and I can get the AD converter to perform properly and place the > result into ADRESL. > > I can display ADRESL information on a LED's and can see it change > values as I heat up the LM34DZ or let it cool down. > > I have also created Macros to turn on different bits of the various > ports to show a numbers on Seven Segment displays. > > Now for the question that I have. > > How do I go from the Raw value of the AD to calling the correct Macro > in assembly. > > In C I would use math.h library and a switch statement to accomplish > this. So below is what I would do to get the values to display in C > but I do not have a C compiler yet (Ordered but has not arrived yet). > /*Code sample > * > *Macros would be small functions to call. > *The Macros are correct I have tested them. > * > * > * > *Macros/Functions > * > * ZERO "Ones value" > * ONE > * TWO > * . > * . > * TEN "Tens Value" > * TWENTY > * . > * . > * NINTEY > */ > > INT iADRESLresult; > FLOAT flTemperature; > INT iTENSdigit; > INT iONESdigit; > > iADRESLresult = ADRESL; > flTemperature = (FLOAT)iADRESLresult * 0.004; /*4 Millivolts per > division*/ > > iTENSdigit = (INT) (flTemperature / 100.0); /*1deg = 10 millivolts*/ > iONESdigit = (INT)((flTemperature - (FLOAT)(iTENSDigit * 100))/10); > > switch(iTENSdigit) > { > case(1): > TENS; > case(2): > TWENTY; > . > . > case(9): > NINTEY; > } > > switch(iONESdigit) > { > case(1): > ONE; > case(2): > TWO; > . > . > case(9): > NINE; > } > /*END CODE SAMPLE*/ > > Any type of example of the math and/or using the branch statements to > produce a switch type of construct would be greatly appreciated. > > Best Regards, > Newbie Chad |
|
Phil, Thank you for the information I found some routines that can perform floating point math which should help me get from the raw AD to the display values that I need to work with. Yes I am losing the top two bits but I figured that since I was building a thermostat and not a full scale temperature gauge the ARESL would be sufficent for a range of 0 to 99 degrees F. since one bit is equivalent to 4 millivolts and the LM34 gives 10 millivolts per degree F. Newbie Chad --- In , "Phil" <phil1960us@y...> wrote: > Your biggest issue is seperating out the 10s and 1s (hundreds?). > there are a number of ways to go: > - there are div/mul routines out there. google or check > www.piclist.com > - do a bcd conversion and use the digits from there. bcd code is > available from same places > - use a giant table lookup scheme. It could do a bcd conversion or > perhaps a direct coding of what your macros do. tables are pretty > useful on the PIC but a PITA. look for the table lookup apnote on > microchip.com > > By the way, aren't you losing the top 2 bits if only using ADRESL? I > left justify and just use ADRESH. You'll probably have at least 1 > LSB of noise and maybe more so losing the two lower bits isn't a > problem. > > --- In , "xdriverdude" <pigleychu@a...> wrote: > > Ok here goes another PIC Newbie question. > > > > Background information: > > I have an LM34DZ (Temperature Sensor) connected to the AD converter > > and I can get the AD converter to perform properly and place the > > result into ADRESL. > > > > I can display ADRESL information on a LED's and can see it change > > values as I heat up the LM34DZ or let it cool down. > > > > I have also created Macros to turn on different bits of the various > > ports to show a numbers on Seven Segment displays. > > > > Now for the question that I have. > > > > How do I go from the Raw value of the AD to calling the correct > Macro > > in assembly. > > > > In C I would use math.h library and a switch statement to > accomplish > > this. So below is what I would do to get the values to display in > C > > but I do not have a C compiler yet (Ordered but has not arrived > yet). > > > > > > /*Code sample > > * > > *Macros would be small functions to call. > > *The Macros are correct I have tested them. > > * > > * > > * > > *Macros/Functions > > * > > * ZERO "Ones value" > > * ONE > > * TWO > > * . > > * . > > * TEN "Tens Value" > > * TWENTY > > * . > > * . > > * NINTEY > > */ > > > > INT iADRESLresult; > > FLOAT flTemperature; > > INT iTENSdigit; > > INT iONESdigit; > > > > iADRESLresult = ADRESL; > > flTemperature = (FLOAT)iADRESLresult * 0.004; /*4 Millivolts per > > division*/ > > > > iTENSdigit = (INT) (flTemperature / 100.0); /*1deg = 10 > millivolts*/ > > iONESdigit = (INT)((flTemperature - (FLOAT)(iTENSDigit * 100))/10); > > > > switch(iTENSdigit) > > { > > case(1): > > TENS; > > case(2): > > TWENTY; > > . > > . > > case(9): > > NINTEY; > > } > > > > switch(iONESdigit) > > { > > case(1): > > ONE; > > case(2): > > TWO; > > . > > . > > case(9): > > NINE; > > } > > /*END CODE SAMPLE*/ > > > > Any type of example of the math and/or using the branch statements > to > > produce a switch type of construct would be greatly appreciated. > > > > Best Regards, > > Newbie Chad |
|
|
|
--- In , "xdriverdude" <pigleychu@a...> wrote: > Phil, > > Yes I am losing the top two bits but I figured that since I was > building a thermostat and not a full scale temperature gauge the > ARESL would be sufficent for a range of 0 to 99 degrees F. since one > bit is equivalent to 4 millivolts and the LM34 gives 10 millivolts > per degree F. when your Vref is 5V, one bit is 4.8 mV approx. You might want to consider setting your Vref to 2.55V and then one bit is one degree F. thus no conversion required - unless you want C :) Then you do need more than 1/4 the measurable range. |
|
Can anyone point me to where I might find an example of how to display data from a
PIC onto a computer screen? I am familiar with the BS2 and would like a feature like the
Debug command. I have a Max232 chip. Is there software for this, possibly with a schematic
somewhere?
Thank you all for your time and patience,
John
|
|
For a schematic on connecting the MAX232 to a PIC see http://www.junun.org/MarkIII/datasheets/Controller_SCH.pdf or just search Google. With this arrangement you can send serial data to a terminal program on the PC such as HyperTerminal. Of course, you can also use something like Visual Basic to create a specialized display. --- In , John Baker <johnbaker_erie_pa@y...> wrote: > Can anyone point me to where I might find an example of how to display data from a PIC onto a computer screen? I am familiar with the BS2 and would like a feature like the Debug command. I have a Max232 chip. Is there software for this, possibly with a schematic somewhere? > Thank you all for your time and patience, > John > --------------------------------- |
|
John, The hardware is very easy. Lookup the datasheet for the MAX232 and you'll see the setup. It's just four caps, plus connecting the Vcc and GND pins to their respective rails. Connecting to the PIC should be obvious: * PIC TX pin to MAX232 T1IN * PIC RX pin to MAX232 R1OUT * MAX232 T1OUT to PC's serial DB9 pin 2 * MAX232 R1IN to PC's serial DB9 pin 3 Check Microchip's site or search Google for the "software". If you have a hardware UART the code is just a few lines. Mike --- In , John Baker <johnbaker_erie_pa@y...> wrote: > Can anyone point me to where I might find an example of how to display data from a PIC onto a computer screen? I am familiar with the BS2 and would like a feature like the Debug command. I have a Max232 chip. Is there software for this, possibly with a schematic somewhere? > Thank you all for your time and patience, > John |
|
|
|
Thank you. I have found a few nice VB programs that do what I want. I have seen some
data on the screen now, and am very pleased with my results.
Thanks to all,
John
upand_at_them <u...@yahoo.com> wrote:
|