Corrected the duration calculation on fixed DDS length.
This commit is contained in:
		
							parent
							
								
									120442533d
								
							
						
					
					
						commit
						660fe0c602
					
				
							
								
								
									
										4
									
								
								DDS.h
								
								
								
								
							
							
						
						
									
										4
									
								
								DDS.h
								
								
								
								
							| 
						 | 
				
			
			@ -170,7 +170,7 @@ public:
 | 
			
		|||
  void on(unsigned short duration) {
 | 
			
		||||
    // Duration in ticks from milliseconds is:
 | 
			
		||||
    // t = (1/refclk)
 | 
			
		||||
    tickDuration = (duration * refclk) / 1000;
 | 
			
		||||
    tickDuration = (unsigned long)((unsigned long)duration * (unsigned long)refclk) / 1000;
 | 
			
		||||
    timeLimited = true;
 | 
			
		||||
    running = true;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -186,7 +186,7 @@ public:
 | 
			
		|||
  // Blocking version
 | 
			
		||||
  void playWait(unsigned short freq, unsigned short duration) {
 | 
			
		||||
    play(freq, duration);
 | 
			
		||||
    delay(duration * 1000);
 | 
			
		||||
    delay(duration);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  // Our maximum clock isn't very high, so our highest
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,9 +8,8 @@ void setup() {
 | 
			
		|||
  pinMode(3, OUTPUT);
 | 
			
		||||
  pinMode(11, OUTPUT);
 | 
			
		||||
  dds.start();
 | 
			
		||||
  dds.setFrequency(440);
 | 
			
		||||
  dds.playWait(600, 3000);
 | 
			
		||||
  dds.on();
 | 
			
		||||
  delay(5000);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue