Submitted by: Steve Redfield - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Submitted by: Steve Redfield

Description:

Here's the code for the music that Jason and I are wanting to demo ... Tone array. unsigned int tones[3][13] = {{61156,57723,54483,51426,48539,45815,43242,40815, ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 14
Provided by: webEngrOr
Category:

less

Transcript and Presenter's Notes

Title: Submitted by: Steve Redfield


1
Submitted by Steve Redfield Here's my encoder
deciphering code. This does both encoders
independently (both can change value in same
while() execution) //////////////////////////////
///////////////////////////////// // Encoder
deciphering excecution is as follows // // 1)
Update Current Encoder Value. // 2) If Current is
different from Last, which bit is different? //
This gives you 4 cases, 2 forward, 2 backward,
each with // its own distinct "Current"
value. // 3) Correlate each "Current" value to
either Increment or // Decrement Volume. // 4)
Update Last Encoder Value. EncoderL PINE
0x30 EncoderR PINE 0x0C if(EncoderL !
EncoderLtmp) if((EncoderL EncoderLtmp)
0x20) if(EncoderL 0x30 EncoderL
0x00) Volume else Volume--
else if(EncoderL 0x10 EncoderL
0x20) Volume else Volume--
if(EncoderR ! EncoderRtmp)
if((EncoderR EncoderRtmp) 0x08)
if(EncoderR 0x0C EncoderR 0x00)
Volume else Volume-- else
if(EncoderR 0x04 EncoderR 0x08)
Volume else Volume--
EncoderLtmp EncoderL EncoderRtmp
EncoderR ///////////////////////////////////////
////////////////////////
2
Submitted by Hai Yue Han Here's the code for
the music that Jason and I are wanting to demo
I'm submitting a portion of the code that's from
my music file. //////////////////////////////////
///////////////////////////// //Fight song
array volatile int music3333
12,12,11,12,-1,7,-1,7,12,5,4,12,-1,12,12,11,1
2,-1,7, -1,7,12,5,4,12,1,0,0,0,0,4,4,4,7,7,7,4,2,0
,12,12,11,12, 1,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,
1,1,1,1,1,2,2,1,1,1,1,1, 1,1,1,1,1,1,1,2,2,2,1,1,1
,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,2, 2,2,
2,2,2,2,2,2,2,2,2,2,8,2,2,2,2,2,2,2,2,2,2,2,2,7,3,
2,2,2,4,2,2,2, 2,2,4,2,4,2,2,2,2,2,2,2,2,2,2,2,2,7
,3,2,2,2,4,2,2,2,2,2,4, unsigned int
songCounter 0 //Tone array unsigned int
tones313 61156,57723,54483,51426,48539,458
15,43242,40815,38525,36362, 34321,32395,30576,30
576,28861,27241,25711,24268,22906,21621,20407,1926
2,18180,17160,16197,15288,15288,14429,13619,1285
5,12133,11452,10809,10203,9630,9089,8579,8098,7643

3
Submitted By Zane Kenney Attached as a gif format
is the schematic I used for the DAC.
4

Here is my code for displaying the frequency to
the lcd. I only kept the directly relevant
sections. // in main loop if (update_lcd)
spi_init() update_lcd 0 //write
frequency itoa(frequency, st3 1, 10)
home_line2() if (!fm_freq) //display
frequency /64 // frequency is always in the
form 1.xxx st30 st31 st31
'.' string2lcd(st3) string2lcd("
MHz") else // display actual frequency
of lo len strlen(st3) st3len
st3len - 1 st3len - 1 '.' st3len
1 '\0' string2lcd(st3 1)
string2lcd(" MHz") .. SIGNAL(SIG_OVERFL
OW0) .. count freq TCNT3
TCNT30 .. // every second if (count
128 0) update_lcd 1 ..
if (!fm_freq) frequency (int) 1000 (freq /
1000000.) else frequency (int) 10
(freq 64. / 1000000) freq 0 ..
..
Submitted By Seth Insley
5

