Added explicit conversion of timer to uint16_t (Timer shows signs of signed int_8)
This commit is contained in:
		
							parent
							
								
									81030bade3
								
							
						
					
					
						commit
						6990bff184
					
				| @ -25,7 +25,9 @@ uint16_t boost_highVoltage_nextTick	=	0; | ||||
| uint8_t signalOutput_nextHigh	=	1; | ||||
| uint16_t signalOutput_nextTick	=	0; | ||||
| 
 | ||||
| uint8_t timer1_prescaler = 256; | ||||
| uint8_t timer1_prescaler = 1; | ||||
| 
 | ||||
| uint16_t test = 0; | ||||
| 
 | ||||
| int main() | ||||
| { | ||||
| @ -60,7 +62,7 @@ int main() | ||||
| 		/*
 | ||||
| 		 * HighVoltage boosting | ||||
| 		 */ | ||||
| 		if(boost_highVoltage_nextTick > 0 && TCNT1 >= boost_highVoltage_nextTick)	// If we are on or after the tick it should be executed
 | ||||
| 		if(boost_highVoltage_nextTick > 0 && (uint16_t)TCNT1 >= boost_highVoltage_nextTick)	// If we are on or after the tick it should be executed
 | ||||
| 		{ | ||||
| 			// Set pin according to next exec
 | ||||
| 			if(boost_highVoltage_nextHigh == 1)		 | ||||
| @ -77,14 +79,14 @@ int main() | ||||
| 			} | ||||
| 
 | ||||
| 			// Calculate when next high/low should be set
 | ||||
| 			boost_highVoltage_nextTick = TCNT1 + F_CPU/timer1_prescaler * 1/(boost_frequency/2);		// Half of time it should be high/low
 | ||||
| 			boost_highVoltage_nextTick = (uint16_t)TCNT1 + F_CPU/timer1_prescaler * 1/(boost_frequency/2);		// Half of time it should be high/low
 | ||||
| 			if(boost_highVoltage_nextTick == 0) boost_highVoltage_nextTick++;		// If its 0, it stops, we dont want that
 | ||||
| 		} | ||||
| 		 | ||||
| 		/*
 | ||||
| 		 * Signal output | ||||
| 		 */ | ||||
| 		if(signalOutput_nextTick > 0 && TCNT1 >= signalOutput_nextTick)	// If we are on or after the tick it should be executed
 | ||||
| 		if(signalOutput_nextTick > 0 && (uint16_t)TCNT1 >= signalOutput_nextTick)	// If we are on or after the tick it should be executed
 | ||||
| 		{ | ||||
| 			// Set pin according to next exec
 | ||||
| 			if(signalOutput_nextHigh == 1)		// Set it high
 | ||||
| @ -94,7 +96,7 @@ int main() | ||||
| 				signalOutput_nextHigh = 0;	// Next is low
 | ||||
| 				 | ||||
| 				// When the signal should stop
 | ||||
| 				signalOutput_nextTick = TCNT1 + F_CPU/timer1_prescaler * signalOutput_time/1000; 		// nextTick is in signalOutput_time in ms
 | ||||
| 				signalOutput_nextTick = (uint16_t)TCNT1 + F_CPU/timer1_prescaler * signalOutput_time/1000; 		// nextTick is in signalOutput_time in ms
 | ||||
| 				if(signalOutput_nextTick == 0) signalOutput_nextTick++;		// If its 0, it stops, we dont want that
 | ||||
| 			} | ||||
| 			else  								// Set it low
 | ||||
| @ -141,7 +143,7 @@ void timer1_init() | ||||
| 	} | ||||
| 	 | ||||
| 	// initialize counter
 | ||||
| 	TCNT1 = 0; | ||||
| 	TCNT1 = (uint16_t)0; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user