Пример #1
0
void main(void)
{
	char opt;
	
	// Make sure nCS is high before doing anything
	nCS_HIGH;
	
	// Enable user module interrupts
	SleepTimer_EnableInt();

	// Enable global interrutps
	M8C_EnableGInt;

	// Start the user modules
	UART_Start(UART_PARITY_NONE);
	UART_PutCRLF();
	SPIM_Start(SPIM_SPIM_MODE_0 | SPIM_SPIM_MSB_FIRST);
	SleepTimer_Start();
	DAC8_Start(DAC8_FULLPOWER);
	UART_CPutString("Synthesiszing waveforms\r\n");
	WriteBlock(0);
	WriteBlock(1);
	WriteBlock(2);
	WriteBlock(3);
	while(1) 
	{
		UART_CPutString("Synthetic wave output is on Port0[4]\r\nCowabunga Dude! Time to catch some waves.\r\n\r\n0. Play block 0\r\n1. Play block 1\r\n2. Play block 2\r\n3. Play block 3\r\n4. Test status register\r\n5. Test byte mode\r\n6. Test sequential mode\r\n");
		
		opt = GetNumber(0, 6);
		switch (opt)
		{
			case 4:
				while(SPIRAM_StatusRegisterTest()) 
					SleepTimer_SyncWait(4, SleepTimer_WAIT_RELOAD);
				break;
			
			case 5:
				while(SPIRAM_ByteModeTest()) 
					SleepTimer_SyncWait(4, SleepTimer_WAIT_RELOAD);	
				break;
			
			case 6:
				while(SPIRAM_SequentialModeTest()) 
					SleepTimer_SyncWait(4, SleepTimer_WAIT_RELOAD);
				break;
			
			default:
				PlayBlock(opt);
				break;	
		}
	}
}
Пример #2
0
void main(void)
{
	int result;
	float voltage;
	int status;
	
	M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
	// Insert your main routine code here.
	
	//Start PGA in high power mode
	PGA_Start(PGA_HIGHPOWER);
	
	//Start ADCINC in high power mode
	ADCINC_Start(ADCINC_HIGHPOWER);
	
	//Start LCD
	LCD_Start();
	
	//Run the ADC continuously
	ADCINC_GetSamples(0);
	
	SleepTimer_Start();
   	SleepTimer_SetInterval(SleepTimer_1_HZ);
   	SleepTimer_EnableInt();
	
	while (1)
	{
		SleepTimer_SyncWait(1, SleepTimer_WAIT_RELOAD);
		
		// Wait for data to be ready
		while (ADCINC_fIsDataAvailable() == 0);
		
		// Get Data and clear flag
		result=ADCINC_iClearFlagGetData();
		voltage = result * SCALE_FACTOR;
		
		LCD_Position(0, 0);
		LCD_PrCString("                ");
		LCD_Position(0, 0);
		LCD_PrHexInt(result);
		
		LCD_Position(1, 0);
		LCD_PrCString("                ");
		LCD_Position(1, 0);
		LCD_PrString(ftoa(voltage, &status));
	}
}
Пример #3
0
void main(void)
{
	//Variables
	char lcdFirstLine[LCD_LENGTH], lcdSecondLine[LCD_LENGTH];
	unsigned int displaymode = 3; // FIXME: sollte 0 sein!
	
	/** init **/
	
	// interrupt and SleepTimer init
	M8C_EnableGInt ;                            // Turn on interrupts
	SleepTimer_Start();
    SleepTimer_SetInterval(SleepTimer_8_HZ);    // Set interrupt to a
    SleepTimer_EnableInt();                     // 8 Hz rate
	
	// init PGA and SAR6 for sun and rain sensor
	PGA_sun_SetGain(PGA_sun_G5_33);  // gain of 5,33
    PGA_sun_Start(PGA_sun_HIGHPOWER);
	//PGA_rain_SetGain(PGA_rain_G8_00);
    //PGA_rain_Start(PGA_rain_MEDPOWER);
	SAR6_sun_Start(SAR6_sun_HIGHPOWER);
	//SAR6_rain_Start(SAR6_sun_MEDPOWER);

	// LCD init
	LCD_Init();
	
	// print welcome screen to LCD
	csprintf(lcdFirstLine,"   Welcome to   ");
	csprintf(lcdSecondLine, " Weatherstation ");
	LCD_Position(0,0);
	LCD_PrString(lcdFirstLine);
	LCD_Position(1,0);
	LCD_PrString(lcdSecondLine);
	
	while(1) {
		// get temp and humidity here
		
		switch(displaymode) {
			case 0:
				// overview();
				break;
				
			case 1:
				// temp();
				break;
				
			case 2:
				// humidity();
				break;
				
			case 3:
				sunsensor(lcdFirstLine, lcdSecondLine);
				break;
				
			case 4:
				// wind();
				break;
		
			default:
				displaymode = 0;
				csprintf(lcdFirstLine,"     Error      ");
				csprintf(lcdSecondLine,"                ");
		}
		
		// lets see what we've got
		LCD_Position(0,0);
		LCD_PrString(lcdFirstLine);
		LCD_Position(1,0);
		LCD_PrString(lcdSecondLine);
		
		// lets sleep for a while
		SleepTimer_SyncWait(8, SleepTimer_WAIT_RELOAD);
	}
}
Пример #4
0
void main(void)
{

	//Variables
	char lcdFirstLine[LCD_LENGTH], lcdSecondLine[LCD_LENGTH];
	int displaymode = 1;
 	int temperature[5];
	int humidity[5];
	
	
	
	/** init **/
	
	// interrupt and SleepTimer init
	M8C_EnableGInt ;                            // Turn on interrupts
	SleepTimer_Start();
    SleepTimer_SetInterval(SleepTimer_8_HZ);    // Set interrupt to a
    SleepTimer_EnableInt();                     // 8 Hz rate

	// LCD init
	LCD_Init();
	
	// print welcome screen to LCD
	csprintf(lcdFirstLine,"   Welcome to   ");
	csprintf(lcdSecondLine, " Weatherstation ");
	LCD_Position(0,0);
	LCD_PrString(lcdFirstLine);
	LCD_Position(1,0);
	LCD_PrString(lcdSecondLine);


	while(1) {
	
		I2Cm_Start();						//Initialize I2C
		I2Cm_fSendStart( 0x28, 0);			//Send Measuring Request	
		measuring(temperature, humidity); 	//measuring temperature and humidity
	
		
		switch(displaymode) {
			case 0:
				// overview();
				break;
				
			case 1:
				printtemp(lcdFirstLine, lcdSecondLine, temperature); //write temp in the variable for the lcd
				break;
				
			case 2:
				printhum(lcdFirstLine, lcdSecondLine, humidity); //wirte humidity in the variable for the lcd
				break;
				
			case 3:
				// rain();
				break;
				
			case 4:
				// wind();
				break;
		
			default:
				displaymode = 0;
				csprintf(lcdFirstLine,"     Error      ");
				csprintf(lcdSecondLine,"                ");
		}
		
		// lets see what we've got
		LCD_Position(0,0);
		LCD_PrString(lcdFirstLine);
		LCD_Position(1,0);
		LCD_PrString(lcdSecondLine);
		
		// lets sleep for a while
		SleepTimer_SyncWait(8, SleepTimer_WAIT_RELOAD);
		
	}
	}