Submitted By Dan Braunworth
I don't know if you wanted to include my fancy
"off" button for the alarm clock. Like you
said, it's a feature. Here's the code IN
ALARM FUNCTION //if the current time is within
the range of the time passed into alarm() //and
the alarm duration AND alarm is armed by
ARM_ALARM flag AND the OFF //flag cleared THEN
enable output compare 1A interrupt if((HOUR
hour) (MINUTE gt minute) (MINUTE lt
(minuteduration)) (AM am) (ARM_ALARM
1) (OFF 0)) TIMSK
(1ltltOCIE1A) //otherwise, make sure to clear
the OFF flag for the next alarm event else
if((MINUTE lt minute) (MINUTE gt
(minuteduration))) OFF 0 //clear OFF
flag if alarm is not going off OFF BUTTON
case 5 //OFF S5 state5 (state5 ltlt
1) (PIND 0xEF) 0xE000 if (state5
0xF000) OFF 1
return 5 break
6

From Experimental Methods in RF Design
7

From R. Traylor
/
/ /
encoder_chk
/ /Takes an argument (either 0 or 1) the
encoder to check. If the encoder / /is moved,
the function returns
/ / 1 if CW rotation
detected, / /
0 if CCW rotation detected
/ / -1 if no
movement detected.
/ /Note the return value is a _singed_
8-bit int. / /Expected
pinout
/ / encoder 0, A output PORTE.3
/
/ B output PORTE.2
/ / encoder 1, A
output PORTE.5
/ / B output
PORTE.4
/ /Port E is expected to be pulled up with the
encoder causing a switch / /closure to
ground. Encoder pulls to ground with a 1K
resistor. / /Debounce time is 12 times
each ISR run or loop time.
/ /Code was adapted from Ganssel's "Guide to
Debouncing" / /

/ int8_t encoder_chk(uint8_t encoder)
static uint16_t state2 0,0 //holds
shifted in bits from encoder uint8_t a_pin,
b_pin //if no encoder 1 is not specified,
assume encoder 0 if (encoder 1) a_pin 5
b_pin 4 else a_pin 3 b_pin
2 stateencoder (stateencoder ltlt 1)
(! bit_is_clear(PINE, a_pin)) 0xE000 if
(stateencoder 0xF000) //falling edge
detected on A output if (bit_is_set(PINE,
b_pin)) //get state of "B" to determine
direction return 1 //detected CW rotation
else return 0 //detected CCW rotation
else return -1 //no movement detected
//encoder_chk
8

From R. Traylor
/
/ /
chk_button
/ /Checks the state of the button number
passed to it. It shifts in ones / /till the
button is pushed. Function returns a 1 only once
per debounced / / button push so a debounce
and toggle function can be implemented at the
/ /same time. Adapted to check all buttons from
Ganssel's "Guide to / /Debouncing".
Expects active low pushbuttons on PIND port.
Debounce time / /is determined by external loop
delay times 12. The argument "button" is
/ /the pushbutton on the mega128 board S2
(button 0) through / /S9 (button
7)
/ /
/ uint8_t
chk_button(uint8_t button) static uint16_t
state8 0,0,0,0,0,0,0,0 //holds shifted in
button bits statebutton (statebutton ltlt 1)
(! bit_is_clear(PIND, button)) 0xE000 if
(statebutton 0xF000) return 1 //if held
true for 12 passes through else return 0
//chk_button
9

From R. Traylor
uint8_t segment_data4 3, 2, 1, 0 //holds
segment data uint8_t digit_mask4 0x7F, 0xBF,
0xDF, 0xEF //holds digit masks (active low) //
decimal to 7-segment LED display encodings,
output "0" to turn on segment uint8_t
dec_to_7seg11 0xC0, 0xF9,
0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90,
0xFF // "0" "1" "2" "3" "4"
"5" "6" "7" "8" "9" "off" /

/ /
timer/counter 2 ISR
/ /When the TCNT2 overflow interrupt occurs,
display is serviced. / /This presently
takes 3.5uS to execute
/ /
/ SIGNAL(SIG_OVER
FLOW2) static uint8_t i0 //update
the LED digit to display i
//update digit to display i i 4
//i varies from 0 to 3 PORTB 0xF0
//cut all digits off if(set_alarm_bool TRUE)
segsum(alarm_minute_cnt, alarm_hour_cnt)
else segsum(minute_cnt, hour_cnt)
if(segment_data3 0) segment_data3 10
//kill leading zero hours PORTA
(dec_to_7segsegment_data3-i) //send
segment data to LED if (blink_colon 0x01)
PORTA 0x7F //blink colon PORTB
digit_mask3-i //turn on
the digit

10

