Changed rf.add() and rf.phase() to allow for uint32_t durations
Instead of limiting number of ticks to 15-bits (32767), RFControl allows for tick size to be any 32-bit number. If ticks > 32767, RFControl adds repeated LOW or HIGH phases as needed to match full duration. This provides for much more flexibility in creating pulse trains that include very long-duration "spaces" between repeats.
This commit is contained in:
		
							parent
							
								
									96ac572136
								
							
						
					
					
						commit
						5bced71345
					
				|  | @ -69,11 +69,12 @@ void RFControl::start(uint32_t *data, int nData, uint8_t nCycles, uint8_t tickTi | ||||||
| 
 | 
 | ||||||
| void RFControl::clear(){ | void RFControl::clear(){ | ||||||
|   data.clear(); |   data.clear(); | ||||||
|  |   lowWord=true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ///////////////////
 | ///////////////////
 | ||||||
| 
 | 
 | ||||||
| void RFControl::add(uint16_t onTime, uint16_t offTime){ | void RFControl::add(uint32_t onTime, uint32_t offTime){ | ||||||
| 
 | 
 | ||||||
|   phase(onTime,HIGH); |   phase(onTime,HIGH); | ||||||
|   phase(offTime,LOW);   |   phase(offTime,LOW);   | ||||||
|  | @ -81,16 +82,19 @@ void RFControl::add(uint16_t onTime, uint16_t offTime){ | ||||||
| 
 | 
 | ||||||
| ///////////////////
 | ///////////////////
 | ||||||
| 
 | 
 | ||||||
| void RFControl::phase(uint16_t nTicks, uint8_t phase){ | void RFControl::phase(uint32_t nTicks, uint8_t phase){ | ||||||
| 
 | 
 | ||||||
|   uint32_t ticks=nTicks&0x7FFF; |   while(nTicks>0){                                      // create as many repeated phases as needed to accomodate duration of nTicks
 | ||||||
|  |     uint32_t ticks=nTicks>0x7FFF?0x7FFF:nTicks; | ||||||
|  |     nTicks-=ticks; | ||||||
| 
 | 
 | ||||||
|   if(lowWord) |     if(lowWord) | ||||||
|     data.push_back(ticks | (phase?(1<<15):0)); |       data.push_back(ticks | (phase?(1<<15):0)); | ||||||
|   else |     else | ||||||
|     data.back()|=ticks<<16 | (phase?(1<<31):0); |       data.back()|=ticks<<16 | (phase?(1<<31):0); | ||||||
| 
 |    | ||||||
|   lowWord=!lowWord; |     lowWord=!lowWord; | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ///////////////////
 | ///////////////////
 | ||||||
|  |  | ||||||
|  | @ -22,8 +22,8 @@ class RFControl { | ||||||
|     void start(uint8_t nCycles=1, uint8_t tickTime=1);                                // starts transmission of pulses from internal data structure, repeated for numCycles, where each tick in pulse is tickTime microseconds long    
 |     void start(uint8_t nCycles=1, uint8_t tickTime=1);                                // starts transmission of pulses from internal data structure, repeated for numCycles, where each tick in pulse is tickTime microseconds long    
 | ||||||
|      |      | ||||||
|     void clear();                                         // clears transmitter memory
 |     void clear();                                         // clears transmitter memory
 | ||||||
|     void add(uint16_t onTime, uint16_t offTime);          // adds pulse of onTime ticks HIGH followed by offTime ticks LOW
 |     void add(uint32_t onTime, uint32_t offTime);          // adds pulse of onTime ticks HIGH followed by offTime ticks LOW
 | ||||||
|     void phase(uint16_t nTicks, uint8_t phase);           // adds either a HIGH phase or LOW phase lasting numTicks ticks
 |     void phase(uint32_t nTicks, uint8_t phase);           // adds either a HIGH phase or LOW phase lasting numTicks ticks
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| // Helper macro for creating your own storage of uint32_t data array elements - used with first variation of start() above
 | // Helper macro for creating your own storage of uint32_t data array elements - used with first variation of start() above
 | ||||||
|  |  | ||||||
|  | @ -10,23 +10,33 @@ void setup() { | ||||||
| 
 | 
 | ||||||
|   Serial.println("\n\nHomeSpan RF Transmitter Example"); |   Serial.println("\n\nHomeSpan RF Transmitter Example"); | ||||||
| 
 | 
 | ||||||
|   RFControl rf(18);               // create an instance of RFControl with signal output to pin 6
 |   RFControl rf(17);               // create an instance of RFControl with signal output to pin 17
 | ||||||
| 
 | 
 | ||||||
| #define NPOINTS 3 |   rf.clear(); | ||||||
|    |  | ||||||
|   uint32_t data[NPOINTS]; |  | ||||||
| 
 | 
 | ||||||
|   for(int i=0;i<NPOINTS;i++){ |   rf.add(10000,10000); | ||||||
|     if(i<NPOINTS-1) |   rf.add(10000,10000); | ||||||
|         data[i]=RF_PULSE(1000,9000); |   rf.add(10000,40000); | ||||||
|     else | 
 | ||||||
|         data[i]=RF_PULSE(1000,30000); |   uint32_t t0=micros(); | ||||||
|   } |   rf.start(4,100); | ||||||
|   |   uint32_t t1=micros(); | ||||||
|   rf.start(data,NPOINTS,2,100); |  | ||||||
|     |     | ||||||
|   Serial.println("End Example"); |   Serial.println("End Example"); | ||||||
|  |   Serial.println((t1-t0)/1000); | ||||||
|    |    | ||||||
|  |   rf.clear(); | ||||||
|  | 
 | ||||||
|  |   rf.add(10000,10000); | ||||||
|  |   rf.add(10000,10000); | ||||||
|  | 
 | ||||||
|  |   t0=micros(); | ||||||
|  |   rf.start(4,100); | ||||||
|  |   t1=micros(); | ||||||
|  |     | ||||||
|  |   Serial.println("End Example"); | ||||||
|  |   Serial.println((t1-t0)/1000); | ||||||
|  | 
 | ||||||
| } // end of setup()
 | } // end of setup()
 | ||||||
| 
 | 
 | ||||||
| void loop(){ | void loop(){ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Gregg
						Gregg