]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
moved PWM from timer 3 to timer 1, now available two pwm channels
authorMichael Wiebusch <m.wiebusch@gsi.de>
Thu, 1 Dec 2016 13:51:57 +0000 (14:51 +0100)
committerMichael Wiebusch <m.wiebusch@gsi.de>
Thu, 1 Dec 2016 13:51:57 +0000 (14:51 +0100)
atmega32u4/cooler/cooler.c
atmega32u4/cooler/pinout.txt

index 276b415959f77d79d0c6632fbeb6cacb28033884..01ad0707f12985e9d4b6863dae959640aa2f59de 100644 (file)
@@ -100,18 +100,34 @@ void timer_init(void) {
   
   
 void PWM_init(void) {
-  DDRC |= 1<<PC6; // peltier PWM pin as output
+//   DDRC |= 1<<PC6; // peltier PWM pin as output
+  DDRB |= 1<<PB5; // peltier PWM pin as output (cooling)
+  DDRB |= 1<<PB6; // peltier PWM pin as output (heating)
 //   PORTC |= 1<<PC6;
-  TCCR3A |= 1<<COM3A1 | 0<<COM3A0; // clear output on compare match
-  TCCR3A |= 1<<WGM31  | 1<<WGM30; // fast PWM, 10 bit ...
-  TCCR3B |= 0<<WGM33  | 0<<WGM32; // ...
-  TCCR3B |= 1<<CS32   | 0<<CS31   | 0<<CS30; // clock source from /256 prescaler
+  TCCR1A |= 1<<COM1A1 | 0<<COM1A0 | 1<<COM1B1 | 0<<COM1B0 ; // clear output on compare match
+  TCCR1A |= 1<<WGM11  | 1<<WGM10; // fast PWM, 10 bit ...
+  TCCR1B |= 0<<WGM13  | 0<<WGM12; // ...
+  TCCR1B |= 1<<CS12   | 0<<CS11   | 0<<CS10; // clock source from /256 prescaler
   // (this should yield a PWM frequency of 30 Hz)
-  OCR3A = 0; // start with output = off
+  OCR1A = 0; // start with output = off
 }
 
-void set_PWM_output(uint16_t value){ // 0-1023
-  OCR3A = value;
+void set_PWM_output_A(uint16_t value){ // 0-1023
+  OCR1A = value;
+  OCR1B = 0; // don't cool and heat at the same time
+}
+void set_PWM_output_B(uint16_t value){ // 0-1023
+  OCR1B = value;
+  OCR1A = 0; // don't cool and heat at the same time
+}
+
+void set_peltier_output(int16_t value){ //-1023 to 1023
+  if(value < 0) {
+    set_PWM_output_B(-value);
+  } else {
+    set_PWM_output_A(value);
+  }
+  
 }
   
   
@@ -496,13 +512,15 @@ __attribute__((naked)) int main(void) {
       pushvalue(1,temps[SUPPSENSOR]);
       lastsecond = second;
       
-      if(temps[MAINSENSOR] > 30*16){ // turn off peltier if temperature is off limits (>30 deg C)
-        set_PWM_output(0);
+      if(temps[MAINSENSOR] > 40*16){ // turn off peltier if temperature is off limits (>30 deg C)
+//         set_PWM_output_A(0);
+//         set_PWM_output_B(0);
+        set_peltier_output(0);
         output_power_percent = 0;
       } else {
         uint16_t pid_output = pid_calculation( temps[MAINSENSOR] - set_value );
-        set_PWM_output(pid_output); // let PID compute output
-        output_power_percent = MIN(100,pid_output/10); // output power in percent (ignore the last 23 from 1023)
+        set_peltier_output(pid_output); // let PID compute output
+        output_power_percent = MIN(100,abs(pid_output)/10); // output power in percent (ignore the last 23 from 1023)
       }
       showPower();
       uartReport();
index 09dcc46b6a43721d76fb51c136d3fc067b7e65e4..309454fcffa8b9718ecce8c1b2d29ce1a4ee2b4f 100644 (file)
@@ -10,7 +10,7 @@ A0        PF7         D/C
 15        PB1(SCK)    SCK
 
 
-ignore jtag
+## JTAG is disabled ##
 #A0        PF7         TDI
 #A1        PF6         TDO
 #A2        PF5         TMS
@@ -21,5 +21,5 @@ ignore jtag
 3         PD0         Up Key
                      
                      
-5         PC6(OC3A)   Peltier Power PWM (cooling)
-6         PD7(OC4D)   Peltier Power PWM (heating)
\ No newline at end of file
+9         PB5(OC1A)   Peltier Power PWM (cooling)
+10        PB6(OC1B)   Peltier Power PWM (heating)
\ No newline at end of file