PE ADC code example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PE ADC code example

3,418 Views
tani
Contributor I
Hi,

I am trying to use the processor expert to build a 4 channel ADC function. I have set up everything correctly in the ATD bean. The place where i am stuck is writing code to measure and get the values and where to insert them into the generated files of the PE. I have no idea how to write in C or assembly language and I was hoping to build this function easily using PE. Anyone has any suggestion? I was told there are only a few lines of codes that need to be added. Thanks,
Tani
Labels (1)
0 Kudos
2 Replies

342 Views
baddad
Contributor I
Tani,
 
Here is a simple program I wrote to demo the 9S08QG8 eval bd using an ADC in processor expert.  It turns an LED off if ADC <1/3 of max (255), blinks if 1/3 to 2/3 and on if >2/3.
 
// <<<<<<<< This section is generated by PE
/* Including used modules for compiling procedure */
#include "Cpu.h"
#include "Bit1.h"
#include "AD1.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
// <<<<<< end of PE generated code

   byte myValue;  /* Number of channels */
   byte min = 255/3;
   byte max = (255*2)/3;
   byte err;
   bool s;
   int i;
#define LED_ON 0;
#define LED_OFF 1;
void main(void)
 {
 /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
 PE_low_level_init();
 /*** End of Processor Expert internal initialization.                    ***/
 /* Write your code here */

   while(1) {
       /* run measurement with set wait for result */
       err = AD1_Measure(TRUE);
       /* Get results */
       err = AD1_GetValue8 (&myValue);
       
       /* Compare value and update LED */
       if (myValue > max) {
           s = LED_ON;            /* set LED ON */
       } else {
           if (myValue < min) {
               s = LED_OFF;        /* set LED OFF */
           } else {
               s = s^1;      /* invert LED ON <-> OFF */
           }
       }
       /* delay */
       for (i = 0; i < 10000; i++);
       Bit1_PutVal(s);
     }
     
     
 /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
 for(;:smileywink:{}
 /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
BadDad
0 Kudos

342 Views
tonyp
Senior Contributor II
No matter how easy something is, it always expects a MINIMUM level of relevant competency!  If you have no idea about programming, you'll have to start from there before trying to go further.  Even if you need to add a single line of code to make something work, you still need to know enough to figure out what that line should be.  In other words, could you drive your car even for one kilometer if you didn't know how to drive at all?
0 Kudos