Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 32bfe8c

Browse filesBrowse files
author
Jacquot-SFE
committed
Restructuring a bit.
Inputs are only read at end of ISR, not constantly polled. Trying out low power idle mode...it doesn't make much of a difference.
1 parent ffd32fa commit 32bfe8c
Copy full SHA for 32bfe8c

File tree

Expand file treeCollapse file tree

3 files changed

+84
-65
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+84
-65
lines changed
512 Bytes
Binary file not shown.

‎Firmware/GccApplication1/GccApplication1/GccApplication1.c

Copy file name to clipboardExpand all lines: Firmware/GccApplication1/GccApplication1/GccApplication1.c
+78-59Lines changed: 78 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <avr/io.h>
1111
#include <avr/interrupt.h>
12+
#include <avr/sleep.h>
1213
#include <stdint.h>
1314
#include <stdbool.h>
1415

@@ -344,10 +345,73 @@ void oneshotFSM()
344345
// monostable - like one-shot, but
345346
// astable - just runs back & forth while switch is held
346347

348+
uint32_t readADC(uint8_t chan)
349+
{
350+
uint32_t value;
351+
352+
// only allow the pins we've selected to read...
353+
if(!( (chan == POTA_CHAN) || (chan == POTB_CHAN) || (chan == POTT_CHAN)))
354+
{
355+
return 0;
356+
}
357+
358+
// turn on adc
359+
// TODO: perhaps turn on and leave on?
360+
ADCSRA = 0x86; // power bit, prescale of 64
361+
362+
ADCSRB |= 0x10; // left justify
363+
364+
// set digital input disable
365+
DIDR0 = 0x89;
366+
367+
// input mux, vref selection
368+
ADMUX = chan;
347369

370+
// pause a moment...
371+
for(volatile uint8_t i = 0xff; i != 0; i--);
372+
373+
// bit 6 starts conversion
374+
// write bit 4 to clear it
375+
ADCSRA |= 0x50;
376+
//ADCSRA = 0x40;
377+
378+
// start bit clears when complete
379+
while(ADCSRA & 0x40);
380+
381+
value = ADCW;
382+
383+
return value;
384+
}
385+
386+
387+
388+
void readInputs()
389+
{
390+
// read pots
391+
current_status.a = readADC(POTA_CHAN);
392+
current_status.b = readADC(POTB_CHAN);
393+
current_status.t = readADC(POTT_CHAN);
394+
395+
if(current_status.input_polarity)
396+
{
397+
// default = active low or switch closure
398+
// read switch - active low
399+
current_status.input = !(PINA & TRIG_PIN_A_MASK);
400+
}
401+
else
402+
{
403+
// active high
404+
current_status.input = (PINA & TRIG_PIN_A_MASK);
405+
}
406+
}
407+
408+
409+
// Called when the PWM timer is restarted.
410+
// The PWM output is set when counter is reset.
411+
// We need to calculate when that output will be cleared.
348412
ISR(TIM1_CAPT_vect)
349413
{
350-
// no hardware soure to reset - flag is cleared on execution of this vector
414+
// no hardware source to reset - flag is cleared on execution of this vector
351415

352416
// set the pulse width based on switch and pot positions.
353417
if(current_status.mode)
@@ -360,7 +424,10 @@ ISR(TIM1_CAPT_vect)
360424
}
361425

362426
OCR1A = PWM_MIN_USEC + current_status.us_val;
363-
427+
428+
// Then read and prepare for next invocation
429+
readInputs();
430+
364431
}
365432

366433

@@ -420,63 +487,7 @@ void setupPWM(void)
420487
GTCCR = 1 << PSR10;
421488
}
422489

423-
uint32_t readADC(uint8_t chan)
424-
{
425-
uint32_t value;
426-
427-
// only allow the pins we've selected to read...
428-
if(!( (chan == POTA_CHAN) || (chan == POTB_CHAN) || (chan == POTT_CHAN)))
429-
{
430-
return 0;
431-
}
432-
433-
// turn on adc
434-
// TODO: perhaps turn on and leave on?
435-
ADCSRA = 0x86; // power bit, prescale of 64
436-
437-
ADCSRB |= 0x10; // left justify
438-
439-
// set digital input disable
440-
DIDR0 = 0x89;
441-
442-
// input mux, vref selection
443-
ADMUX = chan;
444490

445-
// pause a moment...
446-
for(volatile uint8_t i = 0xff; i != 0; i--);
447-
448-
// bit 6 starts conversion
449-
// write bit 4 to clear it
450-
ADCSRA |= 0x50;
451-
//ADCSRA = 0x40;
452-
453-
// start bit clears when complete
454-
while(ADCSRA & 0x40);
455-
456-
value = ADCW;
457-
458-
return value;
459-
}
460-
461-
void readInputs()
462-
{
463-
// read pots
464-
current_status.a = readADC(POTA_CHAN);
465-
current_status.b = readADC(POTB_CHAN);
466-
current_status.t = readADC(POTT_CHAN);
467-
468-
if(current_status.input_polarity)
469-
{
470-
// default = active low or switch closure
471-
// read switch - active low
472-
current_status.input = !(PINA & TRIG_PIN_A_MASK);
473-
}
474-
else
475-
{
476-
// active high
477-
current_status.input = (PINA & TRIG_PIN_A_MASK);
478-
}
479-
}
480491

