Example #1
0
/*********************************************************************
  
  Main Program Loop

**********************************************************************/
int main()
{

  /* Initializations */
  debug_init();     /* This should be first. */
  timer_init();

  /* This should be before any GPIO activities. */
  uint32 ret_val = bcm2835_init(); 
  if ( ret_val == 0 )
  {
    DEBUG_MSG_ERROR("bcm2835_init() failed.");
  }

  pwm_init();
  pump_init();
  therm_init();
  pid_init();

  pump_start();

  /* Take temperature as input from console. */
  float setpoint;
  printf("Set your desired temperature: ");
  scanf("%f", &setpoint);
  pid_update_temp_setpoint(setpoint);

  pid_gain_params pid_gain;
  pid_gain.k_p = 1;
  pid_gain.k_d = 1;
  pid_gain.k_i = 1;
  pid_gain.k_windup = 1;
  pid_set_gain(&pid_gain);

  /* Main Program Loop */
  while (1)
  {
    pwm_run();
    therm_capture();
    pid_loop();
  }

  pump_stop();

  /* De-initializations */
  pump_deinit();
  pid_deinit();
  pwm_deinit();

  /* This should be after all GPIO activities. */
  ret_val = bcm2835_close();
  if ( ret_val == 0 )
  {
    DEBUG_MSG_ERROR("bcm2835_close() failed.");
  }
  timer_deinit();
  debug_deinit();   /* This should be last. */

  return 0;
}
Example #2
0
File: main.c Project: bhase/garage
void deinit(void)
{
	cli();
	timer_deinit();
	pwm_deinit();
	adc_deinit();
	io_deinit();
}
Example #3
0
void pwm_set_rate(byte_t rate)
{
    if (rate == 0)
    {
        pwm_deinit();
    }
    else
    {
        if (!pwm_on)
        {
            pwm_init();
        }
        else
        {
            OCR2 = rate;
        }
    }
}