Пример #5
0
void main(void)
{
	unsigned long temp_ulong;
	INT temp_int, temp_int2;
	BYTE temp_byte;
	AMUX4_0_InputSelect(AMUX4_0_PORT0_1);        
   	AMUX4_1_InputSelect(AMUX4_1_PORT0_0);
   	INSAMP_Start(INSAMP_LOWPOWER); 
    ADCINC_Start(ADCINC_HIGHPOWER);      
   	DAC9_Ia_Start(DAC9_Ia_HIGHPOWER);
	DAC6_VGND_Start(DAC6_VGND_MEDPOWER);
	DAC6_VGND_WriteStall (31);
    PWM8_Vout_DisableInt();  
    PWM8_Vout_Start();     
    PWM8_Heater_DisableInt();  
    PWM8_Heater_Start();
	PWM8_NB_Out_DisableInt();  
    PWM8_NB_Out_Start(); 
	ADCINC_GetSamples(0);
	SleepTimer_Start();  
   	SleepTimer_SetInterval(SleepTimer_512_HZ);  
   	SleepTimer_EnableInt();   
	M8C_EnableGInt ;  
	LCD_Start();                  // Initialize LCD
	LCD_InitBG(LCD_SOLID_BG);

	while(1) {
		temp_ulong++;
		if ((ADC_IF & 1) == 1) {
			ADC_IF = ADC_IF & 254;
			Ri_Min = IIR_Int(Ri_Min_x1*2,Ri_Min,Ri_Filter_Strength);
			Ri_Delta = Ri_Max - Ri_Min;
			Ri_Mid = (Ri_Max + Ri_Min) / 2;
		}

		if ((ADC_IF & 2) == 2) {
			ADC_IF = ADC_IF & 253;
			Ri_Max = IIR_Int(Ri_Max_x1 * 2, Ri_Max, Ri_Filter_Strength);
			Ri_Delta = Ri_Max - Ri_Min;
			Ri_Mid = (Ri_Max + Ri_Min) / 2;
		}

		if ((ADC_IF & 4) == 4) {
			ADC_IF = ADC_IF & 251;
			ip = IIR_Int(ip_x1 * 2, ip, ip_Filter_Strength);
		}

		Ia_PID_Counter += Sleep_Counter;
		Heater_PID_Counter += Sleep_Counter;
		Heatup_Counter += Sleep_Counter;
		Vout_Lookup_Counter += Sleep_Counter;
		LCD_Counter += Sleep_Counter;
		Sleep_Counter = 0;

		if (Ia_PID_Counter > Ia_PID_Counter_Set) {
			Ia_PID_Counter = 0;
			Ia_PID();
		}

		if (Heater_PID_Counter > Heater_PID_Counter_Set) {
			Heater_PID_Counter = 0;
			Heater_PID();
		}

		if (Vout_Lookup_Counter > Vout_Lookup_Counter_Set) {}
			Vout_Lookup_Counter = 0;
			temp_int = ip - ip_to_Vout_Lookup_Start;
			if (temp_int < 0) {
				temp_int = 0;
			} else if (temp_int > (ip_to_Vout_Lookup_Size - 1)) {
				temp_int = (ip_to_Vout_Lookup_Size - 1);
			}
			PWM8_Vout_WritePulseWidth(ip_to_Vout_Lookup[temp_int]);
			
			#ifdef NB_Out
				temp_byte = 23;//0.45v
				if (ip < 251) { // 251 =0.9797787392968
					temp_byte = 46; //0.9v		
				} else if (ip > 259) { //259 = 1.02295956968912
					temp_byte = 0; //0v
				}
				PWM8_NB_Out_WritePulseWidth(temp_byte);
			#endif
		}

		if (LCD_Counter > LCD_Counter_Set) {
			LCD_Counter = 0;
			
			#ifdef LCD_Lambda_Text
				temp_int = ip - ip_to_Lambda_Lookup_Start;
				
				if (temp_int < 0) {
					temp_int = 0;
				} else if (temp_int > (ip_to_Lambda_Lookup_Size - 1)) {
					temp_int=(ip_to_Lambda_Lookup_Size - 1);
				}

				Lambda_x100 = ip_to_Lambda_Lookup[temp_int];
				temp_int = Lambda_x100;
				LCD_Position(0,0);
				temp_int2 = temp_int / 100;
				Str1[9] = btoa(temp_int2);
				temp_int = temp_int - (100 * temp_int2);
				temp_int2 = temp_int / 10;
				Str1[11] = btoa(temp_int2);
				temp_int = temp_int - (10 * temp_int2);
				Str1[12] = btoa(temp_int);
				LCD_PrString(Str1);
			#endif

			#ifdef LCD_AFR_Text
				temp_int = ip - ip_to_Lambda_Lookup_Start;

				if (temp_int < 0) {
					temp_int = 0;
				} else if (temp_int > (ip_to_Lambda_Lookup_Size - 1)) {
					temp_int = (ip_to_Lambda_Lookup_Size - 1);
				}

				Lambda_x100=ip_to_Lambda_Lookup[temp_int];
				temp_int = (INT) Lambda_x100 * 147;
				LCD_Position(0,0);
				temp_int2 = temp_int / 1000;
				Str1[6] = btoa(temp_int2);
				temp_int = temp_int - (1000 * temp_int2);
				temp_int2 = temp_int / 100;
				Str1[7] = btoa(temp_int2);
				temp_int = temp_int - (100 * temp_int2);
				temp_int2 = temp_int / 10;
				Str1[9] = btoa(temp_int2);
				temp_int = temp_int - (10 * temp_int2);
				Str1[10] = btoa(temp_int);
				LCD_PrString(Str1);
			#endif
			
			#ifdef LCD_Lambda_Graph
				temp_int = ip - ip_to_Lambda_Lookup_Start;
				
				if (temp_int < 0) {
					temp_int = 0;
				} else if (temp_int > (ip_to_Lambda_Lookup_Size-1)) {
					temp_int = (ip_to_Lambda_Lookup_Size - 1);
				}

				Lambda_x100 = ip_to_Graph_Lookup[temp_int];
				LCD_DrawBG(0, 0, 16, Lambda_x100);
			#endif
			
			#ifdef LCD_Temperature_Text
				temp_int = Ri_Delta-Ri_Delta_to_Temperature_C_Start;

				if (temp_int < 0) {
					temp_int = 0;
				} else if (temp_int > (Ri_Delta_to_Temperature_C_Size - 1)) {
					temp_int = (Ri_Delta_to_Temperature_C_Size - 1);
				}

				LSU_Temperature_C = Ri_Delta_to_Temperature_C[temp_int] + Ri_Delta_to_Temperature_C_Offset;
				temp_int = LSU_Temperature_C;
				LCD_Position(1,0);           
				temp_int2 = temp_int / 100;
				Str2[7] = btoa(temp_int2);
				temp_int = temp_int - (100 * temp_int2);
				temp_int2 = temp_int / 10;
				Str2[8] = btoa(temp_int2);
				temp_int = temp_int - (10 * temp_int2);
				Str2[9] = btoa(temp_int);
				LCD_PrString(Str2);
			#endif
			
			#ifdef LCD_Temperature_Graph
				temp_int = Ri_Delta - Ri_Delta_to_Temperature_C_Start;

				if (temp_int < 0) {
					temp_int = 0;
				} else if (temp_int > (Ri_Delta_to_Temperature_C_Size - 1)) {
					temp_int = (Ri_Delta_to_Temperature_C_Size - 1);
				}

				LSU_Temperature_C = Ri_Delta_to_Graph[temp_int];
				LCD_DrawBG(1, 0, 16, LSU_Temperature_C);
			#endif
		}

		if (Heatup_Heater_Output < 255) {   
			if (Heatup_Counter > Heatup_Counter_Set) {
				Heatup_Counter = 0;
				Heatup_Heater_Output++;
			}

			if ((Ri_Min > 50) && (Ri_Max < 475) && (Ri_Delta < Ri_Delta_Target)) {
				Heatup_Heater_Output = 255;
				Ri_Delta_Error_Sum = 0;
			}
		}
	}