481492
int main(void)
482493
{
@@ -530,8 +541,16 @@ int main(void)
530541
// then enable interrupts
531542
sei();
532543

544+
// Turn off some peripherals that we're not using.
545+
PRR |= 0x06;//turn off USI and TIM0.
546+
547+
533548
while(1)
534549
{
535-
readInputs();
550+
// Not sure how much difference this was making...maybe a couple mA?
551+
// We have to leave the timer running, so we can only idle...
552+
sleep_enable();
553+
set_sleep_mode(SLEEP_MODE_IDLE);
554+
sleep_mode();
536555
}
537556
}

‎Hardware/Servo_Trigger.sch

Copy file name to clipboardExpand all lines: Hardware/Servo_Trigger.sch
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17466,17 +17466,17 @@ Datasheet says Rup is in the 20K to 50K range.</text>
1746617466
<segment>
1746717467
<pinref part="R1" gate="R?" pin="CW"/>
1746817468
<pinref part="SUPPLY5" gate="G$1" pin="VCC"/>
17469-
<wire x1="165.1" y1="99.06" x2="165.1" y2="109.22" width="0.2032" layer="91"/>
17469+
<wire x1="165.1" y1="99.06" x2="165.1" y2="109.22" width="0.1524" layer="91"/>
1747017470
</segment>
1747117471
<segment>
1747217472
<pinref part="R3" gate="R?" pin="CW"/>
1747317473
<pinref part="SUPPLY8" gate="G$1" pin="VCC"/>
17474-
<wire x1="205.74" y1="99.06" x2="205.74" y2="109.22" width="0.2032" layer="91"/>
17474+
<wire x1="205.74" y1="99.06" x2="205.74" y2="109.22" width="0.1524" layer="91"/>
1747517475
</segment>
1747617476
<segment>
1747717477
<pinref part="R2" gate="R?" pin="CW"/>
1747817478
<pinref part="SUPPLY6" gate="G$1" pin="VCC"/>
17479-
<wire x1="185.42" y1="99.06" x2="185.42" y2="109.22" width="0.2032" layer="91"/>
17479+
<wire x1="185.42" y1="99.06" x2="185.42" y2="109.22" width="0.1524" layer="91"/>
1748017480
</segment>
1748117481
</net>
1748217482
<net name="GND" class="0">
@@ -17538,17 +17538,17 @@ Datasheet says Rup is in the 20K to 50K range.</text>
1753817538
<segment>
1753917539
<pinref part="R1" gate="R?" pin="CCW"/>
1754017540
<pinref part="GND3" gate="1" pin="GND"/>
17541-
<wire x1="165.1" y1="88.9" x2="165.1" y2="81.28" width="0.2032" layer="91"/>
17541+
<wire x1="165.1" y1="88.9" x2="165.1" y2="81.28" width="0.1524" layer="91"/>
1754217542
</segment>
1754317543
<segment>
1754417544
<pinref part="R3" gate="R?" pin="CCW"/>
1754517545
<pinref part="GND1" gate="1" pin="GND"/>
17546-
<wire x1="205.74" y1="88.9" x2="205.74" y2="81.28" width="0.2032" layer="91"/>
17546+
<wire x1="205.74" y1="88.9" x2="205.74" y2="81.28" width="0.1524" layer="91"/>
1754717547
</segment>
1754817548
<segment>
1754917549
<pinref part="GND2" gate="1" pin="GND"/>
1755017550
<pinref part="R2" gate="R?" pin="CCW"/>
17551-
<wire x1="185.42" y1="81.28" x2="185.42" y2="88.9" width="0.2032" layer="91"/>
17551+
<wire x1="185.42" y1="81.28" x2="185.42" y2="88.9" width="0.1524" layer="91"/>
1755217552
</segment>
1755317553
</net>
1755417554
<net name="MOSI/PWM" class="0">

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.