Submitted by Cassady Roop
I've attached my frequency counter code (counter
and display code) and button debouncer. //global
s - NBUTTONS is defined 8 or less unsigned char
buttonVals 0xff //holds button stable
values unsigned char buttonHits 0 //indicates
button status changes unsigned char
buttonQNBUTTONS //debounce queue int main ()
while(1) //infinite loop
scanButtons() //update buttonHits, buttonVals
if(buttonHits) //respond to button activity
//put button response code here
buttonHits 0 //clear flags
// debounce and monitor button inputs.
button inputs are passed into a 8 place //
history queue (an unsigned char, one per button.)
An input is considered // debounced and valid
only when the entire queue sees the same bit.
When the // queue first stabilizes to a single
value, the button-hit flag is raised for // that
button, and its value is recorded. It is the
responsibility of the // button action recipient
to clear the button-hit flag. External
alteration // of buttonVals will confuse this
routine. This routine must run an absolute //
minimum of sixteen times before a change in
button status will be noted // bouncing will
increase this requirement. uses all of port
D. void scanButtons(void) int i unsigned char
scandata PIND //gather input from all
buttons unsigned char oldvalue buttonVals
for(i 0 i lt NBUTTONS i) buttonQi
ltlt 1 //advance the queue buttonQi
(scandata 1) //enqueue latest bit
if((buttonQi 0x00) (oldvalue 1))
buttonVals (1 ltlt i) //clear val bit
buttonHits (1 ltlt i) //set hit bit
if((buttonQi 0xff) !(oldvalue 1))
buttonVals (1 ltlt i) //set val bit
buttonHits (1 ltlt i) //set hit bit
scandata gtgt1 //advance to next bit
oldvalue gtgt1

11

Submitted by Cassady Roop
//globals volatile unsigned char flags
0 //status/control flags volatile unsigned long
int run_cnt 0 //running counter tally volatile
unsigned long int freq_cnt 0 //updated each
second volatile unsigned char time_cnt
0 //counts to one second _at_ 128 Hz char
freq_ascii7 "_reset_" int main ()
init() //one-time initialization
tasks while(1) //infinite loop .....
if(flags UPDATELCD) cntToASCII()
updateLCD() //output to LCD flags
UPDATELCD //clear flag ..... void
init(void) ...deleted to save room.. void
cntToASCII(void) int offset
21000 //measured error offset WRONG int
i unsigned long int n,a n freq_cnt n
offset //add offset (prescaled) n
64 //LO is prescaled by /64 a
100000000 for(i0 i lt 6 i) //convert
int to ascii freq_asciii (n /
a)0x30 //get digit value, add ASCII 0 n
a //remove that digit from int a /
10 //next power of ten
freq_ascii6 freq_ascii5 //insert decimal
point freq_ascii5 freq_ascii4 //via
embarrassingly lazy method freq_ascii4
freq_ascii3 freq_ascii3 '.'

12

Debounce Ideas Submitted by Ben Hershberg
DEBOUNCING PIND, IMPULSE STYLE ------------------
------------- uint8_t debounce_pind() //
Service routine called by a timer interrupt
static uint16_t State8 0,0,0,0,0,0,0,0 //
Current debounce status uint8_t pind 0 int
i 0 for (i 0 i lt 8 i) Statei
(Stateiltlt1) ((PIND (1 ltlt i)) gtgt i)
0xe000 if(Statei0xf000) pind
(1 ltlt i) return pind // Then, in the
while loop (or if you want to be super
precise, // during an ISR), insert this
line debounced_pind debounce_pind()
//debounce DEBOUNCING WHATEVER YOU WANT,
GHETTO STYLE ------------------------------------
------- / INTERRUPT FOR DEBOUNCING THE SHAFT
ENCODERS / INTERRUPT(SIG_OUTPUT_COMPARE2) / LED
REFRESH HERE, OR WHATEVER YOU WANT. / debounced
PINE PINE debouncedPIND PIND

13

Debounce Ideas Submitted by Ben Hershberg
ONE OTHER METHOD ----------------- INTERRUPT(SIG
_OVERFLOW2) StateIndex PIND if(IndexgtMAX
_CHECKS) Index0 // Inside main while
loop j0xFF for(i0 iltMAX_CHECKS-1i)jj
Statei Debounced_State j buttons
Debounced_State
Write a Comment
User Comments (0)
About PowerShow.com