Jump to content
Sign in to follow this  
Hooleygan

Could I please have some help.

Recommended Posts

Hello,

 

I am in a class at my tafe that is supposedly a beginner Microcontrollers class but it turns out that everyone else in the class has a lot of experience already with programming and so the teacher has decided to pitch the content at a much higher level.

 

As I have done nothing as of yet myself I am really struggling.  He has asked us to design and build a 0-10V voltmeter which can display on a screen (he has given us the nokia 5110) and having learnt no C up till now I'm hard pressed.

 

I have found RobG's library but I am having a hard time understanding the concepts of how to implement it, especially as I don't know if what I have written so far will work at all.

 

To scale the ten volts down to the safe input range of the 430 I have a voltage divider (5 to 1) to bring the reading down to 2V5 when the input is @10V.

 

In the code I am trying to scale the ADC10 output down to the right range before sending to the display but that is about as far as I have gotten.

Any help would be greatly appreciated.

//Voltmeter

 
#include <msp430g2553.h>
#include "PCD8544.h"
 
 
#define Run_value 1
#define Scaling_value 85.25                                              /*as the ADC3v3 ref is equal to the 1023rd ADC value
                                                                                                     then the 2v5 highest value we should get in is equal to 852.5.
                                                                                                     Divide this by 85.25 to get to 2v5 being 10*/
#define Scaled_value ADC10MEM/Scaling_value
 
 
void main(void)
{
 
WDTCTL = WDTPW + WDTHOLD;                 // Stop Watchdog Timer
 
//Setup: ADC
ADC10CTL0 = (ADC10SHT_3 +ADC10ON);
ADC10CTL1 = INCH_0;       //A0 is input pin
__delay_cycles(1000);                     // Wait for ADC Ref to settle
ADC10CTL0 |= ENC  + ADC10SC; //Turn ADC on, enable conversions
 
//Setup: Run Program
if (Scaled_value <= 10.0)
   {
Run_Value = 1;           //while this equals 1 the screen will display voltage reading
   }
 
if (Scaled_value > 10.0)
{
Run_Value = 0;           //while this equals 0 the screen will display max voltage
}
 
while (Run_value = 1)
{
// Show voltage readout on screen
 
 
_
 
 
while (Run_value = 0)
{
 
  //Show Max voltage on screen
 
}
 
}
 

 

 

ROBG's nokia5110 library: PCD8544.h

 

Thanks,

 

Hooleygan
 

Share this post


Link to post
Share on other sites

Hooleygan,

 

Sorry to say, but you've got multiple, steep, learning curves ahead.

First, regarding your loop code (the while() statements). 

...while (Run_value = 1)...

You are assigning the value of 1 to Run_value, not testing it. Same with the following statement intended to test for zero.

To test for equality you need to use the "==" operator, not the "=" operator.  This can happen to experienced programmers too, as a typo.

Some use the following syntax so the compiler will generate an error:  while(1== Run_value), if you inadvertently attempt to assign with while( 1 = Run_value), the compiler will stop and tell you that you can't assign to a constant.

As to your bigger problem, a beginning micro class where the professor is either unaware of, or choosing to ignore your lack of prior programming skills, you really do need to sit down with him/her and sort out a plan. Further, in most institutions, the course catalog and syllabus are the "contract" regarding requirements for a course.  If your instructor is basically running a course that does not adhere to the "contract" you might have grounds to have a more assertive conversation - though that may have unwanted consequences. 

Ultimately, you are at such a tremendous disadvantage if the course continues as you've described, your best bet may be to cut your losses and postpone the course.

FWIW, in real life I'm an asst. professor of nursing in an accelerated program, so I see the "deer in the headlights" look with some frequency.  You have to decide how best to handle your situation, whether it's a quick exit, or planning to do a long stretch of 20-hr days.  If you decide to proceed, find the smartest, sympathetic classmate to buddy-up with.  My nursing students employ that technique on a regular basis, and it is a strategy with a high success rate.

Best of luck!

Bob

Share this post


Link to post
Share on other sites

Hooleygan,

 

Sorry to say, but you've got multiple, steep, learning curves ahead.

First, regarding your loop code (the while() statements). 

...while (Run_value = 1)...

You are assigning the value of 1 to Run_value, not testing it. Same with the following statement intended to test for zero.

To test for equality you need to use the "==" operator, not the "=" operator.  This can happen to experienced programmers too, as a typo.

Some use the following syntax so the compiler will generate an error:  while(1== Run_value), if you inadvertently attempt to assign with while( 1 = Run_value), the compiler will stop and tell you that you can't assign to a constant.

As to your bigger problem, a beginning micro class where the professor is either unaware of, or choosing to ignore your lack of prior programming skills, you really do need to sit down with him/her and sort out a plan. Further, in most institutions, the course catalog and syllabus are the "contract" regarding requirements for a course.  If your instructor is basically running a course that does not adhere to the "contract" you might have grounds to have a more assertive conversation - though that may have unwanted consequences. 

Ultimately, you are at such a tremendous disadvantage if the course continues as you've described, your best bet may be to cut your losses and postpone the course.

FWIW, in real life I'm an asst. professor of nursing in an accelerated program, so I see the "deer in the headlights" look with some frequency.  You have to decide how best to handle your situation, whether it's a quick exit, or planning to do a long stretch of 20-hr days.  If you decide to proceed, find the smartest, sympathetic classmate to buddy-up with.  My nursing students employ that technique on a regular basis, and it is a strategy with a high success rate.

Best of luck!

Bob

Thanks for the reply,

 

I have had multiple talks with him trying to get help but so far he seems semi-oblivious. That is why I was looking for help elsewhere, hoping to try and get as far on the project as I can while also trying to get him to see the problem.  I'll have another look at the course outline though, see if he's missing stuff thanks.  

 

I see what you mean about the while loop, thank you.  

Share this post


Link to post
Share on other sites

Re using the LCD Library, you probably best start with RobG's thread:

http://forum.43oh.com/topic/1312-nokia-5110-display/

 

From the looks, he didn't put the "library" into a separate source file but simply implemented it in the main program file. The PCD8544.h file just contains a few constants and the fonts.

 

If this would be my project, I'd copy the function declarations up to and including initLCD into a seperate .h file (e.g. LCDLibrary.h), and then the function implementation (after main, starting at void writeStringToLCD) into a separate .c file (e.g. LCDLibrary.c). Then include the LCDLibrary.h file at the top of main.c and LCDLibrary.c and you should be ready to go.

Share this post


Link to post
Share on other sites

Do you mean that the PCD8544 file only contains a few setup instructions to the LCD driver? Most of the functions to interact with the screen being still in the main.c?

Thanks for the response.

Share this post


Link to post
Share on other sites

The PCD8544.h just contains a few constants. There's no "LCD Driver". All code is in the main.c.

 

There's intensive use of C macros to hide the interaction with GPIO in convenient "commands". For example

#define LCD5110_SET_COMMAND P1OUT &= ~LCD5110_DC_PIN

allows you to use LCD5110_SET_COMMAND like a C command

LCD5110_SET_COMMAND;

but will be translated behind the scenes by the compiler to the C line

P1OUT &= ~LCD5110_DC_PIN;

As with all programming, try to read and understand RobG's example code, and experiment with it, before blindly copying it into your own project.

Share this post


Link to post
Share on other sites

the #define lines make pre-compiler defines, they mean that every time you write the first name, it is replaced with the rest of that line. So

#define Run_value 1

means that from that point on, all occurrences of Run_value should be read as if there was the literal value 1.

 

C and C++ are case sensitive, that means that Run_value is a different name than Run_Value.

 

To store some value, you must store it in a variable. The easiest to use variables are integers, whom are written as int:

int Run_value;

To assign a value to a variable, you use a single equal sign. To compare them you use a double equal sign:

Run_value = 0;        
while (Run_value == 1)
{
  // your code here
}

These are some basic C/C++ things to know.

 

---------------------------------------------

 

Now for some more considerations:

 

floating point (the underlying implementation of non-integer numbers) numbers are never accurate. This is OK, it just means you should never make equal-to comparisons, nor assume there is no gap between two numbers.

In your code you write two mutually exclusive if cases, but there is an else statement you could use instead.

if (Scaled_value <= 10.0)
{
  Run_value = 1;           //while this equals 1 the screen will display voltage reading
}
else
{
  Run_value = 0;           //while this equals 0 the screen will display max voltage
}

Then another issue to realize is that C/C++ run linear. So if you set Run_value to 1, it won't change until you actively change it. For example by moving code execution to pass through this test again.

In your code, you have this snippet.

if (Scaled_value <= 10.0)
   {
Run_Value = 1;           //while this equals 1 the screen will display voltage reading
   }
 
if (Scaled_value > 10.0)
{
Run_Value = 0;           //while this equals 0 the screen will display max voltage
}
 
while (Run_value = 1)
{
// Show voltage readout on screen
 
 
_
 
 
while (Run_value = 0)
{
 
  //Show Max voltage on screen
 
}
 
}

You could change it to

while (1)
{
  if (Scaled_value <= 10.0)
  {
    Run_value = 1;           //while this equals 1 the screen will display voltage reading
  }
  else
  {
    Run_value = 0;           //while this equals 0 the screen will display max voltage
  }
 
  if (Run_value == 1)
  {
    // Show voltage readout on screen
  }
  else
  {
    //Show Max voltage on screen
  }
}

This still could be simpler, but I tried to stay as close to your code as possible.

 

--------------------------------------------------

 

As a last note. If this is your first programming experience, tell your teacher. This is not even close to a 101 class exercise. You may expect him to give you a smoother introduction to programming